/** * Fetch the attribute by its code * * @param string $code * * @throws \LogicException * * @return AttributeInterface */ protected function getAttribute($code) { $attribute = $this->attributeRepository->findOneBy(['code' => $code]); if ($attribute === null) { throw new \LogicException(sprintf('Unknown attribute "%s".', $code)); } return $attribute; }
/** * {@inheritdoc} */ public function getFilter($code) { $attribute = $this->attributeRepository->findOneBy(['code' => FieldFilterHelper::getCode($code)]); if (null !== $attribute) { return $this->getAttributeFilter($attribute); } return $this->getFieldFilter($code); }
/** * {@inheritdoc} */ public function convertDefaultToLocalizedValue($code, $data, $options = []) { $attribute = $this->attributeRepository->findOneBy(['code' => $code]); if (null === $attribute) { return $data; } $attributeType = $attribute->getAttributeType(); if (null === $attributeType) { return $data; } $localizer = $this->localizerRegistry->getLocalizer($attributeType); if (null === $localizer) { return $data; } return $localizer->convertDefaultToLocalized($data, $options); }
/** * {@inheritdoc} */ public function addSorter($field, $direction, array $context = []) { $attribute = $this->attributeRepository->findOneBy(['code' => $field]); if ($attribute !== null) { $sorter = $this->sorterRegistry->getAttributeSorter($attribute); } else { $sorter = $this->sorterRegistry->getFieldSorter($field); } if ($sorter === null) { throw new \LogicException(sprintf('Sorter on field "%s" is not supported', $field)); } $context = $this->getFinalContext($context); if ($attribute !== null) { $this->addAttributeSorter($sorter, $attribute, $direction, $context); } else { $this->addFieldSorter($sorter, $field, $direction, $context); } return $this; }
/** * 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; }
/** * Fetch the attribute by its code * * @param string $code * * @throws \LogicException * * @return AttributeInterface|null */ protected function getAttribute($code) { $attribute = $this->attributeRepository->findOneBy(['code' => $code]); return $attribute; }
/** * Return the identifier attribute * * @return AttributeInterface|null */ protected function getIdentifierAttribute() { return $this->attributeRepository->findOneBy(['attributeType' => AttributeTypes::IDENTIFIER]); }
function it_provides_the_identifier_attribute(AttributeRepositoryInterface $attributeRepository, AttributeInterface $sku) { $attributeRepository->findOneBy(['attributeType' => 'pim_catalog_identifier'])->willReturn($sku); $this->getIdentifierAttribute()->shouldReturn($sku); }
/** * Return the identifier attribute * * @return AttributeInterface|null */ protected function getIdentifierAttribute() { return $this->attributeRepository->findOneBy(['attributeType' => 'pim_catalog_identifier']); }