Skip to content

Commit b1d936e

Browse files
committed
use unique key for grouped option
1 parent 7fe7858 commit b1d936e

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

CatalogDataExporter/Model/Provider/Product/ProductOptions/GroupedProductOptions.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ public function get(array $values) : array
7373
);
7474

7575
while ($row = $cursor->fetch()) {
76-
$optionValues[$row['parentId']][] = $this->formatOptionsValueRow($row);
76+
$key = $this->getOptionKey($row['parentId'], $storeViewCode);
77+
$optionValues[$key][] = $this->formatOptionsValueRow($row);
7778

78-
$output[$row['parentId']] = [
79+
$output[$key] = [
7980
'productId' => $row['parentId'],
8081
'storeViewCode' => $storeViewCode,
8182
'optionsV2' => [
8283
'type' => Grouped::TYPE_CODE,
8384
'id' => $row['parentId'],
84-
'values' => $optionValues[$row['parentId']],
85+
'values' => $optionValues[$key],
8586
]
8687
];
8788
}
@@ -94,6 +95,19 @@ public function get(array $values) : array
9495
return $output;
9596
}
9697

98+
/**
99+
* Generate option key by concatenating parentId, storeViewCode
100+
*
101+
* @param string $parentId
102+
* @param string $storeViewCode
103+
*
104+
* @return string
105+
*/
106+
private function getOptionKey(string $parentId, string $storeViewCode): string
107+
{
108+
return $parentId . $storeViewCode;
109+
}
110+
97111
/**
98112
* Format options value row data for grouped products.
99113
*

CatalogDataExporter/Test/Integration/GroupedProductsTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@ public function testGroupedProductOptions(array $groupedProductOptionsDataProvid
5757
}
5858
}
5959

60+
/**
61+
* Validate grouped product options data in multiple website
62+
*
63+
* @param array $groupedProductOptionsDataProvider
64+
*
65+
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
66+
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped_in_multiple_websites.php
67+
* @dataProvider getGroupedProductOptionsDataProvider
68+
*
69+
* @magentoDbIsolation disabled
70+
* @magentoAppIsolation enabled
71+
*
72+
* @return void
73+
*/
74+
public function testGroupedProductOptionsInMultipleWebsites(array $groupedProductOptionsDataProvider) : void
75+
{
76+
$storeViews = ['fixture_second_store','fixture_third_store'];
77+
78+
foreach ($storeViews as $store) {
79+
$extractedProduct = $this->getExtractedProduct('grouped-product', $store);
80+
$this->assertNotEmpty($extractedProduct, 'Feed data must not be empty');
81+
82+
// Assert values are equal for fixture_second_store
83+
$groupedProductOptionsDataProvider['feedData']['storeViewCode'] = $store;
84+
foreach ($groupedProductOptionsDataProvider as $key => $expectedData) {
85+
$diff = $this->arrayUtils->recursiveDiff($expectedData, $extractedProduct[$key]);
86+
self::assertEquals([], $diff, 'Actual feed data doesn\'t equal to expected data');
87+
}
88+
}
89+
}
90+
6091
/**
6192
* Get grouped product options data provider
6293
*

0 commit comments

Comments
 (0)