Skip to content

Commit ed21f1c

Browse files
committed
update 10727-Do-not-include-shipping-or-tax
1 parent 7002db2 commit ed21f1c

File tree

8 files changed

+74
-52
lines changed

8 files changed

+74
-52
lines changed

Model/AbstractDataLayer.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,65 @@ protected function getPrice(Product $product): float
231231
return $this->formatPrice($price);
232232
}
233233

234+
/**
235+
* @param $product
236+
* @return float
237+
*/
238+
protected function getProductValue($product): float
239+
{
240+
$value = $this->getPrice($product);
241+
242+
if (!$this->config->isPurchaseTaxEnabled()) {
243+
$value = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue('tax');
244+
}
245+
246+
return $this->formatPrice($value);
247+
}
248+
249+
/**
250+
* @param $quote
251+
* @return float
252+
*/
253+
protected function getQuoteValue($quote): float
254+
{
255+
$quoteValue = (float)$quote->getGrandTotal();
256+
$address = $quote->getShippingAddress() ?: $quote->getBillingAddress();
257+
258+
if (!$this->config->isPurchaseTaxEnabled()) {
259+
$quoteValue -= (float)$address->getTaxAmount();
260+
}
261+
262+
if (!$this->config->isPurchaseShippingEnabled()) {
263+
$quoteValue -= (float)$address->getShippingAmount();
264+
}
265+
266+
return $this->formatPrice($quoteValue);
267+
}
268+
269+
/**
270+
* @param $quoteItem
271+
* @return float
272+
*/
273+
protected function getQuoteItemValue($quoteItem): float
274+
{
275+
//fix for magento 2.3.2 - module-quote/Model/Quote/Item/Processor.php prepareItem does not set price to quote item
276+
$quoteItemValue = $quoteItem->getPriceInclTax();
277+
if (!$quoteItemValue && ($quoteItemProduct = $quoteItem->getProduct())) {
278+
$quoteItemValue = (float)$quoteItemProduct->getPrice();
279+
}
280+
281+
if (!$this->config->isPurchaseTaxEnabled()) {
282+
$quoteItemValue -= (float)$quoteItem->getTaxAmount();
283+
}
284+
285+
if (!$this->config->isPurchaseTaxEnabled()) {
286+
$quoteItemValue -= (float)$quoteItem->getAddress()->getShippingAmount();
287+
}
288+
289+
return $this->formatPrice($quoteItemValue);
290+
}
291+
292+
234293
/**
235294
* @param Product $product
236295
* @param string $attributeCode

Model/Config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class Config
4646
/**
4747
* Events config
4848
*/
49-
public const XML_PATH_EVENTS_PURCHASE_TAX_ENABLED = 'mfgoogletagmanager/events/price_tracking/tax_enabled';
50-
public const XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED = 'mfgoogletagmanager/events/price_tracking/shipping_enabled';
49+
public const XML_PATH_EVENTS_PURCHASE_TAX_ENABLED = 'mfgoogletagmanager/events/purchase/tax_enabled';
50+
public const XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED = 'mfgoogletagmanager/events/purchase/shipping_enabled';
5151

5252
/**
5353
* Customer data protection regulation config
@@ -187,7 +187,7 @@ public function getMeasurementId(string $storeId = null): string
187187
* @param string|null $storeId
188188
* @return bool
189189
*/
190-
public function isTrackTaxEnabled(string $storeId = null): bool
190+
public function isPurchaseTaxEnabled(string $storeId = null): bool
191191
{
192192
return (bool)$this->getConfig(self::XML_PATH_EVENTS_PURCHASE_TAX_ENABLED, $storeId);
193193
}
@@ -196,7 +196,7 @@ public function isTrackTaxEnabled(string $storeId = null): bool
196196
* @param string|null $storeId
197197
* @return bool
198198
*/
199-
public function isTrackShippingEnabled(string $storeId = null): bool
199+
public function isPurchaseShippingEnabled(string $storeId = null): bool
200200
{
201201
return (bool)$this->getConfig(self::XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED, $storeId);
202202
}

