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,50 @@
<?php
use Symfony\Component\HttpFoundation\JsonResponse;
class B2BPaymentsSwitchModuleFrontController extends ModuleFrontController
{
public function postProcess()
{
parent::postProcess();
$customer_id = (int)$this->context->customer->id;
if (!$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']
]));
}
if (Tools::isSubmit('ajax')) {
$success = $this->module->toggleCustomerGroup($customer_id);
if ($success) {
$response = array('success' => true);
} else {
$response = array('success' => false, 'error' => $this->module->trans('Failed to switch group.', [], 'Modules.B2bpayments.SwitchController'));
}
(new JsonResponse($response))->send();
exit;
} else {
$success = $this->module->toggleCustomerGroup($customer_id);
if ($success) {
Tools::redirect($this->context->link->getPageLink('my-account', true, $this->context->language->id)); // Redirect back to account
} else {
// Handle the error
$this->context->smarty->assign(
'errors',
array($this->module->trans('Failed to switch group.', [], 'Modules.B2bpayments.SwitchController'))
);
$this->setTemplate('module:b2bpayments/views/templates/front/error.tpl');
}
}
}
}