first commit

This commit is contained in:
2025-04-02 22:15:22 +03:00
commit f17d62c9e5
9 changed files with 765 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
<?php
class B2BPaymentsValidationModuleFrontController extends ModuleFrontController
{
public function postProcess()
{
if ($this->context->cart->id_customer == 0 || $this->context->cart->id_address_delivery == 0 || $this->context->cart->id_address_invoice == 0 || !$this->module->active) {
Tools::redirect($this->context->link->getPageLink('order', true, $this->context->language->id, [
'step' => 1
]));
return false;
}
if (!$this->context->customer->id) {
// Handle unauthenticated access, maybe redirect to login
Tools::redirect($this->context->link->getPageLink('authentication', true, $this->context->language->id, [
'back' => $_SERVER['HTTP_REFERER']
]));
}
$total = $this->context->cart->getOrderTotal(true, Cart::BOTH);
// Refresh cart prices based on the customer's default group. Crucial step!
$this->context->cart->getProducts(true); // Force refresh of product prices.
$this->context->cart->update();
Cart::resetStaticCache();
// Re-calculate the total
$total = $this->context->cart->getOrderTotal(true, Cart::BOTH);
// Determine payment status based on customer group (for example):
$this->context->customer->id;
$b2b_postpaid_group_id = (int)Configuration::get('B2BPAYMENTS_POSTPAID_GROUP');
$b2b_prepaid_group_id = (int)Configuration::get('B2BPAYMENTS_PREPAID_GROUP');
$payment_status = Configuration::get('PS_OS_PAYMENT'); // Default: Payment accepted
if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_postpaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_postpaid_group_id)) {
$payment_status = Configuration::get('PS_OS_PREPARATION'); // Order processing in progress. Adjust as needed.
$payment_method = $this->module->b2b_postpaid_payment_name;
} else if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_prepaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_prepaid_group_id)) {
//Payment Status Already fine.
$payment_method = $this->module->b2b_prepaid_payment_name;
} else {
// Handle the case where the customer is not in either B2B group, or it's their default group
Tools::redirect($this->context->link->getPageLink('order', true, $this->context->language->id, [
'step' => 1
]));
return false;
}
$this->module->validateOrder(
(int)$this->context->cart->id,
$payment_status,
$total,
$payment_method,
null,
[],
null,
false,
$this->context->customer->secure_key
);
Tools::redirect($this->context->link->getPageLink('order-confirmation', true, $this->context->language->id, [
'id_cart' => $this->context->cart->id,
'id_module' => $this->module->id,
'id_order' => $this->module->currentOrder,
'key' => $this->context->customer->secure_key,
]));
return true;
}
}