-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d87b343
commit 267eaf6
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Yireo\GoogleTagManager2\MageWire; | ||
|
||
use Magento\Checkout\Model\Session as CheckoutSession; | ||
use Yireo\GoogleTagManager2\DataLayer\Event\AddPaymentInfo; | ||
use Yireo\GoogleTagManager2\DataLayer\Event\AddShippingInfo; | ||
use Yireo\GoogleTagManager2\DataLayer\Event\BeginCheckout; | ||
|
||
class Checkout extends Component | ||
{ | ||
protected $listeners = [ | ||
'shipping_method_selected' => 'triggerShippingMethod', | ||
'payment_method_selected' => 'triggerPaymentMethod', | ||
]; | ||
|
||
public function __construct( | ||
private readonly CheckoutSession $checkoutSession, | ||
Check failure on line 19 in MageWire/Checkout.php GitHub Actions / PHPStan
|
||
private readonly BeginCheckout $beginCheckout, | ||
private readonly AddShippingInfo $addShippingInfo, | ||
private readonly AddPaymentInfo $addPaymentInfo, | ||
) { | ||
} | ||
|
||
public function triggerBeginCheckout() | ||
{ | ||
$this->dispatchBrowserEvent('ga:trigger-event', $this->beginCheckout->get()); | ||
} | ||
|
||
public function triggerShippingMethod() | ||
{ | ||
$this->dispatchBrowserEvent('ga:trigger-event', $this->addShippingInfo->get()); | ||
} | ||
|
||
public function triggerPaymentMethod() | ||
{ | ||
$this->addPaymentInfo->setCartId((int) $this->checkoutSession->getQuote()->getId()); | ||
$this->addPaymentInfo->setPaymentMethod((string) $this->checkoutSession->getQuote()->getPayment()->getMethod()); | ||
$this->dispatchBrowserEvent('ga:trigger-event', $this->addPaymentInfo->get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Yireo\GoogleTagManager2\MageWire; | ||
|
||
if (class_exists('\Magewirephp\Magewire\Component')) { | ||
class Component extends \Magewirephp\Magewire\Component {} | ||
} else { | ||
class Component {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
layout="checkout" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="main"> | ||
<block template="Yireo_GoogleTagManager2::hyva_checkout/data-layer.phtml" | ||
ifconfig="googletagmanager2/settings/enabled"> | ||
<arguments> | ||
<argument name="magewire" xsi:type="object">Yireo\GoogleTagManager2\MageWire\Checkout</argument> | ||
<argument name="begin_checkout_event" xsi:type="object">Yireo\GoogleTagManager2\DataLayer\Event\BeginCheckout</argument> | ||
</arguments> | ||
</block> | ||
</referenceContainer> | ||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Yireo\GoogleTagManager2\DataLayer\Event\BeginCheckout; | ||
|
||
/** @var Template $block */ | ||
/** @var BeginCheckout $beginCheckoutEvent */ | ||
|
||
$beginCheckoutEvent = $block->getData('begin_checkout_event'); | ||
?> | ||
<script> | ||
function triggerEvent(event) { | ||
yireoGoogleTagManager2Pusher(event.detail); | ||
} | ||
|
||
function initYireoGoogleTagManager() { | ||
"use strict"; | ||
|
||
triggerEvent(new CustomEvent('ga:trigger-event', {detail:<?= json_encode($beginCheckoutEvent->get()) ?>})); | ||
|
||
return { | ||
triggerEvent | ||
} | ||
} | ||
</script> | ||
<div id="ga-trigger" | ||
x-data="initYireoGoogleTagManager()" | ||
class="hidden" | ||
@ga:trigger-event.window="triggerEvent($event)" | ||
></div> | ||
|