Model/DataLayer/BeginCheckout.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,10 @@ public function get(Quote $quote): array
5656
'event' => 'begin_checkout',
5757
'ecommerce' => [
5858
'currency' => $this->getCurrentCurrencyCode(),
59-
'value' => $this->getOrderValue($quote),
59+
'value' => $this->getQuoteValue($quote),
6060
'coupon' => $quote->getCouponCode() ?: '',
6161
'items' => $items
6262
]
6363
]);
6464
}
65-
protected function getOrderValue($quote): float
66-
{
67-
$quoteValue = (float)$quote->getGrandTotal();
68-
if (!$this->config->isTrackTaxEnabled()) {
69-
$quoteValue -= (float)$quote->getShippingAddress()->getTaxAmount();
70-
}
71-
72-
if (!$this->config->isTrackShippingEnabled()) {
73-
$quoteValue -= $quote->getShippingAddress()->getShippingAmount();
74-
}
75-
76-
return $this->formatPrice($quoteValue);
77-
}
7865
}

Model/DataLayer/Purchase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ protected function getOrderValue($order): float
8686
{
8787
$orderValue = (float)$order->getGrandTotal();
8888

89-
if (!$this->config->isTrackTaxEnabled()) {
89+
if (!$this->config->isPurchaseTaxEnabled()) {
9090
$orderValue -= $order->getTaxAmount();
9191
}
9292

93-
if (!$this->config->isTrackShippingEnabled()) {
93+
if (!$this->config->isPurchaseShippingEnabled()) {
9494
$orderValue -= $order->getShippingAmount();
9595
}
9696

Model/DataLayer/ViewCart.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,12 @@ public function get(Quote $quote): array
5858
'event' => 'view_cart',
5959
'ecommerce' => [
6060
'currency' => $this->getCurrentCurrencyCode(),
61-
'value' => $this->getOrderValue($quote),
61+
'value' => $this->getQuoteValue($quote),
6262
'items' => $items
6363
],
6464
'items_count' => count($items),
6565
'items_qty' => $itemsQty,
6666
'coupon_code' => $quote->getCouponCode() ?: ''
6767
]);
6868
}
69-
protected function getOrderValue($quote): float
70-
{
71-
$quoteValue = (float)$quote->getGrandTotal();
72-
if (!$this->config->isTrackTaxEnabled()) {
73-
$quoteValue -= (float)$quote->getShippingAddress()->getTaxAmount();
74-
}
75-
76-
if (!$this->config->isTrackShippingEnabled()) {
77-
$quoteValue -= $quote->getShippingAddress()->getShippingAmount();
78-
}
79-
80-
return $this->formatPrice($quoteValue);
81-
}
8269
}

Model/DataLayer/ViewItem.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,15 @@ public function __construct(
4747
public function get(Product $product): array
4848
{
4949
$item = $this->gtmItem->get($product);
50-
5150
return $this->eventWrap([
5251
'event' => 'view_item',
5352
'ecommerce' => [
5453
'currency' => $this->getCurrentCurrencyCode(),
55-
'value' => $this->getOrderValue($product),
54+
'value' => $this->getProductValue($product),
5655
'items' => [
5756
$item
5857
]
5958
]
6059
]);
6160
}
62-
protected function getOrderValue($product): float
63-
{
64-
$productValue = $this->getPrice($product);
65-
66-
if (!$this->config->isTrackTaxEnabled()) {
67-
$productValue = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue('tax');
68-
}
69-
70-
return $this->formatPrice($productValue);
71-
}
7261
}

etc/adminhtml/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ To create a new secret, navigate in the
348348
</group>
349349
<group id="events" translate="label" type="text" sortOrder="62" showInDefault="1" showInWebsite="1" showInStore="1">
350350
<label>Events</label>
351-
<group id="price_tracking" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
352-
<label>Price Tracking</label>
351+
<group id="purchase" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
352+
<label>Purchase</label>
353353
<field id="shipping_enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
354354
<label>Include Shipping In Purchase Value</label>
355355
<comment>If enabled, shipping amount will be included into purchase value (the monetary value of the event).</comment>

etc/config.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
<categories/>
6464
</attributes>
6565
<events>
66-
<price_tracking>
67-
<shipping_enabled>1</shipping_enabled>
68-
<tax_enabled>1</tax_enabled>
69-
</price_tracking>
66+
<purchase>
67+
<shipping_enabled>0</shipping_enabled>
68+
<tax_enabled>0</tax_enabled>
69+
</purchase>
7070
</events>
7171
<page_speed_optimization>
7272
<enabled>0</enabled>

0 commit comments

Comments
 (0)