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]]);
 }
 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]]]);
 }
 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_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' => '']);
 }
 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');
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * {@inheritDoc}
  */
 public function getAttribute()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAttribute', array());
     return parent::getAttribute();
 }