Esempio n. 1
0
 /**
  * @param \Shopware\Models\Article\Detail|array|null $mainDetail
  * @return \Shopware\Models\Article\Detail
  */
 public function setMainDetail($mainDetail)
 {
     $return = $this->setOneToOne($mainDetail, '\\Shopware\\Models\\Article\\Detail', 'mainDetail', 'article');
     if ($this->mainDetail instanceof \Shopware\Models\Article\Detail) {
         $this->mainDetail->setKind(1);
     }
     return $return;
 }
Esempio n. 2
0
    /**
     * @param array $variantData
     * @param \Shopware\Models\Article\Article $article
     * @param \Shopware\Models\Article\Detail $variant
     * @throws \Shopware\Components\Api\Exception\CustomValidationException
     * @return array
     */
    protected function prepareVariantAttributeAssociatedData($variantData, ArticleModel $article, \Shopware\Models\Article\Detail $variant)
    {
        if (!$variant->getAttribute()) {
            $variantData['attribute']['article'] = $article;
        }

        if (!isset($variantData['attribute'])) {
            return $variantData;
        }

        $variantData['attribute']['article'] = $article;
        return $variantData;
    }
Esempio n. 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);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setManyToOne($data, $model, $property)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setManyToOne', array($data, $model, $property));
     return parent::setManyToOne($data, $model, $property);
 }
Esempio n. 5
0
 /**
  * @param \Shopware\Models\Article\Detail $variant
  * @param Order $order
  * @return null|\Shopware\Models\Order\Detail
  */
 private function getOrderPositionByProduct(\Shopware\Models\Article\Detail $variant, Order $order)
 {
     /**@var $detail \Shopware\Models\Order\Detail*/
     foreach ($order->getDetails() as $detail) {
         if (!$this->isProductPosition($detail)) {
             continue;
         }
         if ($detail->getArticleNumber() === $variant->getNumber()) {
             return $detail;
         }
     }
     return null;
 }
Esempio n. 6
0
 /**
  * @param Detail $articleDetailModel
  * @return bool
  */
 private function deleteDetail(Detail $articleDetailModel)
 {
     $ordernumber = $articleDetailModel->getNumber();
     $sql = "DELETE FROM s_articles_details WHERE ordernumber = :num";
     try {
         $this->db->query($sql, array('num' => $ordernumber));
     } catch (\Exception $ex) {
         return false;
     }
     return true;
 }
Esempio n. 7
0
 /**
  * @param $data
  * @param ArticleModel $article
  * @param Detail $variant
  * @return mixed
  */
 protected function prepareAttributeAssociation($data, ArticleModel $article, Detail $variant)
 {
     if (!$variant->getAttribute()) {
         $data['attribute']['article'] = $article;
     }
     if (!isset($data['attribute'])) {
         return $data;
     }
     $data['attribute']['article'] = $article;
     return $data;
 }
Esempio n. 8
0
 /**
  * @param \Shopware\Models\Article\Detail $articleDetail
  */
 public function setArticleDetail(\Shopware\Models\Article\Detail $articleDetail)
 {
     $this->articleDetail = $articleDetail;
     $this->article = $articleDetail->getArticle();
 }
Esempio n. 9
0
 /**
  * Checks if the passed article image is already created
  * as variant image.
  *
  * @param Detail $variant
  * @param Image $image
  * @return bool
  */
 protected function isVariantImageExist(Detail $variant, Image $image)
 {
     /**@var $variantImage Image */
     foreach ($variant->getImages() as $variantImage) {
         if ($variantImage->getParent()->getId() == $image->getId()) {
             return true;
         }
     }
     return false;
 }