/** * Save configurable product attributes * * @param ProductInterface $product * @return void * @throws \Exception * @deprecated */ private function saveConfigurableOptions(ProductInterface $product) { $data = $product->getConfigurableAttributesData(); if (!$data) { return; } $metadata = $this->metadataPool->getMetadata(ProductInterface::class); foreach ($data as $attributeData) { /** @var $configurableAttribute \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute */ $configurableAttribute = $this->configurableAttributeFactory->create(); if (!$product->getIsDuplicate()) { if (!empty($attributeData['id'])) { $configurableAttribute->load($attributeData['id']); $attributeData['attribute_id'] = $configurableAttribute->getAttributeId(); } elseif (!empty($attributeData['attribute_id'])) { $attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeData['attribute_id']); $attributeData['attribute_id'] = $attribute->getId(); if (!$this->canUseAttribute($attribute)) { throw new \InvalidArgumentException('Provided attribute can not be used with configurable product'); } $configurableAttribute->loadByProductAndAttribute($product, $attribute); } } unset($attributeData['id']); $configurableAttribute->addData($attributeData)->setStoreId($product->getStoreId())->setProductId($product->getData($metadata->getLinkField()))->save(); } /** @var $configurableAttributesCollection \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection */ $configurableAttributesCollection = $this->_attributeCollectionFactory->create(); $configurableAttributesCollection->setProductFilter($product); $configurableAttributesCollection->addFieldToFilter('attribute_id', ['nin' => $this->getUsedProductAttributeIds($product)]); $configurableAttributesCollection->walk('delete'); }