/**
  * Rolls back the item (delete all mappings and the item in plentymarkets)
  */
 protected function rollback()
 {
     // Delete the item in plentymarktes
     $Request_DeleteItems = new PlentySoapRequest_DeleteItems();
     $Request_DeleteItems->DeleteItems = array();
     $Object_DeleteItems = new PlentySoapObject_DeleteItems();
     $Object_DeleteItems->ItemID = $this->PLENTY_itemID;
     $Request_DeleteItems->DeleteItems[] = $Object_DeleteItems;
     PlentymarketsSoapClient::getInstance()->DeleteItems($Request_DeleteItems);
     PlentymarketsLogger::getInstance()->message('Export:Initial:Item', 'The item with the id »' . $this->PLENTY_itemID . '« has been deleted in plentymarkets');
     // Delete the mapping for the main item
     PlentymarketsMappingController::deleteItemByShopwareID($this->SHOPWARE_Article->getId());
     // And for the details
     foreach ($this->SHOPWARE_Article->getDetails() as $ItemVariation) {
         PlentymarketsMappingController::deleteItemVariantByShopwareID($ItemVariation->getId());
     }
 }
 /**
  * @param Article  $article
  * @param Category $category
  */
 protected function addPendingRemoveAssignment(Article $article, Category $category)
 {
     $this->pendingRemoveAssignments[$category->getId() . '_' . $article->getId()] = array('category' => $category, 'article' => $article);
 }
Example #3
0
    /**
     * @param array $data
     * @param \Shopware\Models\Article\Article $article
     * @throws \Shopware\Components\Api\Exception\CustomValidationException
     * @return array
     */
    protected function prepareVariants($data, ArticleModel $article)
    {
        unset($data['details']);

        if (!isset($data['variants'])) {
            return $data;
        }

        $variants = array();
        foreach ($data['variants'] as $variantData) {

            if (isset($variantData['id'])) {
                $variant = $this->getManager()->getRepository('Shopware\Models\Article\Detail')->findOneBy(array(
                    'id'        => $variantData['id'],
                    'articleId' => $article->getId()
                ));

                if (!$variant) {
                    throw new ApiException\CustomValidationException(sprintf("Variant by id %s not found", $variantData['id']));
                }
            } elseif (isset($variantData['number'])) {
                $variant = $this->getManager()->getRepository('Shopware\Models\Article\Detail')->findOneBy(array(
                    'number'    => $variantData['number'],
                    'articleId' => $article->getId()
                ));
            }

            if (!$variant) {
                $variant = new \Shopware\Models\Article\Detail();
                $variant->setKind(2);
            }

            $variantData = $this->prepareVariantAssociatedData($variantData);
            $variantData = $this->prepareVariantPricesAssociatedData($data, $variantData, $article, $variant);
            $variantData = $this->prepareVariantAttributeAssociatedData($variantData, $article, $variant);

            $variant->fromArray($variantData);

            if (isset($variantData['configuratorOptions']) && is_array($variantData['configuratorOptions'])) {
                $configuratorSet = $article->getConfiguratorSet();

                if (!$configuratorSet && !isset($data['configuratorSet'])) {
                    throw new ApiException\CustomValidationException('A configuratorset has to be defined');
                }

                /** @var \Shopware\Models\Article\Configurator\Set $configuratorSet */
                if ($configuratorSet) {
                    $availableGroups = $configuratorSet->getGroups();
                } else {
                    $configuratorSet = $data['configuratorSet'];
                    $availableGroups = $configuratorSet->getGroups();
                }

                $assignedOptions = new \Doctrine\Common\Collections\ArrayCollection();
                foreach ($variantData['configuratorOptions'] as $configuratorOption) {
                    $group  = $configuratorOption['group'];
                    $option = $configuratorOption['option'];

                    /** @var \Shopware\Models\Article\Configurator\Group $availableGroup */
                    foreach ($availableGroups as $availableGroup) {
                        if ($availableGroup->getName() == $group) {
                            $optionExists = false;
                            /** @var \Shopware\Models\Article\Configurator\Option $availableOption */
                            foreach ($availableGroup->getOptions() as $availableOption) {
                                if ($availableOption->getName() == $option) {
                                    $assignedOptions->add($availableOption);
                                    $optionExists = true;
                                    break;
                                }
                            }

                            if (!$optionExists) {
                                $optionModel = new \Shopware\Models\Article\Configurator\Option();
                                $optionModel->setPosition(0);
                                $optionModel->setName($option);
                                $optionModel->setGroup($availableGroup);
                                $this->getManager()->persist($optionModel);
                                $assignedOptions->add($optionModel);
                            }
                        }
                    }
                }

                $variant->setConfiguratorOptions($assignedOptions);
            }

            if (count($variant->getConfiguratorOptions()) === 0) {
                throw new \Exception('No Configurator Options assigned');
            }

            if ($variantData['isMain'] || $variantData['standard']) {
                $newMain = $variant;
                $newMain->setKind(1);

                // todo@dn Check if has configurator - delete else
                $oldMain = $data['mainDetail'];
                $oldMain['kind'] = 2;

                $data['mainDetail'] = $newMain;
//                $variant = $oldMain;
            }

            $variants[] = $variant;
        }

        $data['details'] = $variants;
        unset($data['variants']);

        return $data;
    }
