77
88namespace Magento \Quote \Model \Quote ;
99
10+ use Magento \Framework \App \ObjectManager ;
1011use Magento \Quote \Model \Quote \Address \Total \Collector ;
1112use Magento \Quote \Model \Quote \Address \Total \CollectorFactory ;
1213use Magento \Quote \Model \Quote \Address \Total \CollectorInterface ;
1314
1415/**
15- * Class TotalsCollector
16+ * Composite object for collecting total.
1617 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1718 */
1819class TotalsCollector
@@ -68,6 +69,11 @@ class TotalsCollector
6869 */
6970 protected $ shippingAssignmentFactory ;
7071
72+ /**
73+ * @var QuantityCollector
74+ */
75+ private $ quantityCollector ;
76+
7177 /**
7278 * @param Collector $totalCollector
7379 * @param CollectorFactory $totalCollectorFactory
@@ -78,6 +84,7 @@ class TotalsCollector
7884 * @param \Magento\Quote\Model\ShippingFactory $shippingFactory
7985 * @param \Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory
8086 * @param \Magento\Quote\Model\QuoteValidator $quoteValidator
87+ * @param QuantityCollector $quantityCollector
8188 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
8289 */
8390 public function __construct (
@@ -89,7 +96,8 @@ public function __construct(
8996 \Magento \Quote \Model \Quote \TotalsCollectorList $ collectorList ,
9097 \Magento \Quote \Model \ShippingFactory $ shippingFactory ,
9198 \Magento \Quote \Model \ShippingAssignmentFactory $ shippingAssignmentFactory ,
92- \Magento \Quote \Model \QuoteValidator $ quoteValidator
99+ \Magento \Quote \Model \QuoteValidator $ quoteValidator ,
100+ QuantityCollector $ quantityCollector = null
93101 ) {
94102 $ this ->totalCollector = $ totalCollector ;
95103 $ this ->totalCollectorFactory = $ totalCollectorFactory ;
@@ -100,6 +108,8 @@ public function __construct(
100108 $ this ->shippingFactory = $ shippingFactory ;
101109 $ this ->shippingAssignmentFactory = $ shippingAssignmentFactory ;
102110 $ this ->quoteValidator = $ quoteValidator ;
111+ $ this ->quantityCollector = $ quantityCollector
112+ ?: ObjectManager::getInstance ()->get (QuantityCollector::class);
103113 }
104114
105115 /**
@@ -132,7 +142,7 @@ public function collect(\Magento\Quote\Model\Quote $quote)
132142 ['quote ' => $ quote ]
133143 );
134144
135- $ this ->_collectItemsQtys ($ quote );
145+ $ this ->quantityCollector -> collectItemsQtys ($ quote );
136146
137147 $ total ->setSubtotal (0 );
138148 $ total ->setBaseSubtotal (0 );
@@ -206,6 +216,8 @@ protected function _validateCouponCode(\Magento\Quote\Model\Quote $quote)
206216 *
207217 * @param \Magento\Quote\Model\Quote $quote
208218 * @return $this
219+ * @deprecated
220+ * @see \Magento\Quote\Model\Quote\QuantityCollector
209221 */
210222 protected function _collectItemsQtys (\Magento \Quote \Model \Quote $ quote )
211223 {
@@ -273,7 +285,7 @@ public function collectAddressTotals(
273285 /** @var CollectorInterface $collector */
274286 $ collector ->collect ($ quote , $ shippingAssignment , $ total );
275287 }
276-
288+
277289 $ this ->eventManager ->dispatch (
278290 'sales_quote_address_collect_totals_after ' ,
279291 [
0 commit comments