Exemple #1
0
 /**
  * Internal helper function to save the dynamic attributes of an article price.
  * @param $position
  * @param $attributeData
  * @return mixed
  */
 private function savePositionAttributes($position, $attributeData)
 {
     if (empty($attributeData)) {
         return;
     }
     if ($position->getId() > 0) {
         $builder = Shopware()->Models()->createQueryBuilder();
         $builder->select(array('attribute'))->from('Shopware\\Models\\Attribute\\OrderDetail', 'attribute')->where('attribute.orderDetailId = ?1')->setParameter(1, $position->getId());
         $result = $builder->getQuery()->getOneOrNullResult();
         if (empty($result)) {
             $attributes = new \Shopware\Models\Attribute\OrderDetail();
         } else {
             $attributes = $result;
         }
     } else {
         $attributes = new \Shopware\Models\Attribute\OrderDetail();
     }
     $attributes->fromArray($attributeData);
     $attributes->setOrderDetail($position);
     $this->getManager()->persist($attributes);
 }
 /**
  * @param array $position
  * @param Shopware\Models\Order\Order $orderModel
  * @return array
  */
 private function createOrderDetail($position, $orderModel)
 {
     $orderDetailModel = new Shopware\Models\Order\Detail();
     $articleIds = Shopware()->Db()->fetchRow("SELECT a.id, ad.id AS detailId\n              FROM s_articles a, s_articles_details ad\n              WHERE a.id = ad.articleID\n              AND ad.ordernumber = ?", [$position['articleNumber']]);
     //checks if the article exists
     if (empty($articleIds)) {
         $articleIdentification = $this->createInvalidArticleIdentificationForErrorMessage($position);
         return ['success' => false, 'article' => $articleIdentification];
     }
     $articleId = $articleIds['id'];
     $articleDetailId = $articleIds['detailId'];
     /** @var Shopware\Models\Article\Article $articleModel */
     $articleModel = Shopware()->Models()->find('Shopware\\Models\\Article\\Article', $articleId);
     /** @var Shopware\Models\Article\Detail $articleDetailModel */
     $articleDetailModel = Shopware()->Models()->find('Shopware\\Models\\Article\\Detail', $articleDetailId);
     if (is_object($articleDetailModel->getUnit())) {
         $unitName = $articleDetailModel->getUnit()->getName();
     } else {
         $unitName = 0;
     }
     /** @var Shopware\Models\Tax\Tax $taxModel */
     $taxModel = Shopware()->Models()->find('Shopware\\Models\\Tax\\Tax', $position['taxId']);
     $orderDetailModel->setTax($taxModel);
     if ($orderModel->getNet()) {
         $orderDetailModel->setTaxRate(0);
     } else {
         $orderDetailModel->setTaxRate($position['taxRate']);
     }
     /** checks if it is an esdArticle */
     $orderDetailModel->setEsdArticle(0);
     /** @var Shopware\Models\Order\DetailStatus $detailStatusModel */
     $detailStatusModel = Shopware()->Models()->find('Shopware\\Models\\Order\\DetailStatus', 0);
     $orderDetailModel->setStatus($detailStatusModel);
     $orderDetailModel->setArticleId($articleModel->getId());
     $orderDetailModel->setArticleName($articleModel->getName());
     $orderDetailModel->setArticleNumber($articleDetailModel->getNumber());
     $orderDetailModel->setPrice($position['price']);
     $orderDetailModel->setMode($position['mode']);
     $orderDetailModel->setQuantity($position['quantity']);
     $orderDetailModel->setShipped(0);
     $orderDetailModel->setUnit($unitName);
     $orderDetailModel->setPackUnit($articleDetailModel->getPackUnit());
     $orderDetailModel->setNumber($orderModel->getNumber());
     $orderDetailModel->setOrder($orderModel);
     /** @var \Shopware\Models\Attribute\OrderDetail $orderDetailAttributeModel */
     $orderDetailAttributeModel = new \Shopware\Models\Attribute\OrderDetail();
     $orderDetailAttributeModel->setAttribute1('');
     $orderDetailAttributeModel->setAttribute2('');
     $orderDetailAttributeModel->setAttribute3('');
     $orderDetailAttributeModel->setAttribute4('');
     $orderDetailAttributeModel->setAttribute5('');
     $orderDetailAttributeModel->setAttribute6('');
     $orderDetailModel->setAttribute($orderDetailAttributeModel);
     return $orderDetailModel;
 }