/** * {@inheritdoc} */ public function addData($data) { $backendType = $this->attribute->getBackendType(); if ($this->attribute->isBackendTypeReferenceData()) { $backendType = $this->attribute->getReferenceDataName(); } if (substr($backendType, -1, 1) === 's') { $backendType = substr($backendType, 0, strlen($backendType) - 1); } $name = 'add' . ucfirst($backendType); return $this->{$name}($data); }
function it_sets_the_locale_and_scope_when_denormalizing_values($serializer, AttributeInterface $attribute) { $attribute->getAttributeType()->willReturn('pim_catalog_number'); $attribute->getBackendType()->willReturn('decimal'); $attribute->isBackendTypeReferenceData()->willReturn(false); $attribute->isLocalizable()->willReturn(true); $attribute->isScopable()->willReturn(true); $serializer->denormalize(1, 'pim_catalog_number', 'json', Argument::type('array'))->shouldBeCalled()->willReturn(1); $value = $this->denormalize(['data' => 1, 'locale' => 'en_US', 'scope' => 'ecommerce'], 'Pim\\Component\\Catalog\\Model\\ProductValue', 'json', ['attribute' => $attribute]); $value->shouldBeAnInstanceOf('Pim\\Component\\Catalog\\Model\\ProductValue'); $value->getData()->shouldReturn(1); $value->getLocale()->shouldReturn('en_US'); $value->getScope()->shouldReturn('ecommerce'); }
function it_adds_a_violation_when_validating_product_in_groups_with_non_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, ProductInterface $redTShirtProduct2, UniqueVariantAxis $uniqueVariantAxisConstraint, ConstraintViolationBuilderInterface $violation) { $redTShirtProduct->getVariantGroup()->willReturn($tShirtVariantGroup); $tShirtVariantGroup->getId()->willReturn(1); $tShirtVariantGroup->getLabel()->willReturn('TShirts'); $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]); $sizeAttribute->getCode()->willReturn('size'); $sizeAttribute->isBackendTypeReferenceData()->willReturn(true); $sizeAttribute->getReferenceDataName()->willReturn('ref_size'); $colorAttribute->getCode()->willReturn('color'); $colorAttribute->isBackendTypeReferenceData()->willReturn(true); $colorAttribute->getReferenceDataName()->willReturn('ref_color'); $redTShirtProduct->getValue('size')->willReturn($sizeProductValue); $redTShirtProduct->getValue('color')->willReturn($colorProductValue); $redTShirtProduct->getId()->willReturn(1); $sizeProductValue->getData()->willReturn('XL'); $sizeProductValue->getOption()->willReturn(null); $colorProductValue->getData()->willReturn('Red'); $colorProductValue->getOption()->willReturn(null); $criteria = [['attribute' => $sizeAttribute, 'referenceData' => ['name' => 'ref_size', 'data' => 'XL']], ['attribute' => $colorAttribute, 'referenceData' => ['name' => 'ref_color', 'data' => 'Red']]]; $productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->shouldBeCalled()->willReturn([$redTShirtProduct2]); $context->buildViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'TShirts', '%values%' => 'size: XL, color: Red'])->shouldBeCalled()->willReturn($violation); $this->validate($redTShirtProduct, $uniqueVariantAxisConstraint); }
/** * Returns available information for the attribute and filters which supports it * * @param AttributeInterface $attribute * @param array $attributeFilters * * @return array */ protected function getFilterInformationForAttribute(AttributeInterface $attribute, array $attributeFilters) { $field = $attribute->getCode(); $attributeType = $attribute->getAttributeType(); $isLocalizable = $attribute->isLocalizable() ? 'yes' : 'no'; $isScopable = $attribute->isScopable() ? 'yes' : 'no'; $newEntries = []; if (array_key_exists($attributeType, $attributeFilters)) { foreach ($attributeFilters[$attributeType] as $filter) { $class = get_class($filter); $operators = implode(', ', $filter->getOperators()); $newEntries[] = [$field, $isLocalizable, $isScopable, $attributeType, $operators, $class]; } return $newEntries; } if ($attribute->isBackendTypeReferenceData()) { foreach ($this->registry->getAttributeFilters() as $filter) { if ($filter->supportsAttribute($attribute)) { $class = get_class($filter); $operators = implode(', ', $filter->getOperators()); $newEntries[] = [$field, $isLocalizable, $isScopable, $attributeType, $operators, $class]; } } return $newEntries; } return [[$field, $isLocalizable, $isScopable, $attributeType, '', 'Not supported']]; }