1212use Magento \Sales \Model \Order ;
1313
1414/**
15+ * Tax totals modification block.
16+ *
1517 * @api
1618 * @since 100.0.2
1719 */
@@ -103,6 +105,10 @@ public function initTotals()
103105 protected function _addTax ($ after = 'discount ' )
104106 {
105107 $ taxTotal = new \Magento \Framework \DataObject (['code ' => 'tax ' , 'block_name ' => $ this ->getNameInLayout ()]);
108+ $ totals = $ this ->getParentBlock ()->getTotals ();
109+ if ($ totals ['grand_total ' ]) {
110+ $ this ->getParentBlock ()->addTotalBefore ($ taxTotal , 'grand_total ' );
111+ }
106112 $ this ->getParentBlock ()->addTotal ($ taxTotal , $ after );
107113 return $ this ;
108114 }
@@ -118,6 +124,8 @@ public function getStore()
118124 }
119125
120126 /**
127+ * Initialization grand total.
128+ *
121129 * @return $this
122130 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
123131 */
@@ -199,6 +207,8 @@ protected function _initSubtotal()
199207 }
200208
201209 /**
210+ * Init shipping.
211+ *
202212 * @return $this
203213 */
204214 protected function _initShipping ()
@@ -260,13 +270,19 @@ protected function _initShipping()
260270 }
261271
262272 /**
273+ * Init discount.
274+ *
275+ * phpcs:disable Magento2.CodeAnalysis.EmptyBlock
276+ *
263277 * @return void
264278 */
265279 protected function _initDiscount ()
266280 {
267281 }
268-
282+ //phpcs:enable
269283 /**
284+ * Init grand total.
285+ *
270286 * @return $this
271287 */
272288 protected function _initGrandTotal ()
@@ -304,13 +320,15 @@ protected function _initGrandTotal()
304320 ]
305321 );
306322 $ parent ->addTotal ($ totalExcl , 'grand_total ' );
307- $ this ->_addTax ('grand_total ' );
308323 $ parent ->addTotal ($ totalIncl , 'tax ' );
324+ $ this ->_addTax ('grand_total ' );
309325 }
310326 return $ this ;
311327 }
312328
313329 /**
330+ * Return order.
331+ *
314332 * @return Order
315333 */
316334 public function getOrder ()
@@ -319,6 +337,8 @@ public function getOrder()
319337 }
320338
321339 /**
340+ * Return label properties.
341+ *
322342 * @return array
323343 */
324344 public function getLabelProperties ()
@@ -327,6 +347,8 @@ public function getLabelProperties()
327347 }
328348
329349 /**
350+ * Retuen value properties.
351+ *
330352 * @return array
331353 */
332354 public function getValueProperties ()
0 commit comments