/** * Exports the base item * * @throws PlentymarketsExportException * @return boolean */ protected function exportItemBase() { $Item = $this->SHOPWARE_Article; $Request_SetItemsBase = new PlentySoapRequest_SetItemsBase(); $Request_SetItemsBase->BaseItems = array(); $Object_SetItemsBaseItemBase = new PlentySoapObject_SetItemsBaseItemBase(); $ItemDetails = $Item->getMainDetail(); if (!$ItemDetails instanceof \Shopware\Models\Article\Detail) { throw new PlentymarketsExportException('The item »' . $this->SHOPWARE_Article->getName() . '« with the id »' . $this->SHOPWARE_Article->getId() . '« could not be exported (no main detail)', 2810); } try { // Release date $ReleaseDate = $ItemDetails->getReleaseDate(); } catch (Doctrine\ORM\EntityNotFoundException $E) { throw new PlentymarketsExportException('The item »' . $this->SHOPWARE_Article->getName() . '« with the id »' . $this->SHOPWARE_Article->getId() . '« could not be exported (missing main detail)', 2811); } // Set the release date if ($ReleaseDate instanceof \DateTime) { $Object_SetItemsBaseItemBase->Published = $ReleaseDate->getTimestamp(); } $Object_SetItemsBaseItemBase->ExternalItemID = PlentymarketsUtils::getExternalItemID($Item->getId()); if ($Item->getSupplier() instanceof Shopware\Models\Article\Supplier) { $Object_SetItemsBaseItemBase->ProducerID = PlentymarketsMappingController::getProducerByShopwareID($Item->getSupplier()->getId()); } $Object_SetItemsBaseItemBase->EAN1 = $ItemDetails->getEan(); $Object_SetItemsBaseItemBase->VATInternalID = PlentymarketsMappingController::getVatByShopwareID($Item->getTax()->getId()); $Object_SetItemsBaseItemBase->ItemNo = $ItemDetails->getNumber(); // $Object_SetItemsBaseItemBase->Availability = $this->getObjectAvailabiliy(); $Object_SetItemsBaseItemBase->PriceSet = $this->getObjectPriceSet(); // $Object_SetItemsBaseItemBase->Categories = array(); $Object_SetItemsBaseItemBase->StoreIDs = array(); /** @var Shopware\Models\Category\Category $Category */ foreach ($Item->getCategories() as $Category) { // Get the store for this category $rootId = PlentymarketsUtils::getRootIdByCategory($Category); $shops = PlentymarketsUtils::getShopIdByCategoryRootId($rootId); $plentyCategoryBranchId = null; foreach ($shops as $shopId) { try { $plentyCategoryBranchId = PlentymarketsMappingEntityCategory::getCategoryByShopwareID($Category->getId(), $shopId); } catch (PlentymarketsMappingExceptionNotExistant $E) { PlentymarketsLogger::getInstance()->error('Export:Initial:Item', 'The category »' . $Category->getName() . '« with the id »' . $Category->getId() . '« will not be assigned to the item with the number »' . $ItemDetails->getNumber() . '«', 2820); continue; } try { $storeId = PlentymarketsMappingController::getShopByShopwareID($shopId); } catch (PlentymarketsMappingExceptionNotExistant $E) { continue; } if (!isset($this->storeIds[$storeId])) { // Activate the item for this store $Object_Integer = new PlentySoapObject_Integer(); $Object_Integer->intValue = $storeId; $Object_SetItemsBaseItemBase->StoreIDs[] = $Object_Integer; // Cache $this->storeIds[$storeId] = true; } } if (!$plentyCategoryBranchId) { continue; } // Activate the category $Object_ItemCategory = new PlentySoapObject_ItemCategory(); $Object_ItemCategory->ItemCategoryID = $plentyCategoryBranchId; // string $Object_SetItemsBaseItemBase->Categories[] = $Object_ItemCategory; } $Object_SetItemsBaseItemBase->Texts = $this->getObjectTexts(); $Object_SetItemsBaseItemBase->FreeTextFields = $this->getObjectFreeTextFields(); $Request_SetItemsBase->BaseItems[] = $Object_SetItemsBaseItemBase; $Response_SetItemsBase = PlentymarketsSoapClient::getInstance()->SetItemsBase($Request_SetItemsBase); $ResponseMessage = $Response_SetItemsBase->ResponseMessages->item[0]; if (!$Response_SetItemsBase->Success || $ResponseMessage->Code != 100) { throw new PlentymarketsExportException('The item with the number »' . $ItemDetails->getNumber() . '« could not be exported', 2800); } foreach ($ResponseMessage->SuccessMessages->item as $SubMessage) { if ($SubMessage->Key == 'ItemID') { $this->PLENTY_itemID = (int) $SubMessage->Value; } else { if ($SubMessage->Key == 'PriceID') { $this->PLENTY_priceID = (int) $SubMessage->Value; } } } if ($this->PLENTY_itemID && $this->PLENTY_priceID) { PlentymarketsLogger::getInstance()->message('Export:Initial:Item', 'The item with the number »' . $ItemDetails->getNumber() . '« has been created (ItemId: ' . $this->PLENTY_itemID . ', PriceId: ' . $this->PLENTY_priceID . ')'); PlentymarketsMappingController::addItem($Item->getId(), $this->PLENTY_itemID); } else { throw new PlentymarketsExportException('The item with the number »' . $ItemDetails->getNumber() . '« could not be exported (no item ID and price ID respectively)', 2830); } }
/** * Exports the categories * * @param $shopwareCategories * @param $plentyTree * @param $storeId */ private function export($shopwareCategories, $plentyTree, $storeId) { try { $shopId = PlentymarketsMappingController::getShopByPlentyID($storeId); } catch (PlentymarketsMappingExceptionNotExistant $e) { return; } /** @var Shopware\Models\Category\Category $shopwareCategory */ foreach ($shopwareCategories as $shopwareCategory) { if ($shopwareCategory->getBlog()) { continue; } try { PlentymarketsMappingEntityCategory::getCategoryByShopwareID($shopwareCategory->getId(), $shopId); continue; } catch (PlentymarketsMappingExceptionNotExistant $e) { } $branchId = null; if (!isset($plentyTree['children'])) { $plentyTree['children'] = array(); } $shopwareName = trim($shopwareCategory->getName()); /** @var array $plentyChild1 */ foreach ($plentyTree['children'] as $name => $plentyChild1) { if ($name == $shopwareName) { $branchId = $plentyChild1['id']; PlentymarketsMappingEntityCategory::addCategory($shopwareCategory->getId(), $shopId, $branchId, $storeId); break; } } $branchId = $this->exportCategory($shopwareCategory, $storeId, $shopId, $branchId); // Active the category if ($storeId > 0 && $shopwareCategory->getActive()) { $Request_SetStoreCategories = new PlentySoapRequest_SetStoreCategories(); $Request_SetStoreCategories->StoreCategories = array(); $Object_SetStoreCategory = new PlentySoapObject_SetStoreCategory(); $Object_SetStoreCategory->BranchID = $branchId; $Object_SetStoreCategory->StoreID = $storeId; $Request_SetStoreCategories->StoreCategories[] = $Object_SetStoreCategory; PlentymarketsSoapClient::getInstance()->SetStoreCategories($Request_SetStoreCategories); } $shopwareChildren1 = $shopwareCategory->getChildren(); // search for the next categories of shopware in plentymarkets $this->export($shopwareChildren1, $plentyChild1, $storeId); } }