0

I am trying to be able to create/update a product programatically based on an API call in magento 2.1. I have everything working except for setting our 'Product Brand' multi select attribute. Using code found from stack exchange answers, this is what I have which isn't working:

//...
$product->setData('product_brand', $brands);

Where $brands is a CSV separated string of author names. However, I can hard code in one of the author names or their ID and the result is the same. The rest of the code works fine, and the product does get saved - but without any of the multi select options selected.

If I also include:

$product->getResource()->saveAttribute($product, 'product_brand');

Then I receive an SQL error and the product does not save: Exception PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails ([my user].catalog_product_entity_varchar, CONSTRAINT CAT_PRD_ENTT_VCHR_ENTT_ID_CAT_PRD_ENTT_ENTT_ID FOREIGN KEY (entity_id) REFERENCES catalog_product_entity (entity_id) ON DELETE )

Any help would be appreciated.

1

Your Answer

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

Browse other questions tagged or ask your own question.