Skip to content

Trying to create a configurable product, I get “Option values are not specified” error

I have an error that occurs randomly when I go to create a configurable product.
The process is as follows:
First I create all the simple products and in an array, I store all the ids of the simple products.
Then through the following code, I go to create the configurable product.

$this->_product->save(); //$this->_product Corresponds to the configurable product with the weight, sku set

$this->_productIdCreated = $this->_product->getId();

$configurableproduct_load = $this->_objectManager->create('MagentoCatalogModelProduct')->load($this->_productIdCreated);

$configurableproduct_load->setAssociatedProductIds($listSku);

$configurableproduct_load->setCanSaveConfigurableAttributes(true);

$configurableproduct_load->save(); //The error is generated at this point

If I start the script for creating products via php script, the configurable product is not always created giving the following error: “ERROR: “Option values are not specified”.

The error doesn’t show up every time, but a few times.
When the error is generated, all the simple products to the associated custom product exist with their attributes set.
The custom product is not created.
What can I do? Using magento 2.4.1.

Thank you all