Skip to content

Commit 481a35b

Browse files
authored
Merge pull request #19 from magefan/9536-GTM-for-liqpay-orders
9536 gtm for liqpay orders
2 parents 8f0bc65 + 5304360 commit 481a35b

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

Controller/LastOrder/DataLayer.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
namespace Magefan\GoogleTagManager\Controller\LastOrder;
8+
9+
use Magento\Framework\App\Action\Context;
10+
use Magefan\GoogleTagManager\Model\Config;
11+
use Magefan\GoogleTagManager\Model\DataLayer\Purchase;
12+
use Magento\Sales\Api\OrderRepositoryInterface;
13+
use Magento\Checkout\Model\Session;
14+
use Magento\Framework\Controller\Result\JsonFactory;
15+
16+
class DataLayer extends \Magento\Framework\App\Action\Action
17+
{
18+
/**
19+
* @var Config
20+
*/
21+
protected $config;
22+
23+
/**
24+
* @var Purchase
25+
*/
26+
protected $purchaseDataLayer;
27+
28+
/**
29+
* @var OrderRepositoryInterface
30+
*/
31+
protected $orderRepository;
32+
33+
/**
34+
* @var Session
35+
*/
36+
protected $checkoutSession;
37+
38+
/**
39+
* @var JsonFactory
40+
*/
41+
protected $jsonResultFactory;
42+
43+
/**
44+
* ConfirmOrder constructor.
45+
* @param Context $context
46+
* @param Config $config
47+
* @param Purchase $purchaseDataLayer
48+
* @param OrderRepositoryInterface $orderRepository
49+
* @param Session $checkoutSession
50+
* @param JsonFactory $jsonResultFactory
51+
*/
52+
public function __construct(
53+
Context $context,
54+
Config $config,
55+
Purchase $purchaseDataLayer,
56+
OrderRepositoryInterface $orderRepository,
57+
Session $checkoutSession,
58+
JsonFactory $jsonResultFactory
59+
) {
60+
parent::__construct($context);
61+
$this->config = $config;
62+
$this->purchaseDataLayer = $purchaseDataLayer;
63+
$this->orderRepository = $orderRepository;
64+
$this->checkoutSession = $checkoutSession;
65+
$this->jsonResultFactory = $jsonResultFactory;
66+
}
67+
68+
public function execute()
69+
{
70+
$result = $this->jsonResultFactory->create();
71+
if ($this->config->isEnabled()) {
72+
$orderId = $this->checkoutSession->getLastOrderId();
73+
try {
74+
$order = $this->orderRepository->get($orderId);
75+
} catch (\NoSuchElementException $e) {
76+
}
77+
if ($order && $order->getEntityId()) {
78+
$dataLayer = $this->purchaseDataLayer->get($order);
79+
if ($dataLayer) {
80+
$result = $this->jsonResultFactory->create();
81+
$result->setData($dataLayer);
82+
return $result;
83+
}
84+
}
85+
}
86+
return $result;
87+
}
88+
}

etc/frontend/routes.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
9+
<router id="standard">
10+
<route id="mfgoogletagmanager" frontName="mfgoogletagmanager">
11+
<module name="Magefan_GoogleTagManager" />
12+
</route>
13+
</router>
14+
</config>

0 commit comments

Comments
 (0)