/** * Constructor method * * @param PlentySoapObject_ItemBase $ItemBase */ public function __construct($ItemBase) { $this->ItemBase = $ItemBase; foreach ($this->ItemBase->ItemAttributeMarkup->item as $ItemAttributeMarkup) { // May be percentage or flat rate surcharge $this->valueId2markup[$ItemAttributeMarkup->ValueID] = (double) $ItemAttributeMarkup->Markup; } // $Request_GetAttributeValueSets = new PlentySoapRequest_GetAttributeValueSets(); $valueIds = array(); $chunks = array_chunk($this->ItemBase->AttributeValueSets->item, 50); foreach ($chunks as $chunk) { $Request_GetAttributeValueSets->AttributeValueSets = array(); // Attribute Value Sets abfragen foreach ($chunk as $AttributeValueSet) { // $this->variants[$AttributeValueSet->AttributeValueSetID] = array(); // $RequestObject_GetAttributeValueSets = new PlentySoapRequestObject_GetAttributeValueSets(); $RequestObject_GetAttributeValueSets->AttributeValueSetID = $AttributeValueSet->AttributeValueSetID; $RequestObject_GetAttributeValueSets->Lang = 'de'; $Request_GetAttributeValueSets->AttributeValueSets[] = $RequestObject_GetAttributeValueSets; } $Response_GetAttributeValueSets = PlentymarketsSoapClient::getInstance()->GetAttributeValueSets($Request_GetAttributeValueSets); /** * @var PlentySoapObject_AttributeValueSet $AttributeValueSet * @var PlentySoapObject_Attribute $Attribute */ foreach ($Response_GetAttributeValueSets->AttributeValueSets->item as $AttributeValueSet) { $this->variant2markup[$AttributeValueSet->AttributeValueSetID] = 0; foreach ($AttributeValueSet->Attribute->item as $Attribute) { // if (!array_key_exists($Attribute->AttributeFrontendName, $this->groups)) { try { $attributeId = PlentymarketsMappingController::getAttributeGroupByPlentyID($Attribute->AttributeID); $group = array('id' => $attributeId, 'options' => array()); } catch (Exception $e) { $group = array('name' => $Attribute->AttributeFrontendName, 'options' => array()); } $this->groups[$Attribute->AttributeFrontendName] = $group; $this->groupId2optionName2plentyId[$Attribute->AttributeID] = array(); $this->groupName2plentyId[$Attribute->AttributeFrontendName] = $Attribute->AttributeID; } // $this->configuratorOptions[$AttributeValueSet->AttributeValueSetID][] = array('group' => $Attribute->AttributeFrontendName, 'option' => $Attribute->AttributeValue->ValueFrontendName); // if (!in_array($Attribute->AttributeValue->ValueID, $valueIds)) { try { $valueId = PlentymarketsMappingController::getAttributeOptionByPlentyID($Attribute->AttributeValue->ValueID); $option = array('id' => $valueId); } catch (Exception $e) { $option = array('name' => $Attribute->AttributeValue->ValueFrontendName); } $this->groups[$Attribute->AttributeFrontendName]['options'][] = $option; $this->groupId2optionName2plentyId[$Attribute->AttributeID][$Attribute->AttributeValue->ValueFrontendName] = $Attribute->AttributeValue->ValueID; $valueIds[] = $Attribute->AttributeValue->ValueID; } if ($this->valueId2markup[$Attribute->AttributeValue->ValueID]) { $markup = $this->valueId2markup[$Attribute->AttributeValue->ValueID]; } else { $markup = (double) $Attribute->AttributeValue->Markup; } if ($markup) { if ($Attribute->MarkupPercental == 1) { $markup = $this->ItemBase->PriceSet->Price / 100 * $markup; } $this->variant2markup[$AttributeValueSet->AttributeValueSetID] += $markup; } } } } }
/** * Imports the attribtue */ protected function importAttribute() { try { $SHOPWARE_attributeId = PlentymarketsMappingController::getAttributeGroupByPlentyID($this->Attribute->Id); PyLog()->message('Sync:Item:Attribute', 'Updating the attribute »' . $this->Attribute->FrontendName . '«'); } catch (PlentymarketsMappingExceptionNotExistant $E) { PyLog()->message('Sync:Item:Attribute', 'Skipping the attribute »' . $this->Attribute->FrontendName . '«'); return; } /** @var Shopware\Models\Article\Configurator\Group $Group */ $Group = Shopware()->Models()->find('Shopware\\Models\\Article\\Configurator\\Group', $SHOPWARE_attributeId); // Set the new data if (!is_null($this->Attribute->FrontendName)) { $Group->setName($this->Attribute->FrontendName); } elseif (!is_null($this->Attribute->BackendName)) { // use backend-name if frontend-name doesn't exists $Group->setName($this->Attribute->BackendName); } else { PyLog()->message('Sync:Item:Attribute', 'No valid name for the attribute with id »' . $this->Attribute->Id . '«'); return; } $Group->setPosition($this->Attribute->Position); $this->Group = $Group; }