I have created product programmatically but when i try to update attribute value with code:
$product->setData($attributeCode, '')->save();
It won't change. The update will work only after i have saved the product in Magento admin GUI. What might be the reason of that?
Code I use to create product:
$_product->setName($productName)
->setId($productID)
->setAttributeSetId($attributeSetId)
->setStoreId($storeId)
->setVisibility(4)
->setStatus(1)
->setWebsiteIds(array(1))
->setSku($Sku)
->setPrice($price)
->setDescription($description)
->setShortDescription($shortDescription)
->setStockData(array(
'use_config_manage_stock' => 0,
'is_in_stock' => $stock,
'qty' => $qty
))
->setUrlKey($urlKey)
->setCategoryIds(array($CategoryId))
->setTypeId("simple")
->setData($attributeCode, 5)
->save();
Editing script
`$_product->load($productID)->setStoreId($storeId)->setData($attributeCode, 'Blue')->save();`
$_product
is an instance of \Magento\Catalog\Model\Product
.