Skip to content

Commit afde044

Browse files
committed
remove improvements and keep only fix of ecommerce tracking.
1 parent 7f4f6d9 commit afde044

File tree

5 files changed

+11
-89
lines changed

5 files changed

+11
-89
lines changed

app/code/Magento/GoogleGtag/Block/Ga.php

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\GoogleGtag\Block;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\Cookie\Helper\Cookie;
1211
use Magento\Framework\Api\SearchCriteriaBuilder;
1312
use Magento\Framework\Serialize\SerializerInterface;
@@ -26,32 +25,27 @@ class Ga extends Template
2625
/**
2726
* @var GtagConfiguration
2827
*/
29-
private GtagConfiguration $googleGtagConfig;
28+
private $googleGtagConfig;
3029

3130
/**
3231
* @var Cookie
3332
*/
34-
private Cookie $cookieHelper;
33+
private $cookieHelper;
3534

3635
/**
3736
* @var SerializerInterface
3837
*/
39-
private SerializerInterface $serializer;
38+
private $serializer;
4039

4140
/**
4241
* @var OrderRepositoryInterface
4342
*/
44-
private OrderRepositoryInterface $orderRepository;
43+
private $orderRepository;
4544

4645
/**
4746
* @var SearchCriteriaBuilder
4847
*/
49-
private SearchCriteriaBuilder $searchCriteriaBuilder;
50-
51-
/**
52-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
53-
*/
54-
private ProductRepositoryInterface $productRepository;
48+
private $searchCriteriaBuilder;
5549

