/**
  * Set data from $actions to the given $product
  *
  * @param ProductInterface $product
  * @param array            $actions
  *
  * @return UpdateProductValueProcessor
  */
 protected function setData(ProductInterface $product, array $actions)
 {
     foreach ($actions as $action) {
         $this->productUpdater->setData($product, $action['field'], $action['value']);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function update(ProductTemplateInterface $template, array $products)
 {
     $updates = $template->getValuesData();
     foreach ($updates as $attributeCode => $values) {
         foreach ($values as $value) {
             $this->productUpdater->setValue($products, $attributeCode, $value['value'], $value['locale'], $value['scope']);
         }
     }
 }
 /**
  * Set product values with the one stored inside $this->values
  *
  * @param ProductInterface $product
  */
 protected function setProductValues(ProductInterface $product)
 {
     foreach ($this->values as $value) {
         $rawData = $this->normalizer->normalize($value->getData(), 'json', ['entity' => 'product']);
         // if the value is localizable, let's use the locale the user has chosen in the form
         $locale = null !== $value->getLocale() ? $this->getLocale()->getCode() : null;
         $this->productUpdater->setValue([$product], $value->getAttribute()->getCode(), $rawData, $locale, $value->getScope());
     }
 }
 /**
  * Set data from $actions to the given $product
  *
  * Actions should looks like that
  *
  * $actions =
  * [
  *     [
  *          'field'   => 'group',
  *          'value'   => 'summer_clothes',
  *          'options' => null
  *      ],
  *      [
  *          'field'   => 'category',
  *          'value'   => 'catalog_2013,catalog_2014',
  *          'options' => null
  *      ],
  * ]
  *
  * @param ProductInterface $product
  * @param array            $actions
  *
  * @throws \LogicException
  *
  * @return ProductInterface $product
  */
 protected function updateProduct(ProductInterface $product, array $actions)
 {
     $modifiedAttributesNb = 0;
     foreach ($actions as $action) {
         $attribute = $this->attributeRepository->findOneBy(['code' => $action['field']]);
         if (null === $attribute) {
             throw new \LogicException(sprintf('Attribute with code %s does not exist'), $action['field']);
         }
         $family = $product->getFamily();
         if (null !== $family && $family->hasAttribute($attribute)) {
             $this->productUpdater->setData($product, $action['field'], $action['value'], $action['options']);
             $modifiedAttributesNb++;
         }
     }
     if (0 === $modifiedAttributesNb) {
         $this->stepExecution->incrementSummaryInfo('skipped_products');
         $this->stepExecution->addWarning($this->getName(), 'pim_enrich.mass_edit_action.edit-common-attributes.message.no_valid_attribute', [], $product);
         return null;
     }
     return $product;
 }
 /**
  * @param array  $products
  * @param string $attributeCode
  * @param mixed  $data
  */
 protected function updateProducts(array $products, $attributeCode, $data)
 {
     foreach ($products as $product) {
         $this->productUpdater->setData($product, $attributeCode, $data['value'], ['locale' => $data['locale'], 'scope' => $data['scope']]);
     }
 }