/** * Does the actual import */ public function import() { try { $SHOPWARE_id = PlentymarketsMappingController::getPropertyGroupByPlentyID($this->Group->PropertyGroupID); PyLog()->message('Sync:Item:Producer', 'Updating the property group »' . $this->Group->FrontendName . '«'); } catch (PlentymarketsMappingExceptionNotExistant $E) { PyLog()->message('Sync:Item:Producer', 'Skipping the property group »' . $this->Group->FrontendName . '«'); return; } /** @var Shopware\Models\Property\Group $Group */ $Group = Shopware()->Models()->find('Shopware\\Models\\Property\\Group', $SHOPWARE_id); // Set the new data $Group->setName($this->Group->FrontendName); Shopware()->Models()->persist($Group); Shopware()->Models()->flush(); }
/** * Set the item's properties */ protected function setProperties() { // No properties if (is_null($this->ItemBase->ItemProperties)) { return; } $groups = array(); /** @var PlentySoapObject_ItemProperty $ItemProperty */ foreach ($this->ItemBase->ItemProperties->item as $ItemProperty) { if (is_null($ItemProperty->PropertyGroupID)) { PlentymarketsLogger::getInstance()->error('Sync:Item', 'The property »' . $ItemProperty->PropertyName . '« will not be assigned to the item »' . $this->data['name'] . '« with the id »' . $this->ItemBase->ItemID . '« (not assigned to any group)', 3410); } else { if (!$ItemProperty->ShowOnItemPageInWebshop) { PlentymarketsLogger::getInstance()->error('Sync:Item', 'The property »' . $ItemProperty->PropertyName . '« will not be assigned to the item »' . $this->data['name'] . '« with the id »' . $this->ItemBase->ItemID . '« (may not be shown on item page)', 3420); } else { $groups[$ItemProperty->PropertyGroupID][] = $ItemProperty; } } } if (empty($groups)) { PlentymarketsLogger::getInstance()->error('Sync:Item', 'No property group will be assigned to the item »' . $this->data['name'] . '« with the id »' . $this->ItemBase->ItemID . '«', 3430); return; } $groupId = -1; $numberOfValuesMax = 0; foreach ($groups as $groupIdx => $values) { if (count($values) > $numberOfValuesMax) { $groupId = $groupIdx; $numberOfValuesMax = count($values); } } // Check for filterId try { $filterGroupId = PlentymarketsMappingController::getPropertyGroupByPlentyID($groupId); } catch (PlentymarketsMappingExceptionNotExistant $E) { // Create the group $GroupAdded = Shopware\Components\Api\Manager::getResource('PropertyGroup')->create(array('name' => $ItemProperty->PropertyGroupFrontendName)); // Get the new id $filterGroupId = $GroupAdded->getId(); // Write the mapping and the log PlentymarketsMappingController::addPropertyGroup($filterGroupId, $groupId); PlentymarketsLogger::getInstance()->message('Sync:Item', 'The property group »' . $ItemProperty->PropertyGroupFrontendName . '« has been created'); } // Load the group consistently /** @var Shopware\Models\Property\Group $Group */ $Group = Shopware()->Models()->find('Shopware\\Models\\Property\\Group', $filterGroupId); if (!$Group) { throw new PlentymarketsImportItemException('The property group with the id »' . $filterGroupId . '« could not be loaded', 3441); } // Update the data of this item $this->data['filterGroupId'] = $filterGroupId; $this->data['propertyValues'] = array(); // Properties /** @var PlentySoapObject_ItemProperty $ItemProperty */ foreach ($groups[$groupId] as $ItemProperty) { // import only property values in German language if ($ItemProperty->PropertyValueLang != 'de') { continue; } // Mapping GroupId;ValueId -> ValueId try { $property = PlentymarketsMappingController::getPropertyByPlentyID($ItemProperty->PropertyID); $propertyParts = explode(';', $property); $optionId = $propertyParts[1]; } catch (PlentymarketsMappingExceptionNotExistant $E) { // import the property $Option = new Shopware\Models\Property\Option(); $Option->fromArray(array('name' => $ItemProperty->PropertyName, 'filterable' => 1)); // Persist the objects Shopware()->Models()->persist($Group); Shopware()->Models()->persist($Option); // Add the option to the group $Group->addOption($Option); try { // And flush everything Shopware()->Models()->flush(); PlentymarketsLogger::getInstance()->message('Sync:Item', 'The property »' . $ItemProperty->PropertyName . '« has been created and added to the group »' . $Group->getName() . '«'); } catch (Exception $E) { throw new PlentymarketsImportItemException('The property »' . $ItemProperty->PropertyName . '« could not be created (' . $E->getMessage() . ')', 3440); } // $optionId = $Option->getId(); // Save the mapping PlentymarketsMappingController::addProperty($filterGroupId . ';' . $optionId, $ItemProperty->PropertyID); } // Use SelectionName as PropertyValue for Merkmale-Typ "Auswahl" if (empty($ItemProperty->PropertyValue) && !empty($ItemProperty->PropertySelectionName)) { $ItemProperty->PropertyValue = $ItemProperty->PropertySelectionName; } // Shopware cannot handle empty values if (!empty($ItemProperty->PropertyValue)) { $this->data['propertyValues'][] = array('option' => array('id' => $optionId), 'value' => $ItemProperty->PropertyValue); } } }