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_normalizes_an_attribute_option(AttributeOptionInterface $attributeOption, AttributeInterface $attribute, AttributeOptionValueInterface $valueEn, AttributeOptionValueInterface $valueFr)
 {
     $attributeOption->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('color');
     $attributeOption->getCode()->willReturn('red');
     $attributeOption->getOptionValues()->willReturn(['en_US' => $valueEn, 'fr_FR' => $valueFr]);
     $attributeOption->getSortOrder()->willReturn(1);
     $valueEn->getLocale()->willReturn('en_US');
     $valueEn->getValue()->willReturn('Red');
     $valueFr->getLocale()->willReturn('fr_FR');
     $valueFr->getValue()->willReturn('Rouge');
     $this->normalize($attributeOption, 'standard', ['locales' => ['en_US', 'fr_FR', 'de_DE']])->shouldReturn(['code' => 'red', 'attribute' => 'color', 'sort_order' => 1, 'labels' => ['en_US' => 'Red', 'fr_FR' => 'Rouge', 'de_DE' => null]]);
 }
 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, 'labels' => ['en_US' => 'Red', 'fr_FR' => 'Rouge', 'de_DE' => '']]);
 }
 /**
  * @param AttributeTypeForOption   $constraint
  * @param AttributeOptionInterface $option
  */
 protected function addInvalidAttributeViolation(AttributeTypeForOption $constraint, AttributeOptionInterface $option)
 {
     $this->context->buildViolation($constraint->invalidAttributeMessage, ['%attribute%' => $option->getAttribute()->getCode()])->addViolation();
 }
 /**
  * {@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();
 }
 /**
  * {@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();
 }
 /**
  * @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);
 }