コード例 #1
0
ファイル: Quote.php プロジェクト: aiesh/magento2
 /**
  * Convert quote item to order item
  *
  * @param   \Magento\Sales\Model\Quote\Item\AbstractItem $item
  * @return  \Magento\Sales\Model\Order\Item
  */
 public function itemToOrderItem(\Magento\Sales\Model\Quote\Item\AbstractItem $item)
 {
     $orderItem = $this->_orderItemFactory->create()->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setQuoteParentItemId($item->getParentItemId())->setProductId($item->getProductId())->setProductType($item->getProductType())->setQtyBackordered($item->getBackorders())->setProduct($item->getProduct())->setBaseOriginalPrice($item->getBaseOriginalPrice());
     $options = $item->getProductOrderOptions();
     if (!$options) {
         $options = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
     }
     $orderItem->setProductOptions($options);
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_quote_item', 'to_order_item', $item, $orderItem);
     if ($item->getParentItem()) {
         $orderItem->setQtyOrdered($orderItem->getQtyOrdered() * $item->getParentItem()->getQty());
     }
     if (!$item->getNoDiscount()) {
         $this->_objectCopyService->copyFieldsetToTarget('sales_convert_quote_item', 'to_order_item_discount', $item, $orderItem);
     }
     return $orderItem;
 }
コード例 #2
0
ファイル: Address.php プロジェクト: aiesh/magento2
 /**
  * Add item to address
  *
  * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item
  * @param int $qty
  * @return $this
  */
 public function addItem(\Magento\Sales\Model\Quote\Item\AbstractItem $item, $qty = null)
 {
     if ($item instanceof \Magento\Sales\Model\Quote\Item) {
         if ($item->getParentItemId()) {
             return $this;
         }
         $addressItem = $this->_addressItemFactory->create()->setAddress($this)->importQuoteItem($item);
         $this->getItemsCollection()->addItem($addressItem);
         if ($item->getHasChildren()) {
             foreach ($item->getChildren() as $child) {
                 $addressChildItem = $this->_addressItemFactory->create()->setAddress($this)->importQuoteItem($child)->setParentItem($addressItem);
                 $this->getItemsCollection()->addItem($addressChildItem);
             }
         }
     } else {
         $addressItem = $item;
         $addressItem->setAddress($this);
         if (!$addressItem->getId()) {
             $this->getItemsCollection()->addItem($addressItem);
         }
     }
     if ($qty) {
         $addressItem->setQty($qty);
     }
     return $this;
 }