I have an import script that loads a feed, creates custom attributes, and assigns them to sets.
Now I'm looking for a way to add product information to these attributes, preferably by attribute code, so once I have the product model ready I can set the value and save.
/**
* @var Magento\Catalog\Model\Product
*/
protected $_modelProduct;
/**
* Update product attribute
*
* @param integer $productId
* @param string $attributeCode
* @param string $value
*/
public function updateProductAttribute($productId, $attributeCode, $value)
{
$model = $this->_modelProduct
->load($productId);
/* Update product attribute with new value */
}
Any help is very much appreciated.
Thanks
That one should be working.
$model->addData(array('custom_attribute' => 'foobar'));
$model->save();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.