Skip to content

Commit 3334be7

Browse files
committed
Merge branch 'MAGETWO-99500' of https://github.com/magento-tango/magento2ce into MPI_PR_2019_06_21
2 parents 7d1761a + e4c7282 commit 3334be7

File tree

5 files changed

+340
-44
lines changed

5 files changed

+340
-44
lines changed

app/code/Magento/ConfigurableProduct/Model/LinkManagement.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function addChild($sku, $childSku)
132132
throw new StateException(__("The parent product doesn't have configurable product options."));
133133
}
134134

135-
$attributeIds = [];
135+
$attributeData = [];
136136
foreach ($configurableProductOptions as $configurableProductOption) {
137137
$attributeCode = $configurableProductOption->getProductAttribute()->getAttributeCode();
138138
if (!$child->getData($attributeCode)) {
@@ -143,9 +143,11 @@ public function addChild($sku, $childSku)
143143
)
144144
);
145145
}
146-
$attributeIds[] = $configurableProductOption->getAttributeId();
146+
$attributeData[$configurableProductOption->getAttributeId()] = [
147+
'position' => $configurableProductOption->getPosition()
148+
];
147149
}
148-
$configurableOptionData = $this->getConfigurableAttributesData($attributeIds);
150+
$configurableOptionData = $this->getConfigurableAttributesData($attributeData);
149151

150152
/** @var \Magento\ConfigurableProduct\Helper\Product\Options\Factory $optionFactory */
151153
$optionFactory = $this->getOptionsFactory();
@@ -211,16 +213,16 @@ private function getOptionsFactory()
211213
/**
212214
* Get Configurable Attribute Data
213215
*
214-
* @param int[] $attributeIds
216+
* @param int[] $attributeData
215217
* @return array
216218
*/
217-
private function getConfigurableAttributesData($attributeIds)
219+
private function getConfigurableAttributesData($attributeData)
218220
{
219221
$configurableAttributesData = [];
220222
$attributeValues = [];
221223
$attributes = $this->attributeFactory->create()
222224
->getCollection()
223-
->addFieldToFilter('attribute_id', $attributeIds)
225+
->addFieldToFilter('attribute_id', array_keys($attributeData))
224226
->getItems();
225227
foreach ($attributes as $attribute) {
226228
foreach ($attribute->getOptions() as $option) {
@@ -237,6 +239,7 @@ private function getConfigurableAttributesData($attributeIds)
237239
'attribute_id' => $attribute->getId(),
238240
'code' => $attribute->getAttributeCode(),
239241
'label' => $attribute->getStoreLabel(),
242+
'position' => $attributeData[$attribute->getId()]['position'],
240243
'values' => $attributeValues,
241244
];
242245
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/LinkManagementTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ public function testAddChild()
149149
->disableOriginalConstructor()
150150
->setMethods(['getId', 'getData'])
151151
->getMock();
152-
153152
$extensionAttributesMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtension::class)
154153
->disableOriginalConstructor()
155-
->setMethods([
156-
'getConfigurableProductOptions', 'setConfigurableProductOptions', 'setConfigurableProductLinks'
157-
])
154+
->setMethods(
155+
[
156+
'getConfigurableProductOptions',
157+
'setConfigurableProductOptions',
158+
'setConfigurableProductLinks'
159+
]
160+
)
158161
->getMock();
159162
$optionMock = $this->getMockBuilder(\Magento\ConfigurableProduct\Api\Data\Option::class)
160163
->disableOriginalConstructor()
161-
->setMethods(['getProductAttribute', 'getAttributeId'])
164+
->setMethods(['getProductAttribute', 'getPosition', 'getAttributeId'])
162165
->getMock();
163166
$productAttributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
164167
->disableOriginalConstructor()
@@ -189,7 +192,6 @@ public function testAddChild()
189192
->disableOriginalConstructor()
190193
->setMethods(['getValue', 'getLabel'])
191194
->getMock();
192-
193195
$attributeCollectionMock = $this->getMockBuilder(
194196
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection::class
195197
)
@@ -216,20 +218,18 @@ public function testAddChild()
216218
$productAttributeMock->expects($this->any())->method('getAttributeCode')->willReturn('color');
217219
$simple->expects($this->any())->method('getData')->willReturn('color');
218220
$optionMock->expects($this->any())->method('getAttributeId')->willReturn('1');
221+
$optionMock->expects($this->any())->method('getPosition')->willReturn('0');
219222

220223
$optionsFactoryMock->expects($this->any())->method('create')->willReturn([$optionMock]);
221224
$attributeFactoryMock->expects($this->any())->method('create')->willReturn($attributeMock);
222225
$attributeMock->expects($this->any())->method('getCollection')->willReturn($attributeCollectionMock);
223226
$attributeCollectionMock->expects($this->any())->method('addFieldToFilter')->willReturnSelf();
224227
$attributeCollectionMock->expects($this->any())->method('getItems')->willReturn([$attributeMock]);
225-
228+
$attributeMock->expects($this->any())->method('getId')->willReturn(1);
226229
$attributeMock->expects($this->any())->method('getOptions')->willReturn([$attributeOptionMock]);
227-
228230
$extensionAttributesMock->expects($this->any())->method('setConfigurableProductOptions');
229231
$extensionAttributesMock->expects($this->any())->method('setConfigurableProductLinks');
230-
231232
$this->productRepository->expects($this->once())->method('save');
232-
233233
$this->assertTrue(true, $this->object->addChild($productSku, $childSku));
234234
}
235235

0 commit comments

Comments
 (0)