Example #1
0
 public function testGetAddress()
 {
     $quote = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->setMethods(['getShippingAddress', 'getBillingAddress', '__wakeup'])->disableOriginalConstructor()->getMock();
     $quote->expects($this->once())->method('getShippingAddress')->will($this->returnValue('shipping'));
     $quote->expects($this->once())->method('getBillingAddress')->will($this->returnValue('billing'));
     $this->model->setQuote($quote);
     $quote->setItemsQty(2);
     $quote->setVirtualItemsQty(1);
     $this->assertEquals('shipping', $this->model->getAddress(), 'Wrong shipping address');
     $quote->setItemsQty(2);
     $quote->setVirtualItemsQty(2);
     $this->assertEquals('billing', $this->model->getAddress(), 'Wrong billing address');
 }
Example #2
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);
     } else {
         if (!$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;
 }