1

I am having trouble associating a newly created simple product to an existing configurable product that already have simple products associated.

Using the code below, it will delete the existing simple products associated to the configurable product and add the new one. I want to keep the old simple products associated with the configurable product.

$product = $this->productRepository->get($sku);
$product->setAssociatedProductIds($new_simple_product_ids);
$this->productRepository->save($product);

I also seems that if configurable products doesn't have any simple products yet it will fail with this error:

[Magento\Framework\Exception\InputException] Option values are not specified.

I have tried going through different approaches it this seems the closes but I am unsure how it applies to my problem:

Programmatically create a configurable product and assign the simple product to configurable product in Magento2 product

1

if the configurable has no simples associated yet it doesn't even have attributes selected to connect those simples by. That's why it's breaking.

To add new simple to configurable take a look at: vendor\magento\module-configurable-product\Model\LinkManagement.php

and function addChild($sku, $childSku)

It is taking all values from configurable, then just adds them again with the new one included.

  • thx for the hint. after searching for 3 days ;D – ZFNerd Aug 13 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.