Example #1
0
 /**
  * Initialize stock item
  *
  * @param \Magento\CatalogInventory\Model\Stock\Item $stockItem
  * @param \Magento\Sales\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 public function initialize(\Magento\CatalogInventory\Model\Stock\Item $stockItem, \Magento\Sales\Model\Quote\Item $quoteItem, $qty)
 {
     /**
      * When we work with subitem
      */
     if ($quoteItem->getParentItem()) {
         $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
         /**
          * we are using 0 because original qty was processed
          */
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), 0);
     } else {
         $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
         $rowQty = $qty;
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseQty);
     }
     $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
     if (!is_null($productTypeCustomOption)) {
         // Check if product related to current item is a part of product that represents product set
         if ($this->typeConfig->isProductSet($productTypeCustomOption->getValue())) {
             $stockItem->setProductName($quoteItem->getProduct()->getName());
             $stockItem->setIsChildItem(true);
         }
     }
     $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty);
     if ($stockItem->hasIsChildItem()) {
         $stockItem->unsIsChildItem();
     }
     if (!is_null($result->getItemIsQtyDecimal())) {
         $quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
         if ($quoteItem->getParentItem()) {
             $quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
         }
     }
     /**
      * Just base (parent) item qty can be changed
      * qty of child products are declared just during add process
      * exception for updating also managed by product type
      */
     if ($result->getHasQtyOptionUpdate() && (!$quoteItem->getParentItem() || $quoteItem->getParentItem()->getProduct()->getTypeInstance()->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct()))) {
         $quoteItem->setData('qty', $result->getOrigQty());
     }
     if (!is_null($result->getItemUseOldQty())) {
         $quoteItem->setUseOldQty($result->getItemUseOldQty());
     }
     if (!is_null($result->getMessage())) {
         $quoteItem->setMessage($result->getMessage());
     }
     if (!is_null($result->getItemBackorders())) {
         $quoteItem->setBackorders($result->getItemBackorders());
     }
     return $result;
 }
Example #2
0
 /**
  * Remove item
  *
  * @param Address $address
  * @param  AddressItem|Item $item
  * @return $this
  */
 protected function _removeItem($address, $item)
 {
     if ($item instanceof Item) {
         $address->removeItem($item->getId());
         if ($address->getQuote()) {
             $address->getQuote()->removeItem($item->getId());
         }
     } elseif ($item instanceof AddressItem) {
         $address->removeItem($item->getId());
         if ($address->getQuote()) {
             $address->getQuote()->removeItem($item->getQuoteItemId());
         }
     }
     return $this;
 }
Example #3
0
 /**
  * Adding new item to quote
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 public function addItem(\Magento\Sales\Model\Quote\Item $item)
 {
     /**
      * Temporary workaround for purchase process: it is too dangerous to purchase more than one nominal item
      * or a mixture of nominal and non-nominal items, although technically possible.
      *
      * The problem is that currently it is implemented as sequential submission of nominal items and order,
      * by one click. It makes logically impossible to make the process of the purchase failsafe.
      * Proper solution is to submit items one by one with customer confirmation each time.
      */
     if ($item->isNominal() && $this->hasItems() || $this->hasNominalItems()) {
         throw new \Magento\Framework\Model\Exception(__('Sorry, but items with payment agreements must be ordered one at a time To continue, please remove or buy the other items in your cart, then order this item by itself.'));
     }
     $item->setQuote($this);
     if (!$item->getId()) {
         $this->getItemsCollection()->addItem($item);
         $this->_eventManager->dispatch('sales_quote_add_item', array('quote_item' => $item));
     }
     return $this;
 }
Example #4
0
 /**
  * Set quote item
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return $this
  */
 public function setItem($item)
 {
     $this->setItemId($item->getId());
     $this->_item = $item;
     return $this;
 }
Example #5
0
 /**
  * Return html button which calls configure window
  *
  * @param Item $item
  * @return string
  */
 public function getConfigureButtonHtml($item)
 {
     $product = $item->getProduct();
     $options = array('label' => __('Configure'));
     if ($product->canConfigure()) {
         $options['onclick'] = sprintf('order.showQuoteItemConfiguration(%s)', $item->getId());
     } else {
         $options['class'] = ' disabled';
         $options['title'] = __('This product does not have any configurable options');
     }
     return $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Button')->setData($options)->toHtml();
 }
Example #6
0
 /**
  * Get post parameters for delete from cart
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @return string
  */
 public function getDeletePostJson($item)
 {
     $url = $this->_getUrl(self::DELETE_URL);
     $data = ['id' => $item->getId()];
     if (!$this->_request->isAjax()) {
         $data[\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED] = $this->getCurrentBase64Url();
     }
     return json_encode(array('action' => $url, 'data' => $data));
 }
Example #7
0
 /**
  * Retrieve url for remove product from cart
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return  string
  */
 public function getRemoveUrl($item)
 {
     $params = array('id' => $item->getId(), \Magento\Framework\App\Action\Action::PARAM_NAME_BASE64_URL => $this->getCurrentBase64Url());
     return $this->_getUrl('checkout/cart/delete', $params);
 }
Example #8
0
 /**
  * Initialize item option
  *
  * @param \Magento\Sales\Model\Quote\Item\Option $option
  * @param \Magento\Sales\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 public function initialize(\Magento\Sales\Model\Quote\Item\Option $option, \Magento\Sales\Model\Quote\Item $quoteItem, $qty)
 {
     $optionValue = $option->getValue();
     $optionQty = $qty * $optionValue;
     $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $optionValue;
     $qtyForCheck = $this->quoteItemQtyList->getQty($option->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseOptionQty);
     $stockItem = $this->getStockItem($option, $quoteItem);
     $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue);
     if (!is_null($result->getItemIsQtyDecimal())) {
         $option->setIsQtyDecimal($result->getItemIsQtyDecimal());
     }
     if ($result->getHasQtyOptionUpdate()) {
         $option->setHasQtyOptionUpdate(true);
         $quoteItem->updateQtyOption($option, $result->getOrigQty());
         $option->setValue($result->getOrigQty());
         /**
          * if option's qty was updates we also need to update quote item qty
          */
         $quoteItem->setData('qty', intval($qty));
     }
     if (!is_null($result->getMessage())) {
         $option->setMessage($result->getMessage());
         $quoteItem->setMessage($result->getMessage());
     }
     if (!is_null($result->getItemBackorders())) {
         $option->setBackorders($result->getItemBackorders());
     }
     $stockItem->unsIsChildItem();
     return $result;
 }