Hi everyone.
I try to add configurable product programically, but in some cases i can't make entry in catalog_product_super_attribute table.
My code:
$attributeModel = $this->configurableAttributeFactory->create(); $linked = $attributeModel->getCollection() ->addFieldToFilter('attribute_id', $attributeId) ->addFieldToFilter('product_id', $configurable->getId()) ->getSize(); if (!$linked) { $attributeModel->setData($data); $attributeModel->validateBeforeSave(); $attributeModel->save(); var_dump($attributeModel->getData()); }
After save var_dump returns primary_key for this entry, but the entry is not exists in the database table.
array(5) { ["attribute_id"]=> string(3) "146" ["product_id"]=> string(5) "98106" ["position"]=> int(0) ["product_super_attribute_id"]=> string(5) "36407" ["id"]=> string(5) "36407" }
Do you have any suggestons?
Solved! Go to Solution.
@Webcode It is recommend to use the Magento RSET API
Fist create Simple product
https://devdocs.magento.com/guides/v2.3/rest/tutorials/configurable-product/create-simple-products.html
Then create Configurable product
https://devdocs.magento.com/guides/v2.3/rest/tutorials/configurable-product/define-config-product-options.html
@Webcode It is recommend to use the Magento RSET API
Fist create Simple product
https://devdocs.magento.com/guides/v2.3/rest/tutorials/configurable-product/create-simple-products.html
Then create Configurable product
https://devdocs.magento.com/guides/v2.3/rest/tutorials/configurable-product/define-config-product-options.html