Exemplo n.º 1
0
 /**
  * Initialize quote item object
  *
  * @param \Magento\Framework\Object $request
  * @param Product $product
  *
  * @return \Magento\Sales\Model\Quote\Item
  */
 public function init(Product $product, $request)
 {
     $item = $this->quoteItemFactory->create();
     $this->setItemStoreId($item);
     /**
      * We can't modify existing child items
      */
     if ($item->getId() && $product->getParentProductId()) {
         return $item;
     }
     $item->setOptions($product->getCustomOptions());
     $item->setProduct($product);
     if ($request->getResetCount() && !$product->getStickWithinParent() && $item->getId() === $request->getId()) {
         $item->setData('qty', 0);
     }
     return $item;
 }
Exemplo n.º 2
0
 /**
  * Adding catalog product object data to quote
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param int $qty
  * @return \Magento\Sales\Model\Quote\Item
  */
 protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $qty = 1)
 {
     $newItem = false;
     $item = $this->getItemByProduct($product);
     if (!$item) {
         $item = $this->_quoteItemFactory->create();
         $item->setQuote($this);
         if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
             $item->setStoreId($this->getStore()->getId());
         } else {
             $item->setStoreId($this->_storeManager->getStore()->getId());
         }
         $newItem = true;
     }
     /**
      * We can't modify existing child items
      */
     if ($item->getId() && $product->getParentProductId()) {
         return $item;
     }
     $item->setOptions($product->getCustomOptions())->setProduct($product);
     // Add only item that is not in quote already (there can be other new or already saved item
     if ($newItem) {
         $this->addItem($item);
     }
     return $item;
 }
Exemplo n.º 3
0
 /**
  * Retrieve
  *
  * @param \Magento\Sales\Model\Order\Item $item
  * @return \Magento\Sales\Model\Quote\Item
  */
 public function itemToQuoteItem(\Magento\Sales\Model\Order\Item $item)
 {
     $quoteItem = $this->_quoteItemFactory->create()->setStoreId($item->getOrder()->getStoreId())->setQuoteItemId($item->getId())->setProductId($item->getProductId())->setParentProductId($item->getParentProductId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order_item', 'to_quote_item', $item, $quoteItem);
     return $quoteItem;
 }