/** * Performs the actual import * * @throws PlentymarketsExportException */ public function run() { // Get the data from plentymarkets (for every mapped shop) $shopIds = Shopware()->Db()->fetchAll(' SELECT * FROM plenty_mapping_shop '); foreach ($shopIds as $shopId) { $mainShopId = PlentymarketsMappingController::getShopByPlentyID($shopId['plentyID']); $mainLang = array_values(PlentymarketsTranslation::getShopMainLanguage($mainShopId)); $Request_GetItemCategoryTree = new PlentySoapRequest_GetItemCategoryTree(); $Request_GetItemCategoryTree->Lang = PlentymarketsTranslation::getPlentyLocaleFormat($mainLang[0]['locale']); $Request_GetItemCategoryTree->GetCategoryNames = true; $Request_GetItemCategoryTree->StoreID = $shopId['plentyID']; $Request_GetItemCategoryTree->GetAktivCategories = true; /** @var PlentySoapResponse_GetItemCategoryTree $Response_GetItemCategoryTree */ $Response_GetItemCategoryTree = PlentymarketsSoapClient::getInstance()->GetItemCategoryTree($Request_GetItemCategoryTree); if (!$Response_GetItemCategoryTree->Success) { Shopware()->Db()->query('INSERT plenty_mapping_category SELECT * FROM plenty_mapping_category_old'); throw new PlentymarketsImportException('The item category tree could not be retrieved', 2920); } /** @var PlentySoapObject_ItemCategoryTreeNode $Category */ foreach ($Response_GetItemCategoryTree->MultishopTree->item[0]->CategoryTree->item as $Category) { $importEntityItemCategoryTree = new PlentymarketsImportEntityItemCategoryTree($Category, $shopId['plentyID'], $Request_GetItemCategoryTree->Lang); $importEntityItemCategoryTree->import(); } } $this->rebuild(); }
/** * Genereated the item test SOAP object * * @return PlentySoapObject_ItemTexts[] */ protected function getObjectTexts() { $requestItemTexts = array(); //in this array we save all languages that already have a translation of the article description. $languagesUsed = array(); // if the item is active for a shop => save the item descriptions into the shops languages if (!empty($this->storeIds)) { foreach ($this->storeIds as $storeId => $values) { $mainShopId = PlentymarketsMappingController::getShopByPlentyID($storeId); $shopLanguages = PlentymarketsTranslation::getShopActiveLanguages($mainShopId); foreach ($shopLanguages as $key => $language) { $lang = PlentymarketsTranslation::getPlentyLocaleFormat($language['locale']); if (in_array($lang, $languagesUsed)) { //don't save twice the translation for a language continue; } else { // add the language into the used languages list $languagesUsed[] = $lang; } $Object_ItemTexts = new PlentySoapObject_ItemTexts(); $Object_ItemTexts->Lang = $lang; // string if ($key == key(PlentymarketsTranslation::getShopMainLanguage($mainShopId))) { // set the article texts from the main shop $Object_ItemTexts->Keywords = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getKeywords()); // string $Object_ItemTexts->LongDescription = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getDescriptionLong()); // string $Object_ItemTexts->Name = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getName()); // string $Object_ItemTexts->ShortDescription = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getDescription()); // string } else { // set the article texts from the language shops $translatedText = PlentymarketsTranslation::getShopwareTranslation($mainShopId, 'article', $this->SHOPWARE_Article->getId(), $key); $Object_ItemTexts->Keywords = PlentymarketsSoapClient::removeControlChars($translatedText['txtkeywords']); $Object_ItemTexts->ShortDescription = PlentymarketsSoapClient::removeControlChars($translatedText['txtshortdescription']); $Object_ItemTexts->Name = PlentymarketsSoapClient::removeControlChars($translatedText['txtArtikel']); $Object_ItemTexts->LongDescription = PlentymarketsSoapClient::removeControlChars($translatedText['txtlangbeschreibung']); } $requestItemTexts[] = $Object_ItemTexts; } } } else { // save the item's description per default into German $Object_ItemTexts = new PlentySoapObject_ItemTexts(); $Object_ItemTexts->Lang = 'de'; // string $Object_ItemTexts->Keywords = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getKeywords()); // string $Object_ItemTexts->LongDescription = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getDescriptionLong()); // string $Object_ItemTexts->Name = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getName()); // string $Object_ItemTexts->ShortDescription = PlentymarketsSoapClient::removeControlChars($this->SHOPWARE_Article->getDescription()); // string $requestItemTexts[] = $Object_ItemTexts; } return $requestItemTexts; }
/** * I am the constructor * * @param PlentySoapObject_ItemCategoryTreeNode|PlentySoapObject_ItemCategory $categoryNode * @param integer $storeId * @throws Exception */ public function __construct($categoryNode, $storeId, $categoryNodeLang = 'de') { $category = array(); if (property_exists($categoryNode, 'ItemCategoryPath')) { $categoryPath = explode(';', $categoryNode->ItemCategoryPath); $categoryPathNames = explode(';', $categoryNode->ItemCategoryPathNames); } else { if (property_exists($categoryNode, 'CategoryPath')) { $categoryPath = explode(';', $categoryNode->CategoryPath); $categoryPathNames = explode(';', $categoryNode->CategoryPathNames); } else { throw new Exception(); } } foreach ($categoryPath as $n => $categoryId) { if ($categoryId == 0) { break; } $category[] = array('branchId' => $categoryId, 'name' => $categoryPathNames[$n]); } $this->plentyCategoryBranch = $category; $this->storeId = $storeId; $this->shopId = PlentymarketsMappingController::getShopByPlentyID($storeId); $this->categoryNodeLang = $categoryNodeLang; // get the main language of the shop set it temp $mainLang = array_values(PlentymarketsTranslation::getShopMainLanguage($this->shopId)); $this->shopLang = PlentymarketsTranslation::getPlentyLocaleFormat($mainLang[0]['locale']); if (is_null(self::$CategoryRepository)) { self::$CategoryRepository = Shopware()->Models()->getRepository('Shopware\\Models\\Category\\Category'); } if (is_null(self::$CategoryApi)) { self::$CategoryApi = Shopware\Components\Api\Manager::getResource('Category'); } }