Skip to content

Commit

Permalink
Merge pull request #4 from tagconcierge/feature/TICKET-3360
Browse files Browse the repository at this point in the history
Feature/ticket 3360
  • Loading branch information
mfrankiewicz authored Jun 2, 2023
2 parents 0cfb3f1 + 001fe2b commit a1d2895
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 44 additions & 2 deletions src/Hook/Event/Browser/PurchaseHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion tagconciergefree.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a1d2895

Please sign in to comment.