Skip to content

Commit dcc2686

Browse files
author
Oleksii Korshenko
authored
Merge pull request #384 from magento-okapis/MAGETWO-55126-Cannot-link-simple-product-to-configurable-one-2.1.2
Fixed issue: - MAGETWO-55126: [Backport] [API] Can not link simple product to configurable one - for 2.1.x
2 parents e656a00 + fa6ae74 commit dcc2686

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* @method Product setHasError(bool $value)
2323
* @method \Magento\Catalog\Model\ResourceModel\Product getResource()
2424
* @method null|bool getHasError()
25-
* @method Product setAssociatedProductIds(array $productIds)
2625
* @method array getAssociatedProductIds()
2726
* @method Product setNewVariationsAttributeSetId(int $value)
2827
* @method int getNewVariationsAttributeSetId()
@@ -2609,4 +2608,13 @@ private function getMediaGalleryProcessor()
26092608
}
26102609
return $this->mediaGalleryProcessor;
26112610
}
2611+
2612+
/**
2613+
* Set the associated products
2614+
* @param array $productIds
2615+
*/
2616+
public function setAssociatedProductIds(array $productIds)
2617+
{
2618+
$this->getExtensionAttributes()->setConfigurableProductLinks($productIds);
2619+
}
26122620
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function removeChild($sku, $childSku)
132132
if (count($options) == count($ids)) {
133133
throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
134134
}
135-
$product->addData(['associated_product_ids' => $ids]);
135+
$product->setAssociatedProductIds($ids);
136136
$product->save();
137137
return true;
138138
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ public function testAddChild()
159159
->will(
160160
$this->returnValue([0 => [1, 2, 3]])
161161
);
162-
$configurable->expects($this->once())->method('__call')->with('setAssociatedProductIds', [[1, 2, 3, 999]]);
163162
$configurable->expects($this->once())->method('save');
164163

165164
$this->assertTrue(true, $this->object->addChild($productSku, $childSku));
@@ -203,7 +202,7 @@ public function testRemoveChild()
203202
$childSku = 'simple_10';
204203

205204
$product = $this->getMockBuilder('Magento\Catalog\Model\Product')
206-
->setMethods(['getTypeInstance', 'save', 'getTypeId', 'addData', '__wakeup'])
205+
->setMethods(['getTypeInstance', 'save', 'getTypeId', 'addData', '__wakeup', 'getExtensionAttributes'])
207206
->disableOriginalConstructor()
208207
->getMock();
209208

@@ -231,7 +230,12 @@ public function testRemoveChild()
231230
$productType->expects($this->once())->method('getUsedProducts')
232231
->will($this->returnValue([$option]));
233232

234-
$product->expects($this->once())->method('addData')->with(['associated_product_ids' => []]);
233+
$extensionAttributesMock = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesInterface::class)
234+
->disableOriginalConstructor()
235+
->setMethods(['setConfigurableProductLinks'])
236+
->getMock();
237+
238+
$product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributesMock);
235239
$product->expects($this->once())->method('save');
236240
$this->assertTrue($this->object->removeChild($productSku, $childSku));
237241
}

0 commit comments

Comments
 (0)