/**
  * {@inheritDoc}
  */
 public function getArticle()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getArticle', array());
     return parent::getArticle();
 }
示例#2
0
 /**
  * Checks if the article realy exists
  *
  * @param Detail $articleDetailModel
  * @return bool
  */
 private function checkIfArticleExists(Detail $articleDetailModel)
 {
     $articleId = $articleDetailModel->getArticle()->getId();
     $sql = "SELECT id FROM s_articles WHERE id = :articleId";
     $result = $this->db->fetchOne($sql, array('articleId' => $articleId));
     if (!empty($result)) {
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Helper method which swaps the translations of the newMainDetail and the oldMainDetail
  * Needed because mainDetails' translations are stored for the article, not for the variant itself
  * @param \Shopware\Models\Article\Detail $newMainDetail
  * @param \Shopware\Models\Article\Detail $oldMainDetail
  */
 private function swapDetailTranslations($newMainDetail, $oldMainDetail)
 {
     $articleId = $oldMainDetail->getArticle()->getId();
     // Get available translations for the old mainDetail (stored on the article)
     $sql = "\n            SELECT objectlanguage, objectdata\n            FROM s_core_translations\n            WHERE objecttype = 'article' AND objectkey = ?\n        ";
     $oldTranslations = Shopware()->Db()->fetchAssoc($sql, array($articleId));
     // Get available translations for the new mainDetail (stored for the detail)
     $sql = "\n            SELECT objectlanguage, objectdata\n            FROM s_core_translations\n            WHERE objecttype='variant' AND objectkey = ?\n        ";
     $newTranslations = Shopware()->Db()->fetchAssoc($sql, array($newMainDetail->getId()));
     // We need to determine which of the old article translations can be used for the translation of the
     // variant which was the mainDetail before.
     // We'll get a list of translatable variant fields from the variant which is going to become the new mainDetail
     $translatedFields = array();
     foreach ($newTranslations as $values) {
         $data = $values['objectdata'];
         foreach (unserialize($data) as $field => $translation) {
             if (!array_key_exists($field, $translatedFields)) {
                 $translatedFields[$field] = true;
             }
         }
     }
     // Save the old article translation as new variant translations
     foreach ($oldTranslations as $language => $values) {
         $data = unserialize($values['objectdata']);
         $newData = array_intersect_key($data, $translatedFields);
         $this->getTranslationComponent()->write($language, 'variant', $oldMainDetail->getId(), $newData, false);
     }
     // Save the new mainDetail translations as article translations
     foreach ($newTranslations as $language => $values) {
         $data = unserialize($values['objectdata']);
         $newData = array_intersect_key($data, $translatedFields);
         // We need to check and include old translations, as an article
         // translation is a superset of a variant translation
         if ($oldValues = $oldTranslations[$language]) {
             $oldData = unserialize($oldValues['objectdata']);
             $newData = array_merge($oldData, $newData);
         }
         $this->getTranslationComponent()->write($language, 'article', $articleId, $newData, false);
     }
 }
示例#4
0
 /**
  * @param \Shopware\Models\Article\Detail $articleDetail
  */
 public function setArticleDetail(\Shopware\Models\Article\Detail $articleDetail)
 {
     $this->articleDetail = $articleDetail;
     $this->article = $articleDetail->getArticle();
 }