Skip to content

Commit 8470693

Browse files
authored
Merge pull request #28 from ivanhrytsaim/10727-Do-not-shipping-or-tax
10727-Do-not-include-shipping-or-tax
2 parents d25406c + ed21f1c commit 8470693

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
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/DataLayer/BeginCheckout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function get(Quote $quote): array
5656
'event' => 'begin_checkout',
5757
'ecommerce' => [
5858
'currency' => $this->getCurrentCurrencyCode(),
59-
'value' => $this->formatPrice((float)$quote->getGrandTotal()),
59+
'value' => $this->getQuoteValue($quote),
6060
'coupon' => $quote->getCouponCode() ?: '',
6161
'items' => $items
6262
],

Model/DataLayer/ViewCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function get(Quote $quote): array
5858
'event' => 'view_cart',
5959
'ecommerce' => [
6060
'currency' => $this->getCurrentCurrencyCode(),
61-
'value' => $this->formatPrice((float)$quote->getGrandTotal()),
61+
'value' => $this->getQuoteValue($quote),
6262
'items' => $items
6363
],
6464
'items_count' => count($items),

Model/DataLayer/ViewItem.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ 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->getPrice($product),
54+
'value' => $this->getProductValue($product),
5655
'items' => [
5756
$item
5857
]

etc/config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
</attributes>
6565
<events>
6666
<purchase>
67-
<shipping_enabled>1</shipping_enabled>
68-
<tax_enabled>1</tax_enabled>
67+
<shipping_enabled>0</shipping_enabled>
68+
<tax_enabled>0</tax_enabled>
6969
</purchase>
7070
</events>
7171
<page_speed_optimization>

0 commit comments

Comments
 (0)