コード例 #1
0
 /**
  * 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->propertySetter->setData($product, $action['field'], $action['value']);
     }
     return $this;
 }
コード例 #2
0
 /**
  * Sets the product values,
  *  - always set values related to family's attributes
  *  - sets optional values (not related to family's attributes) when a data is provided
  *  - sets optional values (not related to family's attributes) with empty data if value already exists
  *
  * @param ProductInterface $product
  * @param string           $attributeCode
  * @param array            $values
  */
 protected function updateProductValues(ProductInterface $product, $attributeCode, array $values)
 {
     $family = $product->getFamily();
     $authorizedCodes = null !== $family ? $family->getAttributeCodes() : [];
     $isFamilyAttribute = in_array($attributeCode, $authorizedCodes);
     foreach ($values as $value) {
         $hasValue = $product->getValue($attributeCode, $value['locale'], $value['scope']);
         $providedData = '' === $value['data'] || [] === $value['data'] || null === $value['data'] ? false : true;
         if ($isFamilyAttribute || $providedData || $hasValue) {
             $options = ['locale' => $value['locale'], 'scope' => $value['scope']];
             $this->propertySetter->setData($product, $attributeCode, $value['data'], $options);
         }
     }
 }
コード例 #3
0
 /**
  * Updates product with the provided request data
  *
  * @param ProductInterface $product
  * @param array            $data
  */
 protected function updateProduct(ProductInterface $product, array $data)
 {
     foreach ($data as $item => $itemData) {
         if ('values' === $item) {
             foreach ($itemData as $attributeCode => $values) {
                 foreach ($values as $value) {
                     $this->productUpdater->setData($product, $attributeCode, $value['data'], ['locale' => $value['locale'], 'scope' => $value['scope']]);
                 }
             }
         } else {
             $this->productUpdater->setData($product, $item, $itemData);
         }
     }
 }
コード例 #4
0
 /**
  * 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']);
         }
         if ($product->isAttributeEditable($attribute)) {
             $this->propertySetter->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;
 }
コード例 #5
0
 /**
  * @param array  $products
  * @param string $attributeCode
  * @param mixed  $data
  */
 protected function updateProducts(array $products, $attributeCode, $data)
 {
     foreach ($products as $product) {
         $this->propertySetter->setData($product, $attributeCode, $data['value'], ['locale' => $data['locale'], 'scope' => $data['scope']]);
     }
 }