11 use Magento\Quote\Model\Quote\Address\Total\CollectorFactory;
111 if (
$quote->isVirtual()) {
112 return $this->collectAddressTotals(
$quote,
$quote->getBillingAddress());
114 return $this->collectAddressTotals(
$quote,
$quote->getShippingAddress());
126 $this->eventManager->dispatch(
127 'sales_quote_collect_totals_before',
133 $total->setSubtotal(0);
134 $total->setBaseSubtotal(0);
136 $total->setSubtotalWithDiscount(0);
137 $total->setBaseSubtotalWithDiscount(0);
139 $total->setGrandTotal(0);
140 $total->setBaseGrandTotal(0);
146 $total->setShippingAmount($addressTotal->getShippingAmount());
147 $total->setBaseShippingAmount($addressTotal->getBaseShippingAmount());
148 $total->setShippingDescription($addressTotal->getShippingDescription());
150 $total->setSubtotal((
float)$total->getSubtotal() + $addressTotal->getSubtotal());
151 $total->setBaseSubtotal((
float)$total->getBaseSubtotal() + $addressTotal->getBaseSubtotal());
153 $total->setSubtotalWithDiscount(
154 (
float)$total->getSubtotalWithDiscount() + $addressTotal->getSubtotalWithDiscount()
156 $total->setBaseSubtotalWithDiscount(
157 (
float)$total->getBaseSubtotalWithDiscount() + $addressTotal->getBaseSubtotalWithDiscount()
160 $total->setGrandTotal((
float)$total->getGrandTotal() + $addressTotal->getGrandTotal());
161 $total->setBaseGrandTotal((
float)$total->getBaseGrandTotal() + $addressTotal->getBaseGrandTotal());
164 $this->quoteValidator->validateQuoteAmount(
$quote,
$quote->getGrandTotal());
165 $this->quoteValidator->validateQuoteAmount(
$quote,
$quote->getBaseGrandTotal());
167 $this->eventManager->dispatch(
168 'sales_quote_collect_totals_after',
182 $addressHasCoupon =
false;
187 $addressHasCoupon =
true;
190 if (!$addressHasCoupon) {
191 $quote->setCouponCode(
'');
208 $quote->setVirtualItemsQty(0);
211 if (
$item->getParentItem()) {
218 if ($child->getProduct()->getIsVirtual()) {
219 $quote->setVirtualItemsQty(
$quote->getVirtualItemsQty() + $child->getQty() *
$item->getQty());
224 if (
$item->getProduct()->getIsVirtual()) {
238 public function collectAddressTotals(
243 $shippingAssignment = $this->shippingAssignmentFactory->create();
246 $shipping = $this->shippingFactory->create();
247 $shipping->setMethod(
$address->getShippingMethod());
249 $shippingAssignment->setShipping($shipping);
250 $shippingAssignment->setItems(
$address->getAllItems());
254 $this->eventManager->dispatch(
255 'sales_quote_address_collect_totals_before',
258 'shipping_assignment' => $shippingAssignment,
263 foreach ($this->collectorList->getCollectors(
$quote->getStoreId()) as $collector) {
265 $collector->collect(
$quote, $shippingAssignment, $total);
268 $this->eventManager->dispatch(
269 'sales_quote_address_collect_totals_after',
272 'shipping_assignment' => $shippingAssignment,
277 $address->addData($total->getData());
278 $address->setAppliedTaxes($total->getAppliedTaxes());
_validateCouponCode(\Magento\Quote\Model\Quote $quote)
_collectItemsQtys(\Magento\Quote\Model\Quote $quote)
__construct(Collector $totalCollector, CollectorFactory $totalCollectorFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Quote\Model\Quote\Address\TotalFactory $totalFactory, \Magento\Quote\Model\Quote\TotalsCollectorList $collectorList, \Magento\Quote\Model\ShippingFactory $shippingFactory, \Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory, \Magento\Quote\Model\QuoteValidator $quoteValidator)
collectQuoteTotals(\Magento\Quote\Model\Quote $quote)
$shippingAssignmentFactory