示例#1
0
 private function createProductLinesFromOrder(Order $order)
 {
     $productLines = array();
     foreach ($order->getProductLines() as $orderProductLine) {
         $code = $orderProductLine->getProductSale()->getProduct()->getCode();
         $title = $orderProductLine->getProductSale()->getProduct()->getTitle();
         $price = $orderProductLine->getProductSale()->getPrice();
         $quantity = $orderProductLine->getQuantity();
         $productLine = new ProductLine();
         $productLine->setCode($code)->setPrice($price)->setQuantity($quantity)->setTitle($title)->setTotal($quantity * $price);
         $productLines[] = $productLine;
     }
     return $productLines;
 }
示例#2
0
 private function checkProductsStock(Order $order)
 {
     $quantities = array();
     foreach ($order->getProductLines() as $productLine) {
         $quantities[$productLine->getProductSale()->getProduct()->getId()] = $productLine->getQuantity();
     }
     $productStocks = $this->getProductStocksByProductIds(array_keys($quantities))->execute();
     foreach ($productStocks as $productStock) {
         $id = $productStock->getProduct()->getId();
         if ($quantities[$id] <= $productStock->getQuantity()) {
             unset($quantities[$id]);
         }
     }
     return empty($quantities);
 }