Skip to content

Commit 5dd6961

Browse files
authored
Merge pull request #57 from stape-io/feature/event-value
Feature/event value
2 parents 439c5b0 + fc22f2b commit 5dd6961

File tree

14 files changed

+32
-10
lines changed

14 files changed

+32
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
v1.0.32
4+
- datalayer event value param added;
5+
36
v1.0.31
47
- renamed module in admin panel;
58
- added select_item event;

Model/Webhook/Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class Adapter
1414
{
1515

16-
public const MODULE_VERSION = '1.0.31';
16+
public const MODULE_VERSION = '1.0.32';
1717

1818
/**
1919
* @var Json $json

Observer/AddToCartComplete.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function execute(Observer $observer)
8787
$childItem = $quoteItem->getHasChildren() ? current($quoteItem->getChildren()) : null;
8888
$this->dataProvider->add('add_to_cart', [
8989
'currency' => $this->checkoutSession->getQuote()->getBaseCurrencyCode(),
90+
'value' => (string) $this->priceCurrency->round($quoteItem->getBasePriceInclTax()),
9091
'items' => [
9192
[
9293
'item_name' => $product->getName(),

Plugin/Checkout/Cart/DeletePlugin.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Stape\Gtm\Plugin\Checkout\Cart;
44

55
use Magento\Checkout\Controller\Cart\Delete;
6+
use Magento\Checkout\Controller\Sidebar\RemoveItem;
67
use Magento\Checkout\Model\Session as CheckoutSession;
78
use Magento\Framework\Pricing\PriceCurrencyInterface;
89
use Psr\Log\LoggerInterface;
@@ -71,19 +72,21 @@ public function __construct(
7172
/**
7273
* Add remove from cart event
7374
*
74-
* @param Delete $subject
75+
* @param Delete|RemoveItem $subject
7576
* @param callable $proceed
7677
* @return mixed
7778
* @throws \Magento\Framework\Exception\LocalizedException
7879
* @throws \Magento\Framework\Exception\NoSuchEntityException
7980
*/
80-
public function aroundExecute(Delete $subject, callable $proceed)
81+
public function aroundExecute($subject, callable $proceed)
8182
{
8283
if (!$this->configProvider->isActive()) {
8384
return $proceed();
8485
}
8586

86-
$itemId = (int) $subject->getRequest()->getParam('id');
87+
$request = $subject->getRequest();
88+
$itemId = (int) ($request->getParam('id') ?: $request->getParam('item_id'));
89+
8790
$quote = $this->checkoutSession->getQuote();
8891
/** @var \Magento\Quote\Model\Quote\Item $item */
8992
if (!$item = $quote->getItemById($itemId)) {
@@ -97,6 +100,7 @@ public function aroundExecute(Delete $subject, callable $proceed)
97100

98101
if ($item->isDeleted()) {
99102
$this->dataProvider->add('remove_from_cart', [
103+
'value' => $this->priceCurrency->round($item->getBasePriceInclTax()),
100104
'items' => [
101105
[
102106
'item_name' => $item->getName(),

ViewModel/Cart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function getJson()
114114
'cart_quantity' => (int) $quote->getItemsQty(),
115115
'cart_total' => $this->priceCurrency->round($quote->getBaseGrandTotal()),
116116
'ecommerce' => [
117+
'value' => (string) $this->priceCurrency->round($quote->getBaseGrandTotal()),
117118
'currency' => $this->storeManager->getStore()->getCurrentCurrency()->getCode(),
118119
'items' => $this->prepareItems($quote),
119120
],

ViewModel/Checkout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function getJson()
114114
'cart_quantity' => (int) $quote->getItemsQty(),
115115
'cart_total' => $this->priceCurrency->round($quote->getBaseGrandTotal()),
116116
'ecommerce' => [
117+
'value' => (string) $this->priceCurrency->round($quote->getBaseGrandTotal()),
117118
'currency' => $this->storeManager->getStore()->getCurrentCurrency()->getCode(),
118119
'items' => $this->prepareItems($quote),
119120
],

ViewModel/Product.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ public function getProductData()
151151
*/
152152
public function getJson()
153153
{
154+
$value = $this->priceCurrency->round($this->getProduct()->getFinalPrice());
155+
154156
return $this->json->serialize([
155157
'event' => $this->eventFormatter->formatName('view_item'),
156158
'ecomm_pagetype' => 'product',
157159
'ecommerce' => [
160+
'value' => (string) $value,
158161
'currency' => $this->storeManager->getStore()->getCurrentCurrency()->getCode(),
159162
'items' => array_filter([
160163
$this->getProductData()

ViewModel/Success.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function getJson()
162162
'transaction_id' => $order->getIncrementId(),
163163
'quote_id' => $order->getQuoteId(),
164164
'affiliation' => $this->storeManager->getStore()->getName(),
165-
'value' => $this->priceCurrency->round($order->getBaseGrandTotal()),
165+
'value' => (string) $this->priceCurrency->round($order->getBaseGrandTotal()),
166166
'tax' => $this->priceCurrency->round($order->getBaseTaxAmount()), // tax
167167
'shipping' => $this->priceCurrency->round($order->getBaseShippingAmount()), // shipping price
168168
'coupon' => $order->getCouponCode(), // coupon if exists

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": [
66
"GPL-3.0-only"
77
],
8-
"version": "1.0.31",
8+
"version": "1.0.32",
99
"require": {
1010
"php": ">=7.4.0",
1111
"jeremykendall/php-domain-parser": "^6.0"

etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
<type name="Magento\Checkout\Controller\Cart\Delete">
2020
<plugin name="stape_gtm_cart_delete" type="Stape\Gtm\Plugin\Checkout\Cart\DeletePlugin" />
2121
</type>
22+
<type name="Magento\Checkout\Controller\Sidebar\RemoveItem">
23+
<plugin name="stape_gtm_cart_item_remove" type="Stape\Gtm\Plugin\Checkout\Cart\DeletePlugin" />
24+
</type>
2225
</config>

0 commit comments

Comments
 (0)