Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ihorvansach committed Aug 16, 2023
1 parent c4fe394 commit 4644f7b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Block/DataLayer/PurchaseGetOrderFromRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* Copyright © Magefan ([email protected]). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/

declare(strict_types=1);

namespace Magefan\GoogleTagManager\Block\DataLayer;

use Magefan\GoogleTagManager\Block\DataLayer\Purchase;
Expand Down
3 changes: 2 additions & 1 deletion Block/GtmCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public function getWebsiteId(): int
*/
protected function _toHtml(): string
{
if ($this->config->isEnabled()) {

if ($this->config->isEnabled() && $this->getPublicId()) {
return parent::_toHtml();
}

Expand Down
10 changes: 5 additions & 5 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ public function getContainerId(string $storeId = null): string
*/
public function getPublicId(string $storeId = null): string
{
$result = trim((string)$this->getConfig(self::XML_PATH_WEB_PUBLIC_ID, $storeId));

if (!$result) {
if ('use_public_id' === $this->getInstallGtm()) {
return trim((string)$this->getConfig(self::XML_PATH_WEB_PUBLIC_ID, $storeId));
} else {
if ($gtmScript = $this->getGtmScript($storeId)) {
$pattern = '/GTM-[A-Z0-9]+/';
$matches = [];
if (preg_match($pattern, $gtmScript, $matches)) {
if (isset($matches[0])) {
return (string)$matches[0];
return trim((string)$matches[0]);
}
}
}
}

return $result;
return '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

declare(strict_types=1);

namespace Magefan\GoogleTagManager\Plugin\Magefan\GoogleTagManager\Model\DataLayer;
namespace Magefan\GoogleTagManager\Plugin\Magefan\GoogleTagManager\Api\DataLayer;

use Magefan\GoogleTagManager\Model\DataLayer\Purchase as Subject;
use Magefan\GoogleTagManager\Api\DataLayer\PurchaseInterface as Subject;
use Magefan\GoogleTagManager\Model\ResourceModel\Transaction\CollectionFactory as TransactionCollectionFactory;
use Magefan\GoogleTagManager\Model\TransactionFactory;
use Magefan\GoogleTagManager\Model\TransactionRepository;
use Magento\Sales\Model\Order;
use Magento\Framework\Exception\CouldNotSaveException;
use Psr\Log\LoggerInterface;

class Purchase
class PurchaseInterface
{
/**
* @var TransactionCollectionFactory
Expand Down
4 changes: 2 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<preference for="Magefan\GoogleTagManager\Api\DataLayer\Cart\ItemInterface" type="Magefan\GoogleTagManager\Model\DataLayer\Cart\Item" />
<preference for="Magefan\GoogleTagManager\Api\DataLayer\Order\ItemInterface" type="Magefan\GoogleTagManager\Model\DataLayer\Order\Item" />
<preference for="Magefan\GoogleTagManager\Api\DataLayer\Product\ItemInterface" type="Magefan\GoogleTagManager\Model\DataLayer\Product\Item" />
<type name="Magefan\GoogleTagManager\Model\DataLayer\Purchase">
<plugin name="Plugin_Magefan_GoogleTagManager_Model_DataLayer_Purchase" type="Magefan\GoogleTagManager\Plugin\Magefan\GoogleTagManager\Model\DataLayer\Purchase" sortOrder="10" disabled="false"/>
<type name="Magefan\GoogleTagManager\Api\DataLayer\PurchaseInterface">
<plugin name="Plugin_Magefan_GoogleTagManager_Api_DataLayer_PurchaseInterface" type="Magefan\GoogleTagManager\Plugin\Magefan\GoogleTagManager\Api\DataLayer\PurchaseInterface" sortOrder="10" disabled="false"/>
</type>
</config>
8 changes: 7 additions & 1 deletion view/frontend/layout/p2c2p_payment_success.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?xml version="1.0" ?>
<!--
/**
* Copyright © Magefan ([email protected]). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/
-->
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magefan\GoogleTagManager\Block\DataLayer\PurchaseGetOrderFromRequest" name="mfgtm.data.layer"/>
</referenceContainer>
</body>
</page>
</page>

0 comments on commit 4644f7b

Please sign in to comment.