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 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');
 }
 /**
  * Get id from category and Magento url.
  *
  * @param CategoryInterface $category
  * @param string            $magentoUrl
  * @param MappingCollection $categoryMapping
  *
  * @return int|null
  */
 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;
     }
 }
 /**
  * Get mapping for all mappers.
  *
  * @return array
  */
 public function getMapping()
 {
     $mergedMapping = new MappingCollection();
     if ($this->hasParametersSet) {
         foreach ($this->getOrderedMappers() as $mapper) {
             $mergedMapping->merge($mapper->getMapping());
         }
     }
     return $mergedMapping;
 }
 /**
  * {@inheritdoc}
  */
 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)
 {
     $this->beConstructedWith($productValueNormalizer);
     $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;
 }
 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, ExportableLocaleFilter $localeFilter)
 {
     $this->beConstructedWith($channelManager, $mediaManager, $productValueNormalizer, $categoryMappingManager, $associationTypeManager, $localeFilter, 1, 4, 1, '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', 'urlKey' => false, 'skuFirst' => false];
     $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');
     $attributeMapping->getTarget('url_key')->willReturn('url_key');
     $attributeMapping->getSource('name')->willReturn('my-name');
     $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]));
     $product->getValue('my-name', Argument::any(), Argument::any())->willReturn('my-name');
     $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);
 }
 /**
  * {@inheritdoc}
  */
 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;
 }
 /**
  * {@inheritdoc}
  */
 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, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group, Attribute $attribute)
 {
     $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, 4);
     $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => ['attribute_code' => ['attribute_id' => 42]], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default', 'smallImageAttribute' => 'smallImageAttr', 'baseImageAttribute' => 'baseImageAttr', 'thumbnailAttribute' => 'thumbnailAttr', 'pimGrouped' => 'grouped_product_code', 'urlKey' => false, 'skuFirst' => false];
     $productNormalizer->getNormalizedImages($product, 'conf-group_code', 'smallImageAttr', 'baseImageAttr', 'thumbnailAttr')->willReturn([]);
     $productNormalizer->getValues(Argument::cetera())->willReturn([ProductNormalizer::URL_KEY => 'my-url-key']);
     $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->getId()->willReturn(44);
     $group->getCode()->willReturn('group_code');
     $product->getIdentifier()->willReturn('sku-000');
     $attribute->setCode('attribute_code');
     $group->getAttributes()->willReturn([$attribute]);
     $attribute->getCode()->willReturn('attribute_code');
     $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code');
 }
 /**
  * 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)];
 }
 /**
  * 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;
 }
 function let(ObjectManager $objectManager, EntityRepository $entityRepository, MappingCollection $mappingCollection)
 {
     $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoCategoryMapping');
     $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoCategoryMapping')->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);
 }
 /**
  * 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;
 }
 /**
  * Get normalized labels for attribute.
  *
  * @param AbstractAttribute $attribute
  * @param array             $magentoStoreViews
  * @param string            $defaultLocale
  * @param MappingCollection $storeViewMapping
  * @param MappingCollection $attributeMapping
  *
  * @return array
  */
 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);
 }
 /**
  * Generate url key from product name and identifier.
  * The identifier is included to make sure the url_key is unique, as required in Magento.
  *
  * If name is localized, the default locale is used to get the value.
  *
  * @param ProductInterface  $product
  * @param MappingCollection $attributeCodeMapping
  * @param string            $localeCode
  * @param string            $scopeCode
  * @param boolean           $skuFirst
  *
  * @return string
  */
 protected function generateUrlKey(ProductInterface $product, MappingCollection $attributeCodeMapping, $localeCode, $scopeCode, $skuFirst = false)
 {
     $identifier = $product->getIdentifier();
     $nameAttribute = $attributeCodeMapping->getSource(self::NAME);
     $name = $product->getValue($nameAttribute, $localeCode, $scopeCode);
     if (false === $skuFirst) {
         $url = Urlizer::urlize($name . '-' . $identifier);
     } else {
         $url = Urlizer::urlize($identifier . '-' . $name);
     }
     return $url;
 }