function it_generates_a_query_to_update_product_select_attributes($namingUtility, AttributeOptionInterface $blue, AttributeInterface $color) { $blue->getAttribute()->willReturn($color); $namingUtility->getAttributeNormFields($color)->willReturn(['normalizedData.color-fr_FR', 'normalizedData.color-en_US']); $blue->getCode()->willReturn('blue'); $this->generateQuery($blue, 'code', 'blue', 'bluee')->shouldReturn([[['normalizedData.color-fr_FR' => ['$elemMatch' => ['code' => 'blue']]], ['$set' => ['normalizedData.color-fr_FR.$.code' => 'bluee']], ['multiple' => true]], [['normalizedData.color-en_US' => ['$elemMatch' => ['code' => 'blue']]], ['$set' => ['normalizedData.color-en_US.$.code' => 'bluee']], ['multiple' => true]]]); }
function it_does_violations_if_attribute_type_is_not_allowed($context, AttributeOptionInterface $attributeOption, AttributeInterface $notAllowedAttribute, AttributeTypeForOption $constraint, ConstraintViolationBuilderInterface $violation) { $attributeOption->getAttribute()->willReturn($notAllowedAttribute); $notAllowedAttribute->getAttributeType()->willReturn(AttributeTypes::TEXT); $notAllowedAttribute->getCode()->willReturn('attributeCode'); $violationData = ['%attribute%' => 'attributeCode']; $context->buildViolation($constraint->invalidAttributeMessage, $violationData)->shouldBeCalled()->willReturn($violation); $this->validate($attributeOption, $constraint); }
function it_does_not_update_readonly_fields_on_an_existing_attribute_option(AttributeOptionInterface $attributeOption, AttributeOptionValueInterface $attributeOptionValue) { $attributeOption->getId()->willReturn(42); $attributeOption->getAttribute()->willReturn(null); // read only fields $attributeOption->setCode('mycode')->shouldNotBeCalled(); $attributeOption->setAttribute(Argument::any())->shouldNotBeCalled(); $attributeOption->setSortOrder(12)->shouldBeCalled(); $attributeOption->setLocale('de_DE')->shouldBeCalled(); $attributeOption->getTranslation()->willReturn($attributeOptionValue); $attributeOptionValue->setLabel('210 x 1219 mm')->shouldBeCalled(); $this->update($attributeOption, ['code' => 'mycode', 'attribute' => 'myattribute', 'sort_order' => 12, 'labels' => ['de_DE' => '210 x 1219 mm']]); }
function it_provides_all_locales_if_no_list_provided_in_context(AttributeOptionInterface $option, AttributeInterface $attribute, AttributeOptionValueInterface $valueEn, AttributeOptionValueInterface $valueFr, AttributeOptionValueInterface $valueDe) { $option->getCode()->willReturn('red'); $option->getAttribute()->willReturn($attribute); $option->getSortOrder()->willReturn(1); $attribute->getCode()->willReturn('color'); $option->getOptionValues()->willReturn(['en_US' => $valueEn, 'fr_FR' => $valueFr, 'de_DE' => $valueDe]); $valueEn->getLocale()->willReturn('en_US'); $valueEn->getValue()->willReturn('Red'); $valueFr->getLocale()->willReturn('fr_FR'); $valueFr->getValue()->willReturn('Rouge'); $valueDe->getLocale()->willReturn('de_DE'); $valueDe->getValue()->willReturn(''); $this->normalize($option, null, ['locales' => []])->shouldReturn(['attribute' => 'color', 'code' => 'red', 'sort_order' => 1, 'label' => ['en_US' => 'Red', 'fr_FR' => 'Rouge', 'de_DE' => '']]); }
function it_throws_an_exception_when_attribute_option_is_not_valid($attributeRepository, $validator, AttributeOptionInterface $attributeOption, AttributeInterface $attribute, AttributeGroupInterface $attributeGroup, AttributeOptionValueInterface $attributeOptionValue) { $attributeOption->getId()->willReturn(null); $attributeOption->getAttribute()->willReturn($attribute); $attribute->getGroup()->willReturn($attributeGroup); $attributeOption->setCode('mycode')->shouldBeCalled(); $attributeRepository->findOneByIdentifier('myattribute')->willReturn(null); $attributeOption->setAttribute($attribute)->shouldNotBeCalled(); $attributeOption->setSortOrder(12)->shouldBeCalled(); $attributeOption->setLocale('de_DE')->shouldBeCalled(); $attributeOption->getTranslation()->willReturn($attributeOptionValue); $attributeOptionValue->setLabel('210 x 1219 mm')->shouldBeCalled(); $violationList = new ConstraintViolationList(); $violationList->add(new ConstraintViolation('', '', [], $attributeOption, null, null)); $validator->validate($attributeOption)->willReturn($violationList); $this->shouldThrow('Pim\\Bundle\\CatalogBundle\\Exception\\BusinessValidationException')->during('update', [$attributeOption, ['code' => 'mycode', 'attribute' => 'myattribute', 'sort_order' => 12, 'labels' => ['de_DE' => '210 x 1219 mm']]]); }
/** * {@inheritdoc} */ public function findAllWithAttributeOption(AttributeOptionInterface $option) { $backendType = $option->getAttribute()->getBackendType(); $qb = $this->createQueryBuilder('p')->leftJoin('p.values', 'value')->leftJoin(sprintf('value.%s', $backendType), 'option'); if ('options' === $backendType) { $qb->where($qb->expr()->in('option', ':option')); } else { $qb->where('option=:option'); } return $qb->setParameter('option', $option)->getQuery()->getResult(); }
/** * {@inheritdoc} */ public function findAllWithAttributeOption(AttributeOptionInterface $option) { $id = (int) $option->getId(); $qb = $this->createQueryBuilder('p'); if ('options' === $option->getAttribute()->getBackendType()) { $qb->field('values.optionIds')->in([$id]); } else { $qb->field('values.option')->equals($id); } return $qb->getQuery()->execute()->toArray(); }
/** * @param AttributeTypeForOption $constraint * @param AttributeOptionInterface $option */ protected function addInvalidAttributeViolation(AttributeTypeForOption $constraint, AttributeOptionInterface $option) { $this->context->buildViolation($constraint->invalidAttributeMessage, ['%attribute%' => $option->getAttribute()->getCode()])->addViolation(); }
/** * @param AttributeOptionInterface $attributeOption * * @throws \InvalidArgumentException * * @return ConstraintViolationListInterface */ protected function validateAttributeOption(AttributeOptionInterface $attributeOption) { // TODO: ugly fix to workaround issue with "attribute.group.code: This value should not be blank." // in case of existing option, attribute is a proxy, attribute group too, the validated group code is null null !== $attributeOption->getAttribute() ? $attributeOption->getAttribute()->getGroup()->getCode() : null; return $this->validator->validate($attributeOption); }