I am trying to update a configurable product programmatically but when i am running the script i am getting "Option values are not specified." exception. I am not sure whats wrong i am doing. Here is code that i am using
$superAttribute = [151,152];
configurableProductId =10;
$sku = "B510";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager
$productFactory = $objectManager->create('\Magento\Catalog\Model\Product');
$configurableProduct = $productFactory->load($configurableProductId);
$simpleProductIds = [1,2,3,4,5,6];
$objectManager->create('Magento\ConfigurableProduct\Model\Product\Type\Configurable')->setUsedProductAttributeIds($superAttribute, $configurableProduct);
$configurableProduct->setAssociatedProductIds($simpleProductIds);// Setting Associated Products
$configurableProduct->setCanSaveConfigurableAttributes(true);
$configurableProduct->save();
$output->writeln($sku.' configurable product updated');
Note: We need to update already created configurable products not to create new configurable product. Also, please ignore the use of object manager. I am aware that the use of the object manager is not recommended.