Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yireo/Yireo_GoogleTagManager2
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Jun 15, 2023
2 parents 76c31f1 + 92f1ce0 commit 9049701
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Plugin/TriggerAddGuestPaymentInfoDataLayerEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Yireo\GoogleTagManager2\Plugin;

use Yireo\GoogleTagManager2\Api\CheckoutSessionDataProviderInterface;
use Yireo\GoogleTagManager2\DataLayer\Event\AddPaymentInfo;

class TriggerAddGuestPaymentInfoDataLayerEvent
{
private CheckoutSessionDataProviderInterface $checkoutSessionDataProvider;
private AddPaymentInfo $addPaymentInfo;

public function __construct(
CheckoutSessionDataProviderInterface $checkoutSessionDataProvider,
AddPaymentInfo $addPaymentInfo
) {
$this->checkoutSessionDataProvider = $checkoutSessionDataProvider;
$this->addPaymentInfo = $addPaymentInfo;
}

public function afterSavePaymentInformationAndPlaceOrder(
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
$orderId,
$cartId,
$email,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$addPaymentInfoEventData = $this->addPaymentInfo
->setPaymentMethod($paymentMethod->getMethod())
->setCartId((int)$cartId)
->get();
$this->checkoutSessionDataProvider->add('add_payment_info_event', $addPaymentInfoEventData);

return $orderId;
}

public function afterSavePaymentInformation(
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
$orderId,
$cartId,
$email,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$addPaymentInfoEventData = $this->addPaymentInfo
->setPaymentMethod($paymentMethod->getMethod())
->setCartId((int)$cartId)
->get();
$this->checkoutSessionDataProvider->add('add_payment_info_event', $addPaymentInfoEventData);

return $orderId;
}
}
10 changes: 10 additions & 0 deletions etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
<type name="Magento\Checkout\Api\PaymentInformationManagementInterface">
<plugin name="Yireo_GoogleTagManager2::triggerAddPaymentInfoDataLayerEvent" type="Yireo\GoogleTagManager2\Plugin\TriggerAddPaymentInfoDataLayerEvent"/>
</type>

<type name="Magento\Checkout\Api\GuestPaymentInformationManagementInterface">
<plugin name="Yireo_GoogleTagManager2::triggerAddGuestPaymentInfoDataLayerEvent" type="Yireo\GoogleTagManager2\Plugin\TriggerAddGuestPaymentInfoDataLayerEvent"/>
</type>

<!--
<type name="Magento\Checkout\Api\TotalsInformationManagementInterface">
<plugin name="Yireo_GoogleTagManager2::triggerAddShippingInfoDataLayerEvent" type="Yireo\GoogleTagManager2\Plugin\TriggerAddShippingInfoDataLayerEvent"/>
</type>
-->
</config>

0 comments on commit 9049701

Please sign in to comment.