Example #4
0
 /**
  * Internal helper function to remove all article variants for the deselected options.
  * @param \Shopware\Models\Article\Article $article
  * @param array                            $selectedOptions
  *
  */
 protected function deleteVariantsForAllDeactivatedOptions($article, $selectedOptions)
 {
     $configuratorSet = $article->getConfiguratorSet();
     $oldOptions = $configuratorSet->getOptions();
     $ids = array();
     /**@var $oldOption \Shopware\Models\Article\Configurator\Option*/
     foreach ($oldOptions as $oldOption) {
         if (!array_key_exists($oldOption->getId(), $selectedOptions)) {
             $details = $this->getRepository()->getArticleDetailByConfiguratorOptionIdQuery($article->getId(), $oldOption->getId())->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT)->getResult();
             if (!empty($details)) {
                 /**@var $detail \Shopware\Models\Article\Detail*/
                 foreach ($details as $detail) {
                     if ($detail->getKind() === 1) {
                         $article->setMainDetail(null);
                     }
                     $ids[] = $detail->getId();
                     Shopware()->Models()->remove($detail);
                 }
                 Shopware()->Models()->flush();
             }
         }
     }
     if (!empty($ids)) {
         $builder = Shopware()->Models()->createQueryBuilder();
         $builder->delete('Shopware\\Models\\Attribute\\Article', 'attribute')->where('attribute.articleDetailId IN (:articleDetailIds)')->setParameters(array('articleDetailIds' => $ids))->getQuery()->execute();
     }
 }
Example #5
0
 /**
  * Create the TS-Article translation
  *
  * @param ArticleModel $articleModel
  * @param bool $isUpdate
  * @throws ParameterMissingException
  */
 private function createArticleTranslation(ArticleModel $articleModel, $isUpdate = false)
 {
     /* @var Translation $translationResource */
     $translationResource = new Translation();
     $translationResource->setManager($this->em);
     if ($isUpdate) {
         $translationResource->update($articleModel->getId(), $this->getTranslationArray());
     } else {
         $translationResource->create(array_merge(array('key' => $articleModel->getId()), $this->getTranslationArray()));
     }
 }
Example #6
0
    /**
     * Internal helper function to remove all article variants for the deselected options.
     * @param \Shopware\Models\Article\Article $article
     * @param array $selectedOptions
     *
     */
    protected  function deleteVariantsForAllDeactivatedOptions($article, $selectedOptions)
    {
        $configuratorSet = $article->getConfiguratorSet();
        $oldOptions = $configuratorSet->getOptions();

        /**@var $oldOption \Shopware\Models\Article\Configurator\Option*/
        foreach($oldOptions as $oldOption) {
            if (!array_key_exists($oldOption->getId(), $selectedOptions)) {
                $details = $this->getRepository()
                                ->getArticleDetailByConfiguratorOptionIdQuery($article->getId(), $oldOption->getId())
                                ->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT)
                                ->getResult();

                foreach($details as $detail) {
                    Shopware()->Models()->remove($detail);
                }

                Shopware()->Models()->flush();
            }
        }
    }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }
Example #8
0
 /**
  * Helper function for the category assignment.
  * This function is used for the category configuration.
  * If the data key __options_categories => replace is set to true,
  * the function removes the assigned article categories from the
  * s_articles_categories and s_articles_categories_ro table.
  *
  * @param array $data
  * @param ArticleModel $article
  */
 private function resetArticleCategoryAssignment(array $data, ArticleModel $article)
 {
     if (!$article->getId()) {
         return;
     }
     $key = '__options_categories';
     //replacement deactivated?
     if (isset($data[$key]) && $data[$key]['replace'] == false) {
         return;
     }
     $this->manager->getConnection()->executeUpdate("DELETE FROM s_articles_categories WHERE articleID = :articleId", array(':articleId' => $article->getId()));
     $this->manager->getConnection()->executeUpdate("DELETE FROM s_articles_categories_ro WHERE articleID = :articleId", array(':articleId' => $article->getId()));
 }