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]]]);
 }
コード例 #2
0
 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]]);
 }
コード例 #3
0
 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]]);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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']]]);
 }
コード例 #6
0
 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' => '']);
 }
コード例 #7
0
 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');
 }
コード例 #8
0
 /**
  * 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();
 }
コード例 #9
0
 /**
  * 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;
 }
コード例 #10
0
 /**
  * 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;
 }
コード例 #11
0
 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']]);
 }
 /**
  * {@inheritDoc}
  */
 public function getCode()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', array());
     return parent::getCode();
 }