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]]);
 }
 /**
  * Get id from category and Magento url
  * @param CategoryInterface $category
  * @param string            $magentoUrl
  * @param MappingCollection $categoryMapping
  *
  * @return int
  */
 public function getIdFromCategory(CategoryInterface $category, $magentoUrl, MappingCollection $categoryMapping = null)
 {
     if ($categoryMapping && ($categoryId = $categoryMapping->getTarget($category->getCode())) != $category->getCode()) {
         return $categoryId;
     } else {
         $categoryMapping = $this->getEntityRepository()->findOneBy(['category' => $category, 'magentoUrl' => $magentoUrl]);
         return $categoryMapping ? $categoryMapping->getMagentoCategoryId() : null;
     }
 }
 function let(ProductValue $value, MappingCollection $attributeMapping, AbstractAttribute $attribute)
 {
     $this->globalContext = ['identifier' => 'identifier', 'scopeCode' => 'scope_code', 'localeCode' => 'locale_code', 'onlyLocalized' => false, 'magentoAttributes' => ['attribute_code' => ['code' => 'attribute_ode', 'scope' => 'global']], 'magentoAttributesOptions' => [], 'currencyCode' => 'currency_code', 'attributeCodeMapping' => $attributeMapping];
     $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code');
     $value->getData()->willReturn('hello');
     $value->getAttribute()->willReturn($attribute);
     $value->getScope()->willReturn('scope_code');
     $attribute->getCode()->willReturn('attribute_code');
 }
 /**
  * Return magento akeneo mapping
  *
  * @return array|MappingCollection
  */
 public function getMapping()
 {
     $magentoAttributeMappings = $this->attributeMappingManager->getAllMagentoAttribute($this->clientParameters->getSoapUrl());
     $attributeCodeMapping = $this->attributeCodeMappingMerger->getMapping();
     $mappingCollection = new MappingCollection();
     foreach ($magentoAttributeMappings as $magentoAttributeMapping) {
         $pimAttributeCode = $magentoAttributeMapping->getAttribute()->getCode();
         $mappingCollection->add(['source' => $attributeCodeMapping->getTarget($pimAttributeCode), 'target' => $magentoAttributeMapping->getMagentoAttributeId(), 'deletable' => true]);
     }
     return $mappingCollection;
 }
 function let(ProductValueNormalizer $productValueNormalizer, Attribute $attribute, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductValueManager $productValueManager)
 {
     $this->beConstructedWith($productValueNormalizer, $productValueManager);
     $attribute->isUnique()->willReturn(true);
     $attribute->isRequired()->willReturn(false);
     $attribute->isLocalizable()->willReturn(true);
     $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code_mapped');
     $attributeMapping->getTarget('Attribute_code')->willReturn('Attribute_code_mapped');
     $attributeMapping->getTarget('2ttribute_code')->willReturn('2ttribute_code');
     $attributeMapping->getTarget('attributeCode')->willReturn('attributeCode');
     $this->baseContext['attributeCodeMapping'] = $attributeMapping;
     $this->baseContext['storeViewMapping'] = $storeViewMapping;
 }
 /**
  * Get mapping
  *
  * @return array
  */
 public function getMapping()
 {
     $mapping = new MappingCollection();
     if ($this->isValid()) {
         try {
             $attributes = $this->webserviceGuesser->getWebservice($this->clientParameters)->getAllAttributes();
         } catch (SoapCallException $e) {
             return $mapping;
         }
         foreach ($attributes as $attribute) {
             $mapping->add(['source' => $attribute['code'], 'target' => $attribute['attribute_id'], 'deletable' => true]);
         }
     }
     return $mapping;
 }
 function let(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group)
 {
     $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, $attributeMapping);
     $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default'];
     $productNormalizer->getNormalizedImages($product, 'conf-group_code')->willReturn([]);
     $productNormalizer->getValues(Argument::cetera())->willReturn([]);
     $channelManager->getChannelByCode('channel')->willReturn($channel);
     $channel->getLocales()->willReturn([$localeEN, $localeFR]);
     $localeEN->getCode()->willReturn('default_locale');
     $localeFR->getCode()->willReturn('fr_FR');
     $channel->getCode()->willReturn('channel_code');
     $storeViewMapping->getTarget('default_locale')->willReturn('default_locale');
     $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr');
     $group->getCode()->willReturn('group_code');
     $product->getIdentifier()->willReturn('sku-000');
 }
 /**
  * Get mapping
  *
  * @return array
  */
 public function getMapping()
 {
     if (!$this->isValid()) {
         return new MappingCollection();
     } else {
         try {
             $attributes = $this->webserviceGuesser->getWebservice($this->clientParameters)->getAllAttributes();
         } catch (SoapCallException $e) {
             return new MappingCollection();
         }
         $mapping = new MappingCollection();
         foreach (array_keys($attributes) as $attributeCode) {
             if (in_array($attributeCode, $this->mandatoryAttributes())) {
                 $mapping->add(['source' => $attributeCode, 'target' => $attributeCode, 'deletable' => false]);
             }
         }
         return $mapping;
     }
 }
 function let(ChannelManager $channelManager, MediaManager $mediaManager, ProductValueNormalizer $productValueNormalizer, CategoryMappingManager $categoryMappingManager, AssociationTypeManager $associationTypeManager, MappingCollection $storeViewMapping, MappingCollection $categoryMapping, MappingCollection $attributeMapping, Product $product, ProductValue $productValue, ProductValue $imageValue, Channel $channel, Locale $localeFR, Locale $localeEN, Category $category)
 {
     $this->beConstructedWith($channelManager, $mediaManager, $productValueNormalizer, $categoryMappingManager, $associationTypeManager, 1, 4, 'currency', 'magento_url');
     $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'pimGrouped' => 'pim_grouped', 'created_date' => new \DateTime(), 'updated_date' => new \DateTime(), 'defaultStoreView' => 'default', 'smallImageAttribute' => 'small_image_attribute', 'baseImageAttribute' => 'image_attribute', 'thumbnailAttribute' => 'image_attribute'];
     $attributeMapping->getTarget('visibility')->willReturn('visibility');
     $attributeMapping->getTarget('created_at')->willReturn('created_at');
     $attributeMapping->getTarget('updated_at')->willReturn('updated_at');
     $attributeMapping->getTarget('status')->willReturn('status');
     $attributeMapping->getTarget('categories')->willReturn('categories');
     $channelManager->getChannelByCode('channel')->willReturn($channel);
     $channel->getLocales()->willReturn([$localeEN, $localeFR]);
     $localeEN->getCode()->willReturn('default_locale');
     $localeFR->getCode()->willReturn('fr_FR');
     $channel->getCode()->willReturn('channel_code');
     $channel->getCategory()->willReturn($category);
     $product->getCategories()->willReturn([$category]);
     $product->getIdentifier()->willReturn('sku-000');
     $product->getCreated()->willReturn($this->globalContext['created_date']);
     $product->getUpdated()->willReturn($this->globalContext['updated_date']);
     $product->getValues()->willReturn(new ArrayCollection([$productValue, $imageValue]));
     $storeViewMapping->getTarget('default_locale')->willReturn('default_locale');
     $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr');
     $categoryMappingManager->getIdFromCategory($category, 'magento_url', $categoryMapping)->willReturn(2);
     $productValueNormalizer->normalize($productValue, Argument::cetera())->willReturn(['value' => 'productValueNormalized']);
     $productValueNormalizer->normalize($imageValue, Argument::cetera())->willReturn(null);
 }
 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 normalized labels for attribute
  * @param AbstractAttribute $attribute
  * @param array             $magentoStoreViews
  * @param string            $defaultLocale
  * @param MappingCollection $storeViewMapping
  * @param MappingCollection $attributeMapping
  *
  * @return string
  */
 protected function getNormalizedLabels(AbstractAttribute $attribute, array $magentoStoreViews, $defaultLocale, MappingCollection $storeViewMapping, MappingCollection $attributeMapping)
 {
     $localizedLabels = [];
     foreach ($magentoStoreViews as $magentoStoreView) {
         $localeCode = $storeViewMapping->getSource($magentoStoreView['code']);
         $localizedLabels[] = ['store_id' => $magentoStoreView['store_id'], 'label' => $this->getAttributeTranslation($attribute, $localeCode, $defaultLocale)];
     }
     return array_merge([['store_id' => 0, 'label' => strtolower($attributeMapping->getTarget($attribute->getCode()))]], $localizedLabels);
 }
 /**
  * Get custom values (not provided by the PIM product)
  * @param ProductInterface  $product
  * @param MappingCollection $attributeCodeMapping
  * @param array             $parameters
  *
  * @return mixed
  */
 protected function getCustomValue(ProductInterface $product, MappingCollection $attributeCodeMapping, array $parameters = [])
 {
     return [strtolower($attributeCodeMapping->getTarget(self::VISIBILITY)) => $this->visibility, strtolower($attributeCodeMapping->getTarget(self::ENABLED)) => (string) $this->enabled ? 1 : 2, strtolower($attributeCodeMapping->getTarget('created_at')) => $product->getCreated()->format(AbstractNormalizer::DATE_FORMAT), strtolower($attributeCodeMapping->getTarget('updated_at')) => $product->getUpdated()->format(AbstractNormalizer::DATE_FORMAT), strtolower($attributeCodeMapping->getTarget('categories')) => $this->getProductCategories($product, $parameters['categoryMapping'], $parameters['scopeCode'])];
 }
 /**
  * Get product price from generated mapping
  * @param ProductInterface  $product
  * @param array             $priceChanges
  * @param float             $basePrice
  * @param MappingCollection $attributeMapping
  *
  * @return float
  */
 protected function getProductPriceFromMapping(ProductInterface $product, array $priceChanges, $basePrice, MappingCollection $attributeMapping)
 {
     $priceFromMapping = $basePrice;
     foreach ($priceChanges as $attributeCode => $attributePriceMapping) {
         $priceFromMapping += $this->getAttributePriceFromMapping($product, $attributeMapping->getSource($attributeCode), $attributePriceMapping);
     }
     return $priceFromMapping;
 }
 /**
  * Is the given attribute ignored ?
  *
  * @param AbstractAttribute $attribute
  * @param MappingCollection $attributeMapping
  *
  * @return boolean
  */
 protected function isAttributeIgnored(AbstractAttribute $attribute, MappingCollection $attributeMapping)
 {
     return in_array(strtolower($attributeMapping->getTarget($attribute->getCode())), $this->getIgnoredAttributes()) || $attribute->getAttributeType() === self::IMAGE_ATTRIBUTE_TYPE;
 }
 /**
  * Get the corresponding storeview code for a givent locale
  * @param string            $locale
  * @param array             $magentoStoreViews
  * @param MappingCollection $storeViewMapping
  *
  * @return string
  */
 protected function getStoreViewForLocale($locale, $magentoStoreViews, MappingCollection $storeViewMapping)
 {
     return ['code' => $storeViewMapping->getTarget($locale)];
 }
 function let(ObjectManager $objectManager, EntityRepository $entityRepository, MappingCollection $mappingCollection)
 {
     $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoFamilyMapping');
     $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoFamilyMapping')->willReturn($entityRepository);
     $mappingCollection->getTarget('default')->willReturn(12);
 }
 /**
  * Get the corresponding storeview for a given locale
  * @param string            $locale
  * @param array             $magentoStoreViews
  * @param MappingCollection $storeViewMapping
  *
  * @return string
  */
 protected function getStoreViewForLocale($locale, $magentoStoreViews, MappingCollection $storeViewMapping)
 {
     return $this->getStoreView($storeViewMapping->getTarget($locale), $magentoStoreViews);
 }