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, AttributeOption $blue, AbstractAttribute $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', '', '')->shouldReturn([[['normalizedData.color-fr_FR.code' => 'blue'], ['$unset' => ['normalizedData.color-fr_FR' => '']], ['multiple' => true]], [['normalizedData.color-en_US.code' => 'blue'], ['$unset' => ['normalizedData.color-en_US' => '']], ['multiple' => true]]]);
 }
 /**
  * Returns an array containing the label values
  *
  * @param AttributeOption $entity
  * @param array           $context
  *
  * @return array
  */
 protected function normalizeLabel(AttributeOption $entity, $context)
 {
     $labels = array_fill_keys($context['locales'], '');
     foreach ($entity->getOptionValues() as $translation) {
         $labels[$translation->getLocale()] = $translation->getValue();
     }
     return array('label' => $labels);
 }
 /**
  * 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_raises_an_exception_if_a_error_occure_during_normalization_process(AttributeOption $optionRed, Attribute $attribute, $optionNormalizer, $webservice)
 {
     $optionRed->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('color');
     $optionRed->getCode()->willReturn('red');
     $webservice->getStoreViewsList()->shouldBeCalled();
     $webservice->getAttributeOptions('color')->willReturn(['red']);
     $optionNormalizer->normalize($optionRed, Argument::cetera())->willThrow('Pim\\Bundle\\MagentoConnectorBundle\\Normalizer\\Exception\\NormalizeException');
     $this->shouldThrow('Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->during('process', [[$optionRed]]);
 }
 function it_does_not_validate_attribute_with_non_string_options(AbstractAttribute $attribute, ExecutionContext $context, AttributeOption $option1, AttributeOption $option2, AttributeOption $option3, AttributeOption $option4)
 {
     $option1->getCode()->willReturn('ab');
     $option2->getCode()->willReturn(0);
     $option3->getCode()->willReturn('ef');
     $option4->getCode()->willReturn('gh');
     $attribute->getOptions()->willReturn([$option1, $option2, $option3, $option4]);
     $context->addViolation('Code must be a string. Type "integer" found.')->shouldBeCalled();
     $this->areOptionsValid($attribute, $context);
 }
 function it_normalizes_given_option(AttributeOption $option, AttributeOption $optionUS, AttributeOption $optionFR, AttributeOption $optionDE, AttributeOptionValue $optionValueUS, AttributeOptionValue $optionValueFR, AttributeOptionValue $optionValueDE, Attribute $attribute, MappingCollection $storeViewMapping)
 {
     $magentoStoreViews = [['code' => 'default', 'store_id' => 1], ['code' => 'fr_fr', 'store_id' => 2], ['code' => 'test', 'store_id' => 3]];
     $storeViewMapping->getTarget('en_US')->willReturn('en_us');
     $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr');
     $storeViewMapping->getTarget('de_DE')->willReturn('test');
     $option->getCode()->willReturn('red');
     $option->getOptionValues()->willReturn([$optionValueUS, $optionValueFR, $optionValueDE]);
     $option->getSortOrder()->willReturn(1);
     $option->setLocale('en_US')->willReturn($optionUS);
     $optionUS->getOptionValue()->willReturn($optionValueUS);
     $optionValueUS->getLocale()->willReturn('en_US');
     $optionValueUS->getLabel()->willReturn('Red');
     $option->setLocale('fr_FR')->willReturn($optionFR);
     $optionFR->getOptionValue()->willReturn($optionValueFR);
     $optionValueFR->getLocale()->willReturn('fr_FR');
     $optionValueFR->getLabel()->willReturn('Rouge');
     $option->setLocale('de_DE')->willReturn($optionDE);
     $optionDE->getOptionValue()->willReturn($optionValueDE);
     $optionValueDE->getLocale()->willReturn('de_DE');
     $optionValueDE->getLabel()->willReturn('Rot');
     $option->getAttribute()->willReturn($attribute);
     $attribute->getCode()->willReturn('color');
     $this->normalize($option, Argument::any(), ['magentoStoreViews' => $magentoStoreViews, 'storeViewMapping' => $storeViewMapping, 'channel' => 'magento', 'defaultLocale' => 'en_US', 'attributeCode' => 'attribute_code'])->shouldReturn(['attribute_code', ['label' => [['store_id' => '0', 'value' => 'red'], ['store_id' => '1', 'value' => 'Red'], ['store_id' => '2', 'value' => 'Rouge'], ['store_id' => '3', 'value' => 'Rot']], 'order' => 1]]);
 }
 /**
  * {@inheritdoc}
  */
 protected function normalizeLabel(AttributeOption $entity, $context)
 {
     $labels = array();
     foreach ($context['locales'] as $locale) {
         $labels[sprintf('label-%s', $locale)] = '';
     }
     foreach ($entity->getOptionValues() as $translation) {
         $labels[sprintf('label-%s', $translation->getLocale())] = $translation->getValue();
     }
     return $labels;
 }
 /**
  * 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_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']]]);
 }
 /**
  * Get option translation for given locale code
  * @param AttributeOption $option
  * @param string          $locale
  * @param string          $defaultLocale
  *
  * @return mixed
  */
 protected function getOptionLabel(AttributeOption $option, $locale, $defaultLocale = null)
 {
     $optionValue = $option->setLocale($locale)->getOptionValue();
     if (!$optionValue) {
         if ($defaultLocale) {
             return $this->getOptionTranslation($option, $defaultLocale);
         } else {
             return $option->getCode();
         }
     } else {
         return $optionValue->getLabel();
     }
 }
 function let(Group $group, Product $product1, Product $product2, Product $product3, Attribute $attribute1, Attribute $attribute2, AttributeOption $attributeOption11, AttributeOption $attributeOption12, AttributeOption $attributeOption21, AttributeOption $attributeOption22, ProductValue $productValueOption11, ProductValue $productValueOption12, ProductValue $productValueOption21, ProductValue $productValueOption22, ProductValue $productValuePrice1, ProductPrice $productPrice1, ProductValue $productValuePrice2, ProductPrice $productPrice2, ProductValue $productValuePrice3, ProductPrice $productPrice3, MappingCollection $attributeMapping)
 {
     $this->beConstructedWith('locale', 'currency');
     $group->getAttributes()->willReturn([$attribute1, $attribute2]);
     //get attribute options
     $attribute1->getOptions()->willReturn([$attributeOption11, $attributeOption12]);
     $attribute1->getCode()->willReturn('attribute_1');
     $attributeOption11->getAttribute()->willReturn($attribute1);
     $attributeOption11->getCode()->willReturn('attribute_1_option_1');
     $productValueOption11->getData()->willReturn($attributeOption11);
     $attributeOption12->getAttribute()->willReturn($attribute1);
     $attributeOption12->getCode()->willReturn('attribute_1_option_2');
     $productValueOption12->getData()->willReturn($attributeOption12);
     $attribute2->getOptions()->willReturn([$attributeOption21, $attributeOption22]);
     $attribute2->getCode()->willReturn('attribute_2');
     $attributeOption21->getAttribute()->willReturn($attribute2);
     $attributeOption21->getCode()->willReturn('attribute_2_option_1');
     $productValueOption21->getData()->willReturn($attributeOption21);
     $attributeOption22->getAttribute()->willReturn($attribute2);
     $attributeOption22->getCode()->willReturn('attribute_2_option_2');
     $productValueOption22->getData()->willReturn($attributeOption22);
     //Get product prices
     $product1->getValue('price', 'locale')->willReturn($productValuePrice1);
     $product1->getIdentifier()->willReturn('product_1');
     $productValuePrice1->getPrice('currency')->willReturn($productPrice1);
     $productPrice1->getData()->willReturn(5.0);
     $product2->getValue('price', 'locale')->willReturn($productValuePrice2);
     $product2->getIdentifier()->willReturn('product_2');
     $productValuePrice2->getPrice('currency')->willReturn($productPrice2);
     $productPrice2->getData()->willReturn(15.0);
     $product3->getValue('price', 'locale')->willReturn($productValuePrice3);
     $product3->getIdentifier()->willReturn('product_3');
     $productValuePrice3->getPrice('currency')->willReturn($productPrice3);
     $productPrice3->getData()->willReturn(10.0);
     $attributeMapping->getSource('attribute_1')->willReturn('attribute_1');
     $attributeMapping->getSource('attribute_2')->willReturn('attribute_2');
     $attributeMapping->getTarget('attribute_1')->willReturn('attribute_1');
     $attributeMapping->getTarget('attribute_2')->willReturn('attribute_2');
 }
 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' => '']);
 }
 /**
  * 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);
     }
 }
 /**
  * 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 getOptionValue()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getOptionValue', array());
     return parent::getOptionValue();
 }
 /**
  * Get option translation for given locale code.
  *
  * @param AttributeOption $option
  * @param string          $locale
  *
  * @return mixed
  */
 protected function getOptionLabel(AttributeOption $option, $locale)
 {
     $optionValue = $option->setLocale($locale)->getOptionValue();
     return $optionValue ? $optionValue->getLabel() : $option->getCode();
 }
 function it_normalizes_a_collection_of_option_values($value, $attribute, AttributeOption $option1, AttributeOption $option2)
 {
     $this->globalContext['magentoAttributesOptions'] = ['attribute_code' => ['option_code_1' => 'option_id_1', 'option_code_2' => 'option_id_2']];
     $attribute->isScopable()->willReturn(true);
     $attribute->isLocalizable()->willReturn(false);
     $value->getData()->willReturn([$option1, $option2]);
     $option1->getCode()->willReturn('option_code_1');
     $option2->getCode()->willReturn('option_code_2');
     $this->normalize($value, 'MagentoArray', $this->globalContext)->shouldReturn(['attribute_code' => ['option_id_1', 'option_id_2']]);
 }
 /**
  * Get all products with the given option value.
  *
  * @param ProductInterface[] $products
  * @param AttributeOption    $option
  *
  * @return array
  */
 protected function getProductsWithOption(array $products, AttributeOption $option)
 {
     $productsWithOption = [];
     $attributeCode = $option->getAttribute()->getCode();
     //PHP Warning:  max(): Array must contain at least one element in /home/akeneo_pim/pim-natalys/vendor/akeneo/prestashop-connector-bundle/Pim/Bundle/PrestashopConnectorBundle/Manager/PriceMappingManager.php on line 156
     foreach ($products as $product) {
         if ($product->getValue($attributeCode, $this->locale) !== null && $product->getValue($attributeCode, $this->locale)->getData() !== null && $product->getValue($attributeCode, $this->locale)->getData()->getCode() === $option->getCode()) {
             $productsWithOption[] = $product;
         }
     }
     return $productsWithOption;
 }
 /**
  * Create an attribute option entity
  *
  * @param string $code
  *
  * @return \Pim\Bundle\CatalogBundle\Model\AttributeOptionInterface
  */
 protected function createOption($code)
 {
     $option = new AttributeOption();
     $option->setCode($code);
     return $option;
 }
 /**
  * Add option
  *
  * @param AttributeOption $option
  *
  * @return AbstractAttribute
  */
 public function addOption(AttributeOption $option)
 {
     $this->options[] = $option;
     $option->setAttribute($this);
     return $this;
 }
 /**
  * Get all products with the given option value
  * @param array           $products
  * @param AttributeOption $option
  *
  * @return array
  */
 protected function getProductsWithOption(array $products, AttributeOption $option)
 {
     $productsWithOption = [];
     $attributeCode = $option->getAttribute()->getCode();
     foreach ($products as $product) {
         if ($product->getValue($attributeCode, $this->locale) !== null && $product->getValue($attributeCode, $this->locale)->getData()->getCode() === $option->getCode()) {
             $productsWithOption[] = $product;
         }
     }
     return $productsWithOption;
 }