/**
  * {@inheritdoc}
  */
 public function removeAttributeFromProduct(ProductInterface $product, AttributeInterface $attribute)
 {
     foreach ($product->getValues() as $value) {
         if ($attribute === $value->getAttribute()) {
             $product->removeValue($value);
         }
     }
     $this->objectManager->flush($product);
 }
 /**
  * Denormalize product values
  *
  * @param string           $data
  * @param string           $format
  * @param array            $context
  * @param ProductInterface $product
  */
 protected function denormalizeValues($data, $format, array $context, ProductInterface $product)
 {
     foreach ($product->getValues() as $value) {
         $product->removeValue($value);
     }
     foreach ($data as $attFieldName => $dataValue) {
         $attributeInfos = $this->fieldNameBuilder->extractAttributeFieldNameInfos($attFieldName);
         $attribute = $attributeInfos['attribute'];
         unset($attributeInfos['attribute']);
         if (!$product->hasAttribute($attribute)) {
             $this->productBuilder->addAttributeToProduct($product, $attribute);
         }
         // Denormalize data value.
         // The value is already added to the product so automatically updated
         $productValue = $product->getValue($attribute->getCode(), $attributeInfos['locale_code'], $attributeInfos['scope_code']);
         $this->serializer->denormalize($dataValue, $this->productValueClass, $format, ['product' => $product, 'entity' => $productValue] + $attributeInfos + $context);
     }
 }
예제 #3
0
 /**
  * Deletes values that link an attribute to a product
  *
  * @param ProductInterface   $product
  * @param AttributeInterface $attribute
  * @param array              $savingOptions
  *
  * @deprecated Will be removed in 1.5, please use ProductBuilderInterface::removeAttributeFromProduct() and
  *             ProductSaver::save() instead.
  */
 public function removeAttributeFromProduct(ProductInterface $product, AttributeInterface $attribute, array $savingOptions = [])
 {
     foreach ($product->getValues() as $value) {
         if ($attribute === $value->getAttribute()) {
             $product->removeValue($value);
         }
     }
     $options = array_merge(['recalculate' => false, 'schedule' => false], $savingOptions);
     $this->productSaver->save($product, $options);
 }