/** * Export the missing properties */ protected function doExport() { $propertyGroupRepository = Shopware()->Models()->getRepository('Shopware\\Models\\Property\\Group'); /** @var Shopware\Models\Property\Group $PropertyGroup */ foreach ($propertyGroupRepository->findAll() as $PropertyGroup) { try { $groupIdAdded = PlentymarketsMappingController::getPropertyGroupByShopwareID($PropertyGroup->getId()); } catch (PlentymarketsMappingExceptionNotExistant $E) { if (array_key_exists($PropertyGroup->getName(), $this->PLENTY_groupName2ID)) { $groupIdAdded = $this->PLENTY_groupName2ID[$PropertyGroup->getName()]; } else { $Request_SetPropertyGroups = new PlentySoapRequest_SetPropertyGroups(); $Request_SetPropertyGroups->Properties = array(); $Object_SetPropertyGroup = new PlentySoapObject_SetPropertyGroup(); $Object_SetPropertyGroup->BackendName = $PropertyGroup->getName(); $Object_SetPropertyGroup->FrontendName = $PropertyGroup->getName(); $Object_SetPropertyGroup->Lang = 'de'; $Object_SetPropertyGroup->PropertyGroupID = null; $Request_SetPropertyGroups->PropertyGroups[] = $Object_SetPropertyGroup; $Response = PlentymarketsSoapClient::getInstance()->SetPropertyGroups($Request_SetPropertyGroups); if (!$Response->Success) { throw new PlentymarketsExportException('The item property group »' . $Object_SetPropertyGroup->BackendName . '« could not be exported', 2941); } $groupIdAdded = (int) $Response->ResponseMessages->item[0]->SuccessMessages->item[0]->Value; } PlentymarketsMappingController::addPropertyGroup($PropertyGroup->getId(), $groupIdAdded); // do export for property group translation $this->exportPropertyGroupTranslations($PropertyGroup->getId(), $groupIdAdded); } if (!isset($this->PLENTY_groupIDValueName2ID[$groupIdAdded])) { $this->PLENTY_groupIDValueName2ID[$groupIdAdded] = array(); } /** @var Shopware\Models\Property\Option $Property */ foreach ($PropertyGroup->getOptions() as $Property) { $Request_SetProperties = new PlentySoapRequest_SetProperties(); $Request_SetProperties->Properties = array(); $Object_SetProperty = new PlentySoapObject_SetProperty(); $Object_SetProperty->PropertyGroupID = $groupIdAdded; $Object_SetProperty->PropertyID = null; $Object_SetProperty->Lang = 'de'; $shopwareID = $PropertyGroup->getId() . ';' . $Property->getId(); try { PlentymarketsMappingController::getPropertyByShopwareID($shopwareID); } catch (PlentymarketsMappingExceptionNotExistant $E) { if (array_key_exists($Property->getName(), $this->PLENTY_groupIDValueName2ID[$groupIdAdded])) { $propertyIdAdded = $this->PLENTY_groupIDValueName2ID[$groupIdAdded][$Property->getName()]; } else { $Object_SetProperty->PropertyFrontendName = $Property->getName(); $Object_SetProperty->PropertyBackendName = $Property->getName(); $Object_SetProperty->ShowOnItemPage = 1; $Object_SetProperty->ShowInItemList = 1; $Object_SetProperty->PropertyType = 'text'; $Request_SetProperties->Properties[] = $Object_SetProperty; $Response_SetProperties = PlentymarketsSoapClient::getInstance()->SetProperties($Request_SetProperties); if (!$Response_SetProperties->Success) { throw new PlentymarketsExportException('The item property »' . $Object_SetProperty->PropertyBackendName . '« could not be created', 2942); } $propertyIdAdded = (int) $Response_SetProperties->ResponseMessages->item[0]->SuccessMessages->item[0]->Value; } PlentymarketsMappingController::addProperty($shopwareID, $propertyIdAdded); $this->exportPropertyTranslations($groupIdAdded, $Property->getId(), $propertyIdAdded); } } } }
/** * Exports the item properties */ protected function exportProperties() { $Request_SetPropertiesToItem = new PlentySoapRequest_SetPropertiesToItem(); $Request_SetPropertiesToItem->PropertyToItemList = array(); // max 50 $PropertyGroup = $this->SHOPWARE_Article->getPropertyGroup(); if (!$PropertyGroup instanceof \Shopware\Models\Property\Group) { return; } /** @var Shopware\Models\Property\Value $PropertyValue */ foreach ($this->SHOPWARE_Article->getPropertyValues() as $PropertyValue) { $PropertyOption = $PropertyValue->getOption(); try { $PLENTY_propertyID = PlentymarketsMappingController::getPropertyByShopwareID($PropertyGroup->getId() . ';' . $PropertyOption->getId()); } catch (PlentymarketsMappingExceptionNotExistant $E) { PlentymarketsLogger::getInstance()->error('Export:Initial:Item:Property', 'The property »' . $PropertyGroup->getName() . ' → ' . $PropertyOption->getName() . '« could not be added to the item with the number »' . $this->SHOPWARE_Article->getMainDetail()->getNumber() . '«', 2870); continue; } $Object_SetPropertyToItem = new PlentySoapObject_SetPropertyToItem(); $Object_SetPropertyToItem->ItemId = $this->PLENTY_itemID; // int $Object_SetPropertyToItem->Lang = 'de'; // string $Object_SetPropertyToItem->PropertyId = $PLENTY_propertyID; // int $Object_SetPropertyToItem->PropertyItemValue = $PropertyValue->getValue(); // string $Request_SetPropertiesToItem->PropertyToItemList[] = $Object_SetPropertyToItem; $this->exportPropertyValueTranslations($PropertyValue->getId(), $PLENTY_propertyID); } PlentymarketsSoapClient::getInstance()->SetPropertiesToItem($Request_SetPropertiesToItem); }