/** * {@inheritDoc} */ public function getSeoCategories() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSeoCategories', array()); return parent::getSeoCategories(); }
/** * @param array $data * @param \Shopware\Models\Article\Article $article * @throws \Shopware\Components\Api\Exception\CustomValidationException * @return array */ protected function prepareSeoCategoryAssociatedData($data, ArticleModel $article) { if (!isset($data['seoCategories'])) { return $data; } $categories = $this->checkDataReplacement($article->getSeoCategories(), $data, 'seoCategories', true); foreach ($data['seoCategories'] as $categoryData) { /**@var $seoCategory \Shopware\Models\Article\SeoCategory */ $seoCategory = $this->getOneToManySubElement($categories, $categoryData, '\\Shopware\\Models\\Article\\SeoCategory'); if (isset($categoryData['shopId'])) { /** @var $shop \Shopware\Models\Shop\Shop */ $shop = $this->manager->find('Shopware\\Models\\Shop\\Shop', $categoryData['shopId']); if (!$shop) { throw new ApiException\CustomValidationException(sprintf("Could not find shop by id: %s.", $categoryData['shopId'])); } $seoCategory->setShop($shop); } if (!$seoCategory->getShop()) { throw new ApiException\CustomValidationException(sprintf("An article seo category requires a configured shop")); } if (isset($categoryData['categoryId'])) { /** @var $category \Shopware\Models\Category\Category */ $category = $this->manager->find('Shopware\\Models\\Category\\Category', $categoryData['categoryId']); if (!$category) { throw new ApiException\CustomValidationException(sprintf("Could not find category by id: %s.", $categoryData['categoryId'])); } $seoCategory->setCategory($category); } elseif (isset($categoryData['categoryPath'])) { $category = $this->getResource('Category')->findCategoryByPath($categoryData['categoryPath'], true); if (!$category) { throw new ApiException\CustomValidationException(sprintf("Could not find category by path: %s.", $categoryData['categoryPath'])); } $seoCategory->setCategory($category); } $existing = $this->getCollectionElementByProperty($data['categories'], 'id', $seoCategory->getCategory()->getId()); if (!$existing) { throw new ApiException\CustomValidationException(sprintf("Seo category isn't assigned as normal article category. Only assigned categories can be used as seo category")); } $seoCategory->setArticle($article); } $data['seoCategories'] = $categories; return $data; }