Skip to content

Commit a255fb6

Browse files
committed
Initital commit
1 parent ffd54f8 commit a255fb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2257
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Quote\Model\Quote;
13+
14+
interface BeginCheckoutInterface
15+
{
16+
/**
17+
* Get GTM datalayer
18+
*
19+
* @param Quote $quote
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(Quote $quote): array;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer\Cart;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Quote\Model\Quote\Item;
13+
14+
interface ItemInterface
15+
{
16+
/**
17+
* Get quote Item
18+
*
19+
* @param Item $quoteItem
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(Item $quoteItem): array;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer\Order;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Sales\Api\Data\OrderItemInterface;
13+
14+
interface ItemInterface
15+
{
16+
/**
17+
* Get order item
18+
*
19+
* @param OrderItemInterface $orderItem
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(OrderItemInterface $orderItem): array;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer\Product;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Catalog\Model\Product;
13+
14+
interface ItemInterface
15+
{
16+
/**
17+
* Get product item
18+
*
19+
* @param Product $product
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(Product $product): array;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Sales\Model\Order;
13+
14+
interface PurchaseInterface
15+
{
16+
/**
17+
* Get GTM datalayer
18+
*
19+
* @param Order $order
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(Order $order): array;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Quote\Model\Quote;
13+
14+
interface ViewCartInterface
15+
{
16+
/**
17+
* Get GTM datalayer
18+
*
19+
* @param Quote $quote
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(Quote $quote): array;
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Api\DataLayer;
10+
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Catalog\Model\Product;
13+
14+
interface ViewItemInterface
15+
{
16+
/**
17+
* Get GTM datalayer
18+
*
19+
* @param Product $product
20+
* @return array
21+
* @throws NoSuchEntityException
22+
*/
23+
public function get(Product $product): array;
24+
}

Block/AbstractDataLayer.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Block;
10+
11+
use Magento\Framework\View\Element\AbstractBlock;
12+
use Magento\Framework\View\Element\Context;
13+
use Magefan\GoogleTagManager\Model\Config;
14+
15+
abstract class AbstractDataLayer extends AbstractBlock
16+
{
17+
/**
18+
* @var Config
19+
*/
20+
protected $config;
21+
22+
/**
23+
* AbstractDataLayer constructor.
24+
*
25+
* @param Context $context
26+
* @param Config $config
27+
* @param array $data
28+
*/
29+
public function __construct(
30+
Context $context,
31+
Config $config,
32+
array $data = []
33+
) {
34+
$this->config = $config;
35+
parent::__construct($context, $data);
36+
}
37+
38+
/**
39+
* Get GTM datalayer
40+
*
41+
* @return array
42+
*/
43+
abstract protected function getDataLayer(): array;
44+
45+
/**
46+
* Init GTM datalayer
47+
*
48+
* @return string
49+
*/
50+
protected function _toHtml(): string
51+
{
52+
if ($this->config->isEnabled()) {
53+
$dataLayer = $this->getDataLayer();
54+
if ($dataLayer) {
55+
return '<script>
56+
require(["mfPushDataLayer"], function(mfPushDataLayer) {
57+
mfPushDataLayer(' . json_encode($dataLayer) . ');
58+
})
59+
</script>';
60+
}
61+
}
62+
63+
return '';
64+
}
65+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Block\Adminhtml\System\Config\Form;
10+
11+
use Magento\Config\Block\System\Config\Form\Field;
12+
use Magento\Framework\Data\Form\Element\AbstractElement;
13+
14+
class Button extends Field
15+
{
16+
public const BUTTON_TEMPLATE = 'system/config/button/button.phtml';
17+
18+
/**
19+
* Set template to itself
20+
*
21+
* @return $this
22+
*/
23+
protected function _prepareLayout(): Button
24+
{
25+
parent::_prepareLayout();
26+
if (!$this->getTemplate()) {
27+
$this->setTemplate(static::BUTTON_TEMPLATE);
28+
}
29+
return $this;
30+
}
31+
32+
/**
33+
* Render button
34+
*
35+
* @param AbstractElement $element
36+
* @return string
37+
*/
38+
public function render(AbstractElement $element): string
39+
{
40+
// Remove scope label
41+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
42+
return parent::render($element);
43+
}
44+
45+
/**
46+
* Get the button and scripts contents
47+
*
48+
* @param AbstractElement $element
49+
* @return string
50+
*/
51+
protected function _getElementHtml(AbstractElement $element): string
52+
{
53+
return $this->_toHtml();
54+
}
55+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
declare(strict_types=1);
8+
9+
namespace Magefan\GoogleTagManager\Block\Adminhtml\System\Config\Form;
10+
11+
class Info extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info
12+
{
13+
/**
14+
* Return extension url
15+
*
16+
* @return string
17+
*/
18+
protected function getModuleUrl(): string
19+
{
20+
return 'https://mage' .
21+
'fan.com/magento2-extensions?utm_source=gtm_config&utm_medium=link&utm_campaign=regular';
22+
}
23+
24+
/**
25+
* Return extension title
26+
*
27+
* @return string
28+
*/
29+
protected function getModuleTitle(): string
30+
{
31+
return 'Google Tag Manager Extension';
32+
}
33+
}

0 commit comments

Comments
 (0)