/**
  * 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);
 }
Exemplo n.º 2
0
    /**
     * @param array $data
     * @param \Shopware\Models\Article\Article $article
     * @throws \Shopware\Components\Api\Exception\CustomValidationException
     * @throws \Exception
     * @return array
     */
    protected function prepareConfiguratorSet($data, ArticleModel $article)
    {
        if (!isset($data['configuratorSet'])) {
            return $data;
        }

        $configuratorSet = $article->getConfiguratorSet();
        if (!$configuratorSet) {
            $configuratorSet = new \Shopware\Models\Article\Configurator\Set();
            if (isset($data['mainDetail']['number'])) {
                $number = $data['mainDetail']['number'];
            } else {
                $number = $article->getMainDetail()->getNumber();
            }

            $configuratorSet->setName('Set-' . $number);
            $configuratorSet->setPublic(false);
        }

        if (isset($data['configuratorSet']['type'])) {
            $configuratorSet->setType($data['configuratorSet']['type']);
        }

        if (isset($data['configuratorSet']['name'])) {
            $configuratorSet->setName($data['configuratorSet']['name']);
        }

        $allOptions = array();
        $allGroups = array();

        $groupPosition = 0;

        foreach ($data['configuratorSet']['groups'] as $groupData) {
            $group = null;
            if (isset($groupData['id'])) {
                $group = $this->getManager()->getRepository('Shopware\Models\Article\Configurator\Group')->find($groupData['id']);
                if (!$group) {
                    throw new ApiException\CustomValidationException(sprintf("ConfiguratorGroup by id %s not found", $groupData['id']));
                }
            } elseif (isset($groupData['name'])) {
                $group = $this->getManager()->getRepository('Shopware\Models\Article\Configurator\Group')->findOneBy(array('name' => $groupData['name']));

                if (!$group) {
                    $group = new \Shopware\Models\Article\Configurator\Group();
                    $group->setPosition($groupPosition);
                }
            } else {
                throw new ApiException\CustomValidationException('At least the groupname is required');
            }

            $groupOptions = array();
            $optionPosition = 0;
            foreach ($groupData['options'] as $optionData) {
                $option = null;
                if ($group->getId() > 0) {
                    $option = $this->getManager()->getRepository('Shopware\Models\Article\Configurator\Option')->findOneBy(array(
                        'name'    => $optionData['name'],
                        'groupId' => $group->getId()
                    ));
                }

                if (!$option) {
                    $option = new \Shopware\Models\Article\Configurator\Option();
                }

                $option->fromArray($optionData);
                $option->setGroup($group);
                $option->setPosition($optionPosition++);
                $allOptions[]   = $option;
                $groupOptions[] = $option;
            }

            $groupData['options'] = $groupOptions;
            $group->fromArray($groupData);
            $allGroups[] = $group;
        }

        $configuratorSet->setOptions($allOptions);
        $configuratorSet->setGroups($allGroups);

        $data['configuratorSet'] = $configuratorSet;

        return $data;
    }
 /**
  * {@inheritDoc}
  */
 public function getMainDetail()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getMainDetail', array());
     return parent::getMainDetail();
 }
Exemplo n.º 4
0
 /**
  * @param array $data
  * @param \Shopware\Models\Article\Article $article
  * @throws \Shopware\Components\Api\Exception\CustomValidationException
  * @throws \Exception
  * @return array
  */
 protected function prepareConfiguratorSet($data, ArticleModel $article)
 {
     if (!isset($data['configuratorSet'])) {
         return $data;
     }
     $configuratorSet = $article->getConfiguratorSet();
     if (!$configuratorSet) {
         $configuratorSet = new Configurator\Set();
         if (isset($data['mainDetail']['number'])) {
             $number = $data['mainDetail']['number'];
         } else {
             $number = $article->getMainDetail()->getNumber();
         }
         $configuratorSet->setName('Set-' . $number);
         $configuratorSet->setPublic(false);
     }
     if (isset($data['configuratorSet']['type'])) {
         $configuratorSet->setType($data['configuratorSet']['type']);
     }
     if (isset($data['configuratorSet']['name'])) {
         $configuratorSet->setName($data['configuratorSet']['name']);
     }
     $allOptions = [];
     $allGroups = [];
     $groupPosition = 0;
     foreach ($data['configuratorSet']['groups'] as $groupData) {
         $group = null;
         if (isset($groupData['id'])) {
             $group = $this->getManager()->getRepository('Shopware\\Models\\Article\\Configurator\\Group')->find($groupData['id']);
             if (!$group) {
                 throw new ApiException\CustomValidationException(sprintf("ConfiguratorGroup by id %s not found", $groupData['id']));
             }
         } elseif (isset($groupData['name'])) {
             $group = $this->getManager()->getRepository('Shopware\\Models\\Article\\Configurator\\Group')->findOneBy(array('name' => $groupData['name']));
             if (!$group) {
                 $group = new Configurator\Group();
                 $group->setPosition($groupPosition);
             }
         } else {
             throw new ApiException\CustomValidationException('At least the groupname is required');
         }
         $groupOptions = [];
         $optionPosition = 0;
         foreach ($groupData['options'] as $optionData) {
             $option = null;
             if ($group->getId() > 0) {
                 if (isset($optionData['id'])) {
                     $option = $this->getManager()->find('Shopware\\Models\\Article\\Configurator\\Option', $optionData['id']);
                     if (!$option) {
                         throw new ApiException\CustomValidationException(sprintf("ConfiguratorOption by id %s not found", $optionData['id']));
                     }
                 } else {
                     $option = $this->getManager()->getRepository('Shopware\\Models\\Article\\Configurator\\Option')->findOneBy(['name' => $optionData['name'], 'groupId' => $group->getId()]);
                 }
             }
             if (!$option) {
                 $option = new Configurator\Option();
             }
             $option->fromArray($optionData);
             $option->setGroup($group);
             if (!isset($optionData['position'])) {
                 $option->setPosition($optionPosition++);
             }
             $allOptions[] = $option;
             $groupOptions[] = $option;
         }
         $groupData['options'] = $groupOptions;
         $group->fromArray($groupData);
         $allGroups[] = $group;
     }
     // Clear needed in order to allow updates on configuratorSet. When removed constraints in
     // s_article_configurator_set_group_relations and s_article_configurator_set_option_relations
     // might fail.
     $configuratorSet->getOptions()->clear();
     $configuratorSet->setOptions($allOptions);
     $configuratorSet->getGroups()->clear();
     $configuratorSet->setGroups($allGroups);
     $this->getManager()->persist($configuratorSet);
     $data['configuratorSet'] = $configuratorSet;
     return $data;
 }