Example #1
0
 /**
  * Address item initialization
  *
  * @param Address $address
  * @param AddressItem|Item $item
  * @return bool
  */
 protected function _initItem($address, $item)
 {
     if ($item instanceof AddressItem) {
         $quoteItem = $item->getAddress()->getQuote()->getItemById($item->getQuoteItemId());
     } else {
         $quoteItem = $item;
     }
     $product = $quoteItem->getProduct();
     $product->setCustomerGroupId($quoteItem->getQuote()->getCustomerGroupId());
     /**
      * Quote super mode flag mean what we work with quote without restriction
      */
     if ($item->getQuote()->getIsSuperMode()) {
         if (!$product) {
             return false;
         }
     } else {
         if (!$product || !$product->isVisibleInCatalog()) {
             return false;
         }
     }
     $originalPrice = $product->getPrice();
     if ($quoteItem->getParentItem() && $quoteItem->isChildrenCalculated()) {
         $finalPrice = $quoteItem->getParentItem()->getProduct()->getPriceModel()->getChildFinalPrice($quoteItem->getParentItem()->getProduct(), $quoteItem->getParentItem()->getQty(), $product, $quoteItem->getQty());
         $this->_calculateRowTotal($item, $finalPrice, $originalPrice);
     } elseif (!$quoteItem->getParentItem()) {
         $finalPrice = $product->getFinalPrice($quoteItem->getQty());
         $this->_calculateRowTotal($item, $finalPrice, $originalPrice);
         $this->_addAmount($item->getRowTotal());
         $this->_addBaseAmount($item->getBaseRowTotal());
         $address->setTotalQty($address->getTotalQty() + $item->getQty());
     }
     return true;
 }
Example #2
0
 public function testSetAndQuote()
 {
     $idValue = "id_value";
     $quote = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->setMethods(['getId', 'getStoreId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $quote->expects($this->once())->method('getId')->will($this->returnValue($idValue));
     $quote->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
     $this->model->setQuote($quote);
     $this->assertSame($quote, $this->model->getQuote());
     $this->assertEquals($idValue, $this->model->getQuoteId());
 }
Example #3
0
 /**
  * @param \Magento\Quote\Model\Quote\Item $quoteItem
  * @return $this
  */
 public function importQuoteItem(\Magento\Quote\Model\Quote\Item $quoteItem)
 {
     $this->_quote = $quoteItem->getQuote();
     $this->setQuoteItem($quoteItem)->setQuoteItemId($quoteItem->getId())->setProductId($quoteItem->getProductId())->setProduct($quoteItem->getProduct())->setSku($quoteItem->getSku())->setName($quoteItem->getName())->setDescription($quoteItem->getDescription())->setWeight($quoteItem->getWeight())->setPrice($quoteItem->getPrice())->setCost($quoteItem->getCost());
     if (!$this->hasQty()) {
         $this->setQty($quoteItem->getQty());
     }
     $this->setQuoteItemImported(true);
     return $this;
 }
 /**
  * Removes error statuses from quote and item, set by this observer
  *
  * @param \Magento\Quote\Model\Quote\Item $item
  * @param int $code
  * @return void
  */
 protected function _removeErrorsFromQuoteAndItem($item, $code)
 {
     if ($item->getHasError()) {
         $params = ['origin' => 'cataloginventory', 'code' => $code];
         $item->removeErrorInfosByParams($params);
     }
     $quote = $item->getQuote();
     $quoteItems = $quote->getItemsCollection();
     $canRemoveErrorFromQuote = true;
     foreach ($quoteItems as $quoteItem) {
         if ($quoteItem->getItemId() == $item->getItemId()) {
             continue;
         }
         $errorInfos = $quoteItem->getErrorInfos();
         foreach ($errorInfos as $errorInfo) {
             if ($errorInfo['code'] == $code) {
                 $canRemoveErrorFromQuote = false;
                 break;
             }
         }
         if (!$canRemoveErrorFromQuote) {
             break;
         }
     }
     if ($quote->getHasError() && $canRemoveErrorFromQuote) {
         $params = ['origin' => 'cataloginventory', 'code' => $code];
         $quote->removeErrorInfosByParams(null, $params);
     }
 }