first commit
This commit is contained in:
50
controllers/front/switch.php
Normal file
50
controllers/front/switch.php
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user