/**
  * Recalculates the Amount for the given items
  *
  * @param array $items
  *
  * @return float
  */
 private function getRecalculatedAmount($items)
 {
     $basket = array();
     foreach ($items as $item) {
         $detailModel = new \Shopware\Models\Order\Detail();
         $detailModel->setQuantity($item->getQuantity());
         $detailModel->setPrice($item->getUnitPriceGross());
         $detailModel->setTaxRate($item->getTaxRate());
         $detailModel->setArticleName($item->getArticleName());
         $detailModel->setArticleNumber($item->getArticleNumber());
         $basket[] = $detailModel;
     }
     $orderModel = new \Shopware\Models\Order\Order();
     $orderModel->setDetails($basket);
     $orderModel->calculateInvoiceAmount();
     return $orderModel->getInvoiceAmount();
 }
Esempio n. 2
0
 /**
  * @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;
 }