/** * Collect address subtotal * * @param Address $address * @return $this */ public function collect(Address $address) { parent::collect($address); $address->setTotalQty(0); $baseVirtualAmount = $virtualAmount = 0; /** * Process address items */ $items = $this->_getAddressItems($address); foreach ($items as $item) { if ($this->_initItem($address, $item) && $item->getQty() > 0) { /** * Separately calculate subtotal only for virtual products */ if ($item->getProduct()->isVirtual()) { $virtualAmount += $item->getRowTotal(); $baseVirtualAmount += $item->getBaseRowTotal(); } } else { $this->_removeItem($address, $item); } } $address->setBaseVirtualAmount($baseVirtualAmount); $address->setVirtualAmount($virtualAmount); /** * Initialize grand totals */ $this->_salesData->checkQuoteAmount($address->getQuote(), $address->getSubtotal()); $this->_salesData->checkQuoteAmount($address->getQuote(), $address->getBaseSubtotal()); return $this; }
public function testCheckQuoteAmountAmountGreaterThanAvailable() { $this->quoteMock->expects($this->once())->method('getHasError')->will($this->returnValue(false)); $this->quoteMock->expects($this->once())->method('setHasError')->with(true); $this->quoteMock->expects($this->once())->method('addMessage')->with(__('This item price or quantity is not valid for checkout.')); $this->assertSame($this->helper, $this->helper->checkQuoteAmount($this->quoteMock, Data::MAXIMUM_AVAILABLE_NUMBER + 1)); }
/** * Collect totals * * @return $this */ public function collectTotals() { /** * Protect double totals collection */ if ($this->getTotalsCollectedFlag()) { return $this; } $this->_eventManager->dispatch($this->_eventPrefix . '_collect_totals_before', array($this->_eventObject => $this)); $this->_collectItemsQtys(); $this->setSubtotal(0); $this->setBaseSubtotal(0); $this->setSubtotalWithDiscount(0); $this->setBaseSubtotalWithDiscount(0); $this->setGrandTotal(0); $this->setBaseGrandTotal(0); foreach ($this->getAllAddresses() as $address) { $address->setSubtotal(0); $address->setBaseSubtotal(0); $address->setGrandTotal(0); $address->setBaseGrandTotal(0); $address->collectTotals(); $this->setSubtotal((double) $this->getSubtotal() + $address->getSubtotal()); $this->setBaseSubtotal((double) $this->getBaseSubtotal() + $address->getBaseSubtotal()); $this->setSubtotalWithDiscount((double) $this->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()); $this->setBaseSubtotalWithDiscount((double) $this->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()); $this->setGrandTotal((double) $this->getGrandTotal() + $address->getGrandTotal()); $this->setBaseGrandTotal((double) $this->getBaseGrandTotal() + $address->getBaseGrandTotal()); } $this->_salesData->checkQuoteAmount($this, $this->getGrandTotal()); $this->_salesData->checkQuoteAmount($this, $this->getBaseGrandTotal()); $this->setData('trigger_recollect', 0); $this->_validateCouponCode(); $this->_eventManager->dispatch($this->_eventPrefix . '_collect_totals_after', array($this->_eventObject => $this)); $this->setTotalsCollectedFlag(true); return $this; }