Skip to content

Commit

Permalink
fixes 'empty' hook calling by p24
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankiewicz committed Jun 2, 2023
1 parent dfa1aad commit 001fe2b
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/Hook/Event/Browser/PurchaseHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@

class PurchaseHook extends AbstractHook
{
private $eventFired = false;

/** @var array */
public const HOOKS = [
Hooks::DISPLAY_ORDER_CONFIRMATION => [
'addDataElementInOrderConfirmationPage',
],
Hooks::DISPLAY_BEFORE_BODY_CLOSING_TAG => [
Hooks::DISPLAY_AFTER_BODY_OPENING_TAG => [
'p24Compatibility',
],
];

public function addDataElementInOrderConfirmationPage(array $data): string
{
if (true === $this->isP24ConfirmationPage()) {
return '';
}

/** @var PrestaShopOrder $orderObject */
$orderObject = $data['order'];

Expand All @@ -31,15 +33,7 @@ public function addDataElementInOrderConfirmationPage(array $data): string

public function p24Compatibility(array $data): string
{
$controller = $this->getContext()->controller;

if (null === $controller) {
return '';
}

$controllerClass = get_class($controller);

if ('Przelewy24paymentConfirmationModuleFrontController' !== $controllerClass) {
if (false === $this->isP24ConfirmationPage()) {
return '';
}

Expand All @@ -56,19 +50,26 @@ public function p24Compatibility(array $data): string

private function handlePurchaseEvent(PrestaShopOrder $order): string
{
if (true === $this->eventFired) {
return '';
}

$orderModel = Order::fromOrderObject($order);

$this->getContext()->smarty->assign('tc_order', $orderModel->toArray());

$this->eventFired = true;

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);
}
}

0 comments on commit 001fe2b

Please sign in to comment.