/** * {@inheritdoc} */ public function getMapping() { $simpleMappingItems = $this->simpleMappingManager->getMapping($this->getIdentifier($this->rootIdentifier)); $mapping = new MappingCollection(); foreach ($simpleMappingItems as $simpleMappingItem) { $mapping->add(array('source' => $simpleMappingItem->getSource(), 'target' => $simpleMappingItem->getTarget(), 'deletable' => true)); } return $mapping; }
/** * Get id from category and Prestashop url. * * @param CategoryInterface $category * @param string $prestashopUrl * @param MappingCollection $categoryMapping * * @return int|null */ public function getIdFromCategory(CategoryInterface $category, $prestashopUrl, MappingCollection $categoryMapping = null) { if ($categoryMapping && ($categoryId = $categoryMapping->getTarget($category->getCode())) != $category->getCode()) { return $categoryId; } else { $categoryMapping = $this->getEntityRepository()->findOneBy(['category' => $category, 'prestashopUrl' => $prestashopUrl]); return $categoryMapping ? $categoryMapping->getPrestashopCategoryId() : 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() { $prestashopAttributeMappings = $this->attributeMappingManager->getAllPrestashopAttribute($this->clientParameters->getPrestashopUrl()); $attributeCodeMapping = $this->attributeCodeMappingMerger->getMapping(); $mappingCollection = new MappingCollection(); foreach ($prestashopAttributeMappings as $prestashopAttributeMapping) { $pimAttributeCode = $prestashopAttributeMapping->getAttribute()->getCode(); $mappingCollection->add(['source' => $attributeCodeMapping->getTarget($pimAttributeCode), 'target' => $prestashopAttributeMapping->getPrestashopAttributeId(), 'deletable' => true]); } return $mappingCollection; }
/** * {@inheritdoc} */ public function getMapping() { $mapping = new MappingCollection(); if ($this->isValid()) { try { $attributes = $this->webserviceGuesser->getWebservice($this->clientParameters)->getAllAttributes(); } catch (RestCallException $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 (RestCallException $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; } }
/** * Generate url key from product name and identifier. * The identifier is included to make sure the url_key is unique, as required in Prestashop. * * 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; }
/** * 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 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 $prestashopStoreViews * @param string $defaultLocale * @param MappingCollection $storeViewMapping * @param MappingCollection $attributeMapping * * @return array */ protected function getNormalizedLabels(AbstractAttribute $attribute, array $prestashopStoreViews, $defaultLocale, MappingCollection $storeViewMapping, MappingCollection $attributeMapping) { $localizedLabels = []; foreach ($prestashopStoreViews as $prestashopStoreView) { $localeCode = $storeViewMapping->getSource($prestashopStoreView['code']); $localizedLabels[] = ['store_id' => $prestashopStoreView['store_id'], 'label' => $this->getAttributeTranslation($attribute, $localeCode, $defaultLocale)]; } return array_merge([['store_id' => 0, 'label' => strtolower($attributeMapping->getTarget($attribute->getCode()))]], $localizedLabels); }
/** * Get the corresponding storeview for a given locale. * * @param string $locale * @param array $prestashopStoreViews * @param MappingCollection $storeViewMapping * * @return string */ protected function getStoreViewForLocale($locale, $prestashopStoreViews, MappingCollection $storeViewMapping) { return $this->getStoreView($storeViewMapping->getTarget($locale), $prestashopStoreViews); }
/** * Get the corresponding storeview code for a givent locale. * * @param string $locale * @param array $prestashopStoreViews * @param MappingCollection $storeViewMapping * * @return string */ protected function getStoreViewForLocale($locale, $prestashopStoreViews, MappingCollection $storeViewMapping) { return ['code' => $storeViewMapping->getTarget($locale)]; }