5650
/**
5751
* @param Context $context
@@ -60,7 +54,6 @@ class Ga extends Template
6054
* @param SerializerInterface $serializer
6155
* @param SearchCriteriaBuilder $searchCriteriaBuilder
6256
* @param OrderRepositoryInterface $orderRepository
63-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
6457
* @param array $data
6558
*/
6659
public function __construct(
@@ -70,16 +63,13 @@ public function __construct(
7063
SerializerInterface $serializer,
7164
SearchCriteriaBuilder $searchCriteriaBuilder,
7265
OrderRepositoryInterface $orderRepository,
73-
ProductRepositoryInterface $productRepository,
7466
array $data = []
7567
) {
7668
$this->googleGtagConfig = $googleGtagConfig;
7769
$this->cookieHelper = $cookieHelper;
7870
$this->serializer = $serializer;
7971
$this->orderRepository = $orderRepository;
8072
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
81-
$this->productRepository = $productRepository;
82-
8373
parent::__construct($context, $data);
8474
}
8575

@@ -107,7 +97,6 @@ public function isCookieRestrictionModeEnabled(): bool
10797
* Return current website id.
10898
*
10999
* @return int
110-
* @throws \Magento\Framework\Exception\LocalizedException
111100
*/
112101
public function getCurrentWebsiteId(): int
113102
{
@@ -140,7 +129,6 @@ public function getPageTrackingData($measurementId): array
140129
* @link https://developers.google.com/gtagjs/reference/event#purchase
141130
*
142131
* @return array
143-
* @throws \Magento\Framework\Exception\NoSuchEntityException
144132
*/
145133
public function getOrdersTrackingData(): array
146134
{
@@ -157,48 +145,25 @@ public function getOrdersTrackingData(): array
157145
$collection = $this->orderRepository->getList($this->searchCriteriaBuilder->create());
158146

159147
foreach ($collection->getItems() as $order) {
160-
foreach ($order->getAllVisibleItems() as $index => $item) {
161-
$product = $this->productRepository->get($item->getSku());
162-
$orderProduct = [
163-
'index' => $index+1,
148+
foreach ($order->getAllVisibleItems() as $item) {
149+
$result['products'][] = [
164150
'item_id' => $this->_escaper->escapeHtmlAttr($item->getSku()),
165151
'item_name' => $this->_escaper->escapeHtmlAttr($item->getName()),
166-
'item_brand' => $this->_escaper->escapeHtmlAttr(
167-
$product->getAttributeText('manufacturer')
168-
),
169152
'affiliation' => $this->_escaper->escapeHtmlAttr(
170153
$this->_storeManager->getStore()->getFrontendName()
171154
),
172155
'price' => round((float) $item->getPrice(), 2),
173156
'quantity' => (int)$item->getQtyOrdered()
174157
];
175-
176-
if ($item->getDiscountAmount() > 0) {
177-
$orderProduct['discount'] = $this->_escaper->escapeHtmlAttr($item->getDiscountAmount());
178-
179-
if (!empty($order->getCouponCode())) {
180-
$orderProduct['coupon'] = $this->_escaper->escapeHtmlAttr($order->getCouponCode());
181-
}
182-
}
183-
184-
$result['products'][] = $orderProduct;
185158
}
186-
187-
$resultOrder = [
159+
$result['orders'][] = [
188160
'transaction_id' => $order->getIncrementId(),
189161
'currency' => $order->getOrderCurrencyCode(),
190162
'value' => round((float) $order->getGrandTotal(), 2),
191163
'tax' => round((float) $order->getTaxAmount(), 2),
192164
'shipping' => round((float) $order->getShippingAmount(), 2),
193165
];
194-
195-
if (!empty($order->getCouponCode())) {
196-
$resultOrder['coupon'] = $this->_escaper->escapeHtmlAttr($order->getCouponCode());
197-
}
198-
199-
$result['orders'][] = $resultOrder;
200166
}
201-
202167
return $result;
203168
}
204169

@@ -221,7 +186,6 @@ private function getOptPageUrl(): string
221186
* Provide analytics events data
222187
*
223188
* @return bool|string
224-
* @throws \Magento\Framework\Exception\NoSuchEntityException|\Magento\Framework\Exception\LocalizedException
225189
*/
226190
public function getAnalyticsData()
227191
{
@@ -233,7 +197,6 @@ public function getAnalyticsData()
233197
'ordersTrackingData' => $this->getOrdersTrackingData(),
234198
'googleAnalyticsAvailable' => $this->googleGtagConfig->isGoogleAnalyticsAvailable()
235199
];
236-
237200
return $this->serializer->serialize($analyticData);
238201
}
239202
}

app/code/Magento/GoogleGtag/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ A lot of functionality in the module is on JavaScript, use [mixins](https://deve
2121
### Layouts
2222

2323
This module introduces the following layouts in the `view/frontend/layout` directory:
24-
2524
- `default`
2625
- `checkout_onepage_success`
2726

app/code/Magento/GoogleGtag/Test/Unit/Block/GaTest.php

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\GoogleGtag\Test\Unit\Block;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
11-
use Magento\Catalog\Model\Product;
1210
use Magento\Cookie\Helper\Cookie;
1311
use Magento\Framework\Api\SearchCriteriaBuilder;
1412
use Magento\Framework\Api\SearchCriteriaInterface;
@@ -54,11 +52,6 @@ class GaTest extends TestCase
5452
*/
5553
private $storeMock;
5654

57-
/**
58-
* @var MockObject
59-
*/
60-
private $productMock;
61-
6255
/**
6356
* @var GtagConfiguration|mixed|MockObject
6457
*/
@@ -68,17 +61,10 @@ class GaTest extends TestCase
6861
* @var SearchCriteriaBuilder|mixed|MockObject
6962
*/
7063
private $searchCriteriaBuilder;
71-
7264
/**
7365
* @var OrderRepositoryInterface|mixed|MockObject
7466
*/
7567
private $orderRepository;
76-
77-
/**
78-
* @var OrderRepositoryInterface|mixed|MockObject
79-
*/
80-
private $productRepository;
81-
8268
/**
8369
* @var SerializerInterface|mixed|MockObject
8470
*/
@@ -113,18 +99,6 @@ protected function setUp(): void
11399
->disableOriginalConstructor()
114100
->getMockForAbstractClass();
115101

116-
$this->productRepository = $this->getMockBuilder(ProductRepositoryInterface::class)
117-
->onlyMethods(['get'])
118-
->disableOriginalConstructor()
119-
->getMockForAbstractClass();
120-
121-
$this->productMock = $this->getMockBuilder(Product::class)
122-
->disableOriginalConstructor()
123-
->onlyMethods(['getAttributeText'])
124-
->getMock();
125-
126-
$this->productRepository->expects($this->once())->method('get')->willReturn($this->productMock);
127-
128102
$this->googleGtagConfig = $this->getMockBuilder(GtagConfiguration::class)
129103
->disableOriginalConstructor()
130104
->getMock();
@@ -152,7 +126,6 @@ protected function setUp(): void
152126
'serializer' => $this->serializerMock,
153127
'searchCriteriaBuilder' => $this->searchCriteriaBuilder,
154128
'orderRepository' => $this->orderRepository,
155-
'productRepository' => $this->productRepository,
156129
'_escaper' => $escaper
157130
]
158131
);
@@ -177,7 +150,6 @@ public function testGetCurrentWebsiteId()
177150
/**
178151
* Test for getOrdersTrackingData()
179152
* @return void
180-
* @throws \Magento\Framework\Exception\NoSuchEntityException
181153
*/
182154
public function testOrderTrackingData()
183155
{
@@ -195,31 +167,23 @@ public function testOrderTrackingData()
195167
$this->searchCriteriaBuilder->method('create')->willReturn($searchCriteria);
196168
$this->storeMock->expects($this->once())->method('getFrontendName')->willReturn('test');
197169
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
198-
$this->productMock->expects($this->once())->method('getAttributeText')
199-
->with('manufacturer')->willReturn('Brand 1');
200-
201170
$expectedResult = [
202171
'orders' => [
203172
[
204173
'transaction_id' => 100,
205174
'currency' => 'USD',
206175
'value' => 10.00,
207176
'tax' => 2.00,
208-
'shipping' => 1.00,
209-
'coupon' => 'coupon1'
177+
'shipping' => 1.00
210178
]
211179
],
212180
'products' => [
213181
[
214-
'index' => 1,
215182
'item_id' => 'sku0',
216183
'item_name' => 'testName0',
217-
'item_brand' => 'Brand 1',
218184
'affiliation' => 'test',
219185
'price' => 0.00,
220-
'quantity' => 1,
221-
'discount' => 0.01,
222-
'coupon' => 'coupon1',
186+
'quantity' => 1
223187
]
224188
],
225189
];
@@ -252,11 +216,10 @@ protected function createOrderMock($orderItemCount = 1)
252216
$orderItemMock = $this->getMockBuilder(OrderItemInterface::class)
253217
->disableOriginalConstructor()
254218
->getMockForAbstractClass();
255-
$orderItemMock->expects($this->exactly(2))->method('getSku')->willReturn('sku' . $i);
219+
$orderItemMock->expects($this->once())->method('getSku')->willReturn('sku' . $i);
256220
$orderItemMock->expects($this->once())->method('getName')->willReturn('testName' . $i);
257221
$orderItemMock->expects($this->once())->method('getPrice')->willReturn($i . '.00');
258222
$orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn($i + 1);
259-
$orderItemMock->expects($this->exactly(2))->method('getDiscountAmount')->willReturn(0.01);
260223
$orderItems[] = $orderItemMock;
261224
}
262225

@@ -269,7 +232,6 @@ protected function createOrderMock($orderItemCount = 1)
269232
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2);
270233
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn($orderItemCount);
271234
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->willReturn('USD');
272-
$orderMock->expects($this->exactly(4))->method('getCouponCode')->willReturn('coupon1');
273235
return $orderMock;
274236
}
275237

app/code/Magento/GoogleGtag/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"require": {
88
"php": "~8.1.0||~8.2.0",
99
"magento/framework": "*",
10-
"magento/module-catalog": "*",
1110
"magento/module-cookie": "*",
1211
"magento/module-sales": "*",
1312
"magento/module-store": "*"

app/code/Magento/GoogleGtag/etc/module.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
99
<module name="Magento_GoogleGtag" >
1010
<sequence>
11-
<module name="Magento_Catalog"/>
1211
<module name="Magento_Store"/>
1312
<module name="Magento_Checkout"/>
1413
</sequence>

0 commit comments

Comments
 (0)