Skip to content

Commit b766a77

Browse files
authored
Merge pull request #64 from ivanhrytsaim/13682-GTM-Problems-V3
13682-GTM-Problems-V3
2 parents bfe7a1f + 8ebfa3e commit b766a77

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Block/DataLayer/ViewItem.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function __construct(
6767
*/
6868
protected function getDataLayer(): array
6969
{
70-
$data = $this->viewItem->get($this->getCurrentProduct());
70+
$product = $this->getCurrentProduct();
71+
$data = $this->viewItem->get($product);
7172
if ($productId = $this->_request->getParam('mfpreselect')) {
7273
try {
7374
$child = $this->productRepository->getById($productId);
@@ -78,7 +79,15 @@ protected function getDataLayer(): array
7879

7980
$delimiter = (false === strpos($childUrl, '?')) ? '?' : '&';
8081
$childUrl .= $delimiter . 'mfpreselect=' . $child->getId();
81-
82+
83+
$attributes = $product->getTypeInstance()->getConfigurableAttributes($product);
84+
foreach ($attributes as $attribute) {
85+
$attrCode = $attribute->getProductAttribute()->getAttributeCode();
86+
$value = $child->getData($attrCode);
87+
$delimiter = (false === strpos($childUrl, '?')) ? '?' : '&';
88+
$childUrl .= $delimiter . $attrCode . '=' . $value;
89+
}
90+
8291
$childData['ecommerce']['items'][0]['item_url'] = $childUrl;
8392
}
8493
$data = $childData;

Model/DataLayer/AbstractOrder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ protected function getValue(Order $order): float
105105
*/
106106
protected function setMfChildrenItem($entity)
107107
{
108-
foreach ($entity->getAllItems() as $childrenItem) {
108+
// Use getItem, not getAllItems, to prevent some errors with the custom plugins
109+
foreach ($entity->getItems() as $childrenItem) {
109110
if ($parentItemId = $childrenItem->getParentItemId()) {
110111
foreach ($entity->getAllVisibleItems() as $parentItem) {
111112
if ($parentItem->getId() == $parentItemId) {

0 commit comments

Comments
 (0)