diff --git a/src/Controller/AjaxController.php b/src/Controller/AjaxController.php index 6a36a2d..43f1c8e 100644 --- a/src/Controller/AjaxController.php +++ b/src/Controller/AjaxController.php @@ -21,7 +21,7 @@ public function postProcess() ob_end_clean(); header('Content-Type: application/json'); - $this->ajaxDie(json_encode($response, JSON_THROW_ON_ERROR, 512)); + $this->ajaxDie(json_encode($response)); } private function getCart(): array diff --git a/src/Hook/Event/Browser/PurchaseHook.php b/src/Hook/Event/Browser/PurchaseHook.php index dab90f8..30bf0b8 100644 --- a/src/Hook/Event/Browser/PurchaseHook.php +++ b/src/Hook/Event/Browser/PurchaseHook.php @@ -14,20 +14,62 @@ class PurchaseHook extends AbstractHook Hooks::DISPLAY_ORDER_CONFIRMATION => [ 'addDataElementInOrderConfirmationPage', ], + Hooks::DISPLAY_AFTER_BODY_OPENING_TAG => [ + 'p24Compatibility', + ], ]; public function addDataElementInOrderConfirmationPage(array $data): string { + if (true === $this->isP24ConfirmationPage()) { + return ''; + } + /** @var PrestaShopOrder $orderObject */ $orderObject = $data['order']; - $order = Order::fromOrderObject($orderObject); + return $this->handlePurchaseEvent($orderObject); + } + + public function p24Compatibility(array $data): string + { + if (false === $this->isP24ConfirmationPage()) { + return ''; + } + + $orderId = PrestaShopOrder::getIdByCartId($this->getContext()->cart->id); + + if (false === $orderId) { + return ''; + } + + $order = new PrestaShopOrder($orderId); + + return $this->handlePurchaseEvent($order); + } + + private function handlePurchaseEvent(PrestaShopOrder $order): string + { + $orderModel = Order::fromOrderObject($order); - $this->getContext()->smarty->assign('tc_order', $order->toArray()); + $this->getContext()->smarty->assign('tc_order', $orderModel->toArray()); return $this->module->display( \TagConciergeFree::MODULE_FILE, 'views/templates/hooks/purchase/display_order_confirmation.tpl' ); } + + private function isP24ConfirmationPage(): bool + { + $controller = $this->getContext()->controller; + + if (null === $controller) { + return false; + } + + $controllerClass = get_class($controller); + + return 'przelewy24paymentconfirmationmodulefrontcontroller' === strtolower($controllerClass); + } } diff --git a/tagconciergefree.php b/tagconciergefree.php index e90380f..92888ae 100644 --- a/tagconciergefree.php +++ b/tagconciergefree.php @@ -41,7 +41,7 @@ public function __construct() { $this->name = 'tagconciergefree'; $this->author = 'Tag Concierge'; - $this->version = '1.0.1'; + $this->version = '1.0.2'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->bootstrap = true; $this->tab = 'advertising_marketing'; diff --git a/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl b/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl index 6db2568..6af8d3b 100644 --- a/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl +++ b/views/templates/hooks/add_to_cart/display_before_body_closing_tag.tpl @@ -9,7 +9,7 @@ if (null === tagConcierge.lastPrestashopCartFromResponse) { jQuery.ajax({ type: 'POST', - url: '/index.php?fc=module&module=tag_concierge&controller=ajax&ajax=true', + url: '/index.php?fc=module&module=tagconciergefree&controller=ajax&ajax=true', data: 'action=getCart', async: false, success: function (d) {