Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ public function isWebhookTriggerOnOrderState(): bool
return $this->getWebhookTriggerMode() === 'on_order_state';
}

/**
* Whether to skip storing purchase event in checkout session
*/
public function isPurchaseSessionStorageDisabled(): bool
{
return (bool)$this->getModuleConfigValueAdvanced('disable_purchase_session_storage', false);
}

/**
* @return bool
*/
Expand Down
11 changes: 10 additions & 1 deletion Observer/TriggerPurchaseDataLayerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Tagging\GTM\Api\CheckoutSessionDataProviderInterface;
use Tagging\GTM\Config\Config;
use Tagging\GTM\DataLayer\Event\Purchase as PurchaseEvent;
use Tagging\GTM\Logger\Debugger;
use Exception;
Expand All @@ -15,22 +16,30 @@ class TriggerPurchaseDataLayerEvent implements ObserverInterface
private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider;
private PurchaseEvent $purchaseEvent;
private Debugger $debugger;
private Config $config;

public function __construct(
CheckoutSessionDataProviderInterface $checkoutSessionDataProvider,
PurchaseEvent $purchaseEvent,
Debugger $debugger
Debugger $debugger,
Config $config
) {
$this->checkoutSessionDataProvider = $checkoutSessionDataProvider;
$this->purchaseEvent = $purchaseEvent;
$this->debugger = $debugger;
$this->config = $config;
}

public function execute(Observer $observer)
{
/** @var OrderInterface $order */
$order = $observer->getData('order');

if ($this->config->isPurchaseSessionStorageDisabled()) {
$this->debugger->debug("[TriggerPurchaseDataLayerEvent] Purchase session storage disabled; skipping add");
return;
}

$this->debugger->debug("TriggerPurchaseDataLayerEvent::execute(): has changed ");
$this->checkoutSessionDataProvider->add(
'purchase_event',
Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
<field id="webhook_trigger_mode">on_order_state</field>
</depends>
</field>
<field id="disable_purchase_session_storage" type="select" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Disable purchase session storage</label>
<comment>When enabled, purchase events are not stored in checkout session (prevents pushes on non-success pages after failed/aborted payments).</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="*/settings/enabled">1</field>
</depends>
</field>
</group>
</section>
</system>
Expand Down
Loading