Skip to content

Commit 4158cc3

Browse files
author
Jon Doe
committed
ACP2E-31: Free Shipping does not show in totals on invoice page
1 parent 5a25f8f commit 4158cc3

File tree

6 files changed

+43
-31
lines changed

6 files changed

+43
-31
lines changed

app/code/Magento/Sales/Block/Adminhtml/Totals.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ protected function _initTotals()
9797
$shippingLabel = __('Shipping & Handling');
9898

9999
if (!isset($this->_totals['discount'])) {
100-
if ($order->getCouponCode() ) {
100+
if ($order->getCouponCode()) {
101101
$shippingLabel .= " ({$order->getCouponCode()})";
102-
} else if ($order->getDiscountDescription()) {
102+
} elseif ($order->getDiscountDescription()) {
103103
$shippingLabel .= " ({$order->getDiscountDescription()})";
104104
}
105105
}

app/code/Magento/Sales/Block/Order/Invoice/Totals.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Sales\Block\Order\Invoice;
77

8-
use Magento\Sales\Model\Order\Invoice;
8+
use Magento\Sales\Model\Order;
99

1010
/**
1111
* @api
@@ -33,6 +33,8 @@ public function __construct(
3333
protected $_invoice = null;
3434

3535
/**
36+
* Get order
37+
*
3638
* @return Order
3739
*/
3840
public function getInvoice()
@@ -50,6 +52,8 @@ public function getInvoice()
5052
}
5153

5254
/**
55+
* Set Order
56+
*
5357
* @param Order $invoice
5458
* @return $this
5559
*/

app/code/Magento/Sales/Block/Order/Totals.php

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,7 @@ protected function _initTotals()
142142
);
143143
}
144144

145-
/**
146-
* Add shipping
147-
*/
148-
if (!$source->getIsVirtual()
149-
&& ($source->getShippingAmount() !== null
150-
|| $source->getShippingDescription())
151-
) {
152-
$shippingLabel = __('Shipping & Handling');
153-
154-
if (!isset($this->_totals['discount'])) {
155-
if ($source->getCouponCode() ) {
156-
$shippingLabel .= " ({$source->getCouponCode()})";
157-
} else if ($source->getDiscountDescription()) {
158-
$shippingLabel .= " ({$source->getDiscountDescription()})";
159-
}
160-
}
161-
$this->_totals['shipping'] = new DataObject(
162-
[
163-
'code' => 'shipping',
164-
'field' => 'shipping_amount',
165-
'value' => $source->getShippingAmount(),
166-
'label' => $shippingLabel,
167-
]
168-
);
169-
}
145+
$this->addShippingTotal($source);
170146

171147
$this->_totals['grand_total'] = new \Magento\Framework\DataObject(
172148
[
@@ -194,6 +170,38 @@ protected function _initTotals()
194170
return $this;
195171
}
196172

173+
/**
174+
* add shipping total
175+
*
176+
* @param Order|Order\Invoice $source
177+
* @retrurn void
178+
*/
179+
private function addShippingTotal($source)
180+
{
181+
if (!$source->getIsVirtual()
182+
&& ($source->getShippingAmount() !== null
183+
|| $source->getShippingDescription())
184+
) {
185+
$shippingLabel = __('Shipping & Handling');
186+
187+
if (!isset($this->_totals['discount'])) {
188+
if ($source->getCouponCode()) {
189+
$shippingLabel .= " ({$source->getCouponCode()})";
190+
} elseif ($source->getDiscountDescription()) {
191+
$shippingLabel .= " ({$source->getDiscountDescription()})";
192+
}
193+
}
194+
$this->_totals['shipping'] = new DataObject(
195+
[
196+
'code' => 'shipping',
197+
'field' => 'shipping_amount',
198+
'value' => $source->getShippingAmount(),
199+
'label' => $shippingLabel,
200+
]
201+
);
202+
}
203+
}
204+
197205
/**
198206
* Add new total to totals array after specific total or before last total by default
199207
*

app/code/Magento/Sales/Model/Order/Invoice/Total/Shipping.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
class Shipping extends AbstractTotal
1414
{
1515
/**
16+
* Collect shipping total
17+
*
1618
* @param \Magento\Sales\Model\Order\Invoice $invoice
1719
* @return $this
1820
*/
@@ -27,7 +29,7 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
2729
* Check shipping amount in previous invoices
2830
*/
2931
foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
30-
if ((double)$previousInvoice->getShippingAmount() !== null && !$previousInvoice->isCanceled()) {
32+
if ($previousInvoice->getShippingAmount() !== null && !$previousInvoice->isCanceled()) {
3133
return $this;
3234
}
3335
}

dev/tests/integration/testsuite/Magento/Sales/Block/Order/Invoice/TotalsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ protected function setUp(): void
4444
$this->orderFactory = $this->objectManager->get(OrderInterfaceFactory::class);
4545
}
4646

47-
4847
/**
4948
* @magentoDataFixture Magento/Sales/_files/order_with_free_shipping_by_coupon_and_invoice.php
5049
*

dev/tests/integration/testsuite/Magento/Sales/_files/order_with_free_shipping_by_coupon_and_invoice.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@
2828
$transactionSave = $objectManager
2929
->create(\Magento\Framework\DB\Transaction::class);
3030
$transactionSave->addObject($invoice)->addObject($order)->save();
31-

0 commit comments

Comments
 (0)