/**
  * {@inheritDoc}
  */
 public function getRelated()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getRelated', array());
     return parent::getRelated();
 }
Exemple #2
0
 /**
  * @param array $data
  * @param \Shopware\Models\Article\Article $article
  * @throws \Shopware\Components\Api\Exception\CustomValidationException
  * @return array
  */
 protected function prepareRelatedAssociatedData($data, ArticleModel $article)
 {
     if (!isset($data['related'])) {
         return $data;
     }
     $related = $this->checkDataReplacement($article->getRelated(), $data, 'related', true);
     foreach ($data['related'] as $relatedData) {
         if (empty($relatedData['number']) && empty($relatedData['id'])) {
             continue;
         }
         $relatedArticle = null;
         if ($relatedData['number']) {
             $articleId = $this->getManager()->getConnection()->fetchColumn("SELECT articleID FROM s_articles_details WHERE ordernumber = :number", array(':number' => $relatedData['number']));
             if ($articleId) {
                 $relatedArticle = $this->getManyToManySubElement($related, array('id' => $articleId), '\\Shopware\\Models\\Article\\Article');
             }
         }
         if (!$relatedArticle) {
             $relatedArticle = $this->getManyToManySubElement($related, $relatedData, '\\Shopware\\Models\\Article\\Article');
         }
         //no valid entity found, throw exception!
         if (!$relatedArticle) {
             $property = $relatedData['number'] ? $relatedData['number'] : $relatedData['id'];
             throw new ApiException\CustomValidationException(sprintf("Related Article by number/id %s not found", $property));
         }
         /**@var $relatedArticle ArticleModel */
         if ($relatedData['cross']) {
             $relatedArticle->getRelated()->add($article);
         }
     }
     $data['related'] = $related;
     return $data;
 }