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(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;
 }
 /**
  * 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;
     }
 }
 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');
 }
 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');
 }
 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);
 }
 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 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);
 }
 /**
  * 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 custom values (not provided by the PIM product).
  *
  * @param ProductInterface  $product
  * @param MappingCollection $attributeCodeMapping
  * @param array             $parameters
  *
  * @return array
  */
 protected function getCustomValue(ProductInterface $product, MappingCollection $attributeCodeMapping, array $parameters = [])
 {
     if ($this->belongsToVariant($product) && null !== $parameters['pimGrouped'] && !$this->hasGroupedProduct($product, $parameters['pimGrouped'])) {
         $visibility = $this->variantMemberVisibility;
     } else {
         $visibility = $this->visibility;
     }
     $customValue = [strtolower($attributeCodeMapping->getTarget(self::VISIBILITY)) => $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'])];
     if (false === $parameters['urlKey']) {
         $customValue[strtolower($attributeCodeMapping->getTarget(self::URL_KEY))] = $this->generateUrlKey($product, $attributeCodeMapping, $parameters['localeCode'], $parameters['scopeCode'], $parameters['skuFirst']);
     }
     return $customValue;
 }
 /**
  * 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)];
 }