/**
  * 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
     */
    private function prepareImageAssociatedData($data, ArticleModel $article)
    {
        if (!isset($data['images'])) {
            return $data;
        }

        $images = $article->getImages();

        $position = 1;

        foreach ($data['images'] as &$imageData) {
            if (isset($imageData['id'])) {
                $image = $this->getManager()
                        ->getRepository('Shopware\Models\Article\Image')
                        ->find($imageData['id']);

                if (!$image instanceof \Shopware\Models\Article\Image) {
                    throw new ApiException\CustomValidationException(sprintf("Image by id %s not found", $imageData['id']));
                }
            } else {
                $image = new \Shopware\Models\Article\Image();
            }

            if (isset($imageData['link'])) {
                $path = $this->load($imageData['link']);

                $file = new \Symfony\Component\HttpFoundation\File\File($path);

                $media = new \Shopware\Models\Media\Media();
                $media->setAlbumId(-1);
                $media->setAlbum($this->getManager()->find('Shopware\Models\Media\Album', -1));

                $media->setFile($file);
                $media->setDescription('');
                $media->setCreated(new \DateTime());
                $media->setUserId(0);

                try {
                    //persist the model into the model manager
                    $this->getManager()->persist($media);
                    $this->getManager()->flush();
                } catch (\Doctrine\ORM\ORMException $e) {
                    throw new ApiException\CustomValidationException(sprintf("Some error occured while loading your image"));
                }

                $image->setMain(2);
                $image->setMedia($media);
                $image->setPosition($position);
                $image->setArticle($article);
                $position++;
                $image->setPath($media->getName());
                $image->setExtension($media->getExtension());
            }

            $image->fromArray($imageData);
            $images->add($image);
        }

        unset($data['images']);

        return $data;
    }
Example #4
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 #5
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 #6
0
 /**
  * Resolves the passed configuratorOptions parameter for a single variant.
  * Each passed configurator option, has to be configured in the article configurator set.
  *
  * @param array $data
  * @param ArticleModel $article
  * @param Detail $variant
  * @return \Doctrine\Common\Collections\Collection
  * @throws \Shopware\Components\Api\Exception\CustomValidationException
  */
 protected function prepareConfigurator(array $data, ArticleModel $article, Detail $variant)
 {
     if (!$article->getConfiguratorSet()) {
         throw new ApiException\CustomValidationException('A configurator set has to be defined');
     }
     $availableGroups = $article->getConfiguratorSet()->getGroups();
     $options = new ArrayCollection();
     foreach ($data['configuratorOptions'] as $optionData) {
         $availableGroup = $this->getAvailableGroup($availableGroups, array('id' => $optionData['groupId'], 'name' => $optionData['group']));
         //group is in the article configurator set configured?
         if (!$availableGroup) {
             continue;
         }
         //check if the option is available in the configured article configurator set.
         $option = $this->getAvailableOption($availableGroup->getOptions(), array('id' => $optionData['optionId'], 'name' => $optionData['option']));
         if (!$option) {
             if (!$optionData['option']) {
                 throw new ApiException\CustomValidationException('A new configurator option requires a name');
             }
             $option = new Option();
             $option->setPosition(0);
             $option->setName($optionData['option']);
             $option->setGroup($availableGroup);
             $this->getManager()->persist($option);
         }
         $options->add($option);
     }
     $data['configuratorOptions'] = $options;
     $variant->setConfiguratorOptions($options);
     return $data;
 }
Example #7
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 setManyToOne($data, $model, $property)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setManyToOne', array($data, $model, $property));
     return parent::setManyToOne($data, $model, $property);
 }
 public function testCanUpdateOneToMany()
 {
     $article = new Article();
     $link0 = new \Shopware\Models\Article\Link();
     $link0->setName('dummy');
     $link0->setLink('lorem');
     $this->setProperty($link0, 'id', 1);
     $article->getLinks()->add($link0);
     $this->assertContains($link0, $article->getLinks());
     $data = array('links' => array(array('id' => 2, 'name' => 'batz')));
     $article->fromArray($data);
     $this->assertCount(1, $article->getLinks());
     $this->assertNotContains($link0, $article->getLinks());
     $this->assertEquals('batz', $article->getLinks()->first()->getName());
 }
Example #10
0
 /**
  * Creates the article image mappings for the passed article and image entity.
  * The mappings parameter contains a multi dimensional array with configurator options.
  * The first level of the mappings defines the OR conditions of the image mappings.
  * The second level of the mappings defines a single rule.
  * Example:
  * $mappings = array(
  *    array(
  *       array('name' => 'red')
  *       AND
  *       array('name' => 'small')
  *    )
  *    //OR
  *    array('name' => 'blue')
  * )
  *
  * @param Image $image
  * @param ArticleModel $article
  * @param array $mappings
  * @throws \Shopware\Components\Api\Exception\CustomValidationException
  */
 protected function createImageMappings(Image $image, ArticleModel $article, array $mappings)
 {
     if (!$article->getConfiguratorSet()) {
         throw new ApiException\CustomValidationException("Article is no configurator article. Image mapping can only be created on configurator articles");
     }
     $configuratorOptions = $article->getConfiguratorSet()->getOptions();
     foreach ($mappings as $mappingData) {
         $options = new ArrayCollection();
         foreach ($mappingData as $option) {
             $available = $this->getCollectionElementByProperties($configuratorOptions, ['id' => $option['id'], 'name' => $option['name']]);
             if (!$available) {
                 $property = $option['id'] ? $option['id'] : $option['name'];
                 throw new ApiException\CustomValidationException(sprintf("Passed option %s do not exist in the configurator set of the article", $property));
             }
             $options->add($available);
         }
         if (empty($options)) {
             throw new ApiException\CustomValidationException("No available option exists");
         }
         $this->getVariantResource()->createImageMappingForOptions($options, $image);
     }
 }