function it_normalizes_attribute_for_versioning($attribute)
 {
     $attribute->getLocaleSpecificCodes()->willReturn(['en_US', 'fr_FR']);
     $attribute->isLocalizable()->willReturn(true);
     $attribute->isScopable()->willReturn(true);
     $size = new AttributeOption();
     $size->setCode('size');
     $en = new AttributeOptionValue();
     $fr = new AttributeOptionValue();
     $en->setLocale('en_US');
     $en->setValue('big');
     $fr->setLocale('fr_FR');
     $fr->setValue('grand');
     $size->addOptionValue($en);
     $size->addOptionValue($fr);
     $attribute->getOptions()->willReturn(new ArrayCollection([$size]));
     $attribute->getSortOrder()->willReturn(1);
     $attribute->isRequired()->willReturn(false);
     $attribute->getMaxCharacters()->willReturn(null);
     $attribute->getValidationRule()->willReturn(null);
     $attribute->getValidationRegexp()->willReturn(null);
     $attribute->isWysiwygEnabled()->willReturn(false);
     $attribute->getNumberMin()->willReturn(1);
     $attribute->getNumberMax()->willReturn(10);
     $attribute->isDecimalsAllowed()->willReturn(false);
     $attribute->isNegativeAllowed()->willReturn(false);
     $attribute->getDateMin()->willReturn(null);
     $attribute->getDateMax()->willReturn(null);
     $attribute->getMaxFileSize()->willReturn(0);
     $this->normalize($attribute, null, ['versioning' => true])->shouldReturn(['type' => 'Yes/No', 'code' => 'attribute_size', 'group' => 'size', 'unique' => 1, 'useable_as_grid_filter' => 0, 'allowed_extensions' => 'csv,xml,json', 'metric_family' => 'Length', 'default_metric_unit' => 'Centimenter', 'reference_data_name' => 'color', 'available_locales' => 'en_US,fr_FR', 'localizable' => true, 'scope' => 'Channel', 'options' => 'Code:size,en_US:big,fr_FR:grand', 'sort_order' => 1, 'required' => 0, 'max_characters' => '', 'validation_rule' => '', 'validation_regexp' => '', 'wysiwyg_enabled' => '', 'number_min' => '1', 'number_max' => '10', 'decimals_allowed' => '', 'negative_allowed' => '', 'date_min' => '', 'date_max' => '', 'metric_family' => 'Length', 'default_metric_unit' => 'Centimenter', 'max_file_size' => '0']);
 }
 function it_generates_a_query_to_update_product_select_attributes($namingUtility, AttributeOptionValue $bleu, AttributeOption $blue, AbstractAttribute $color)
 {
     $bleu->getOption()->willReturn($blue);
     $bleu->getLocale()->willReturn('fr_FR');
     $blue->getAttribute()->willReturn($color);
     $namingUtility->getAttributeNormFields($color)->willReturn(['normalizedData.color-fr_FR', 'normalizedData.color-en_US']);
     $blue->getCode()->willReturn('blue');
     $this->generateQuery($bleu, 'value', 'Bleu', 'Bleus')->shouldReturn([[['normalizedData.color-fr_FR' => ['$elemMatch' => ['code' => 'blue']]], ['$set' => ['normalizedData.color-fr_FR.$.optionValues.fr_FR.value' => 'Bleus']], ['multiple' => true]], [['normalizedData.color-en_US' => ['$elemMatch' => ['code' => 'blue']]], ['$set' => ['normalizedData.color-en_US.$.optionValues.fr_FR.value' => 'Bleus']], ['multiple' => true]]]);
 }
 /**
  * Add attribute option labels
  *
  * @param AttributeOption $option
  * @param array           $data
  */
 protected function addAttributeOptionLabels(AttributeOption $option, array $data)
 {
     foreach ($data['label'] as $locale => $data) {
         $value = new AttributeOptionValue();
         $value->setLocale($locale);
         $value->setValue($data);
         $option->addOptionValue($value);
     }
 }
 function it_normalizes_attribute_option(AttributeOption $option, AttributeOptionValue $valueUs, AttributeOptionValue $valueFr)
 {
     $option->getId()->willReturn(42);
     $option->getCode()->willReturn('red');
     $valueUs->getLocale()->willReturn('en_US');
     $valueUs->getValue()->willReturn('Red');
     $valueFr->getLocale()->willReturn('fr_FR');
     $valueFr->getValue()->willReturn('Rouge');
     $option->getOptionValues()->willReturn([$valueUs, $valueFr]);
     $this->normalize($option, 'mongodb_json', [])->shouldReturn(['id' => 42, 'code' => 'red', 'optionValues' => ['en_US' => ['value' => 'Red', 'locale' => 'en_US'], 'fr_FR' => ['value' => 'Rouge', 'locale' => 'fr_FR']]]);
 }
 /**
  * Test __toString method
  */
 public function testToString()
 {
     $code = 'test_code';
     $this->attributeOption->setCode($code);
     $this->assertSame('[' . $code . ']', $this->attributeOption->__toString());
     $newValue = 'test_value';
     $optionValue = new AttributeOptionValue();
     $optionValue->setValue($newValue);
     $this->attributeOption->addOptionValue($optionValue);
     $this->assertSame($newValue, $this->attributeOption->__toString());
 }
 function it_normalizes_the_whole_option(AttributeOption $option, AbstractAttribute $attribute, AttributeOptionValue $valueEn, AttributeOptionValue $valueFr)
 {
     $option->getCode()->willReturn('red');
     $option->getAttribute()->willReturn($attribute);
     $option->isDefault()->willReturn(true);
     $attribute->getCode()->willReturn('color');
     $option->getOptionValues()->willReturn(['en_US' => $valueEn, 'fr_FR' => $valueFr]);
     $valueEn->getLocale()->willReturn('en_US');
     $valueEn->getValue()->willReturn('Red');
     $valueFr->getLocale()->willReturn('fr_FR');
     $valueFr->getValue()->willReturn('Rouge');
     $this->normalize($option, null, ['locales' => ['en_US', 'fr_FR', 'de_DE']])->shouldReturn(['attribute' => 'color', 'code' => 'red', 'default' => '1', 'label-en_US' => 'Red', 'label-fr_FR' => 'Rouge', 'label-de_DE' => '']);
 }
 /**
  * {@inheritdoc}
  */
 public function getTranslation()
 {
     $value = $this->getOptionValue();
     if (!$value) {
         $value = new AttributeOptionValue();
         $value->setLocale($this->locale);
         $this->addOptionValue($value);
     }
     return $value;
 }
 /**
  * Create attribute options
  *
  * @param AttributeInterface $attribute
  * @param array              $data
  */
 protected function addOptions(AttributeInterface $attribute, $data)
 {
     $options = array_filter(explode('|', $data['options']));
     foreach ($options as $option) {
         $attributeOption = new AttributeOption();
         $translations = explode(',', $option);
         foreach ($translations as $translation) {
             $translation = explode(':', $translation);
             $locale = reset($translation);
             $value = end($translation);
             if ($locale == 'Code') {
                 $attributeOption->setCode($value);
             } else {
                 $optionValue = new AttributeOptionValue();
                 $optionValue->setLocale($locale);
                 $optionValue->setValue($value);
                 $attributeOption->addOptionValue($optionValue);
             }
         }
         $attribute->addOption($attributeOption);
     }
 }
 /**
  * Add option value
  *
  * @param AttributeOptionValue $value
  *
  * @return AbstractAttribute
  */
 public function addOptionValue(AttributeOptionValue $value)
 {
     $this->optionValues[] = $value;
     $value->setOption($this);
     return $this;
 }
 /**
  * Create attribute options
  *
  * @param AttributeInterface $attribute
  * @param array              $data
  */
 protected function addOptions(AttributeInterface $attribute, $data)
 {
     if (count($data['options']) === 1) {
         $attribute->setBackendType('option');
     } elseif (count($data['options']) > 1) {
         $attribute->setBackendType('option');
     }
     foreach ($data['options'] as $code => $values) {
         $attributeOption = new AttributeOption();
         $attributeOption->setCode($code);
         foreach ($values as $locale => $value) {
             $optionValue = new AttributeOptionValue();
             $optionValue->setLocale($locale);
             $optionValue->setValue($value);
             $attributeOption->addOptionValue($optionValue);
         }
         $attribute->addOption($attributeOption);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setLabel($label)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setLabel', array($label));
     return parent::setLabel($label);
 }