Skip to content

Commit 1fa9601

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-98680' into 2.3-develop-pr19
2 parents a937dbe + 975872e commit 1fa9601

File tree

4 files changed

+131
-1
lines changed

4 files changed

+131
-1
lines changed

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

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

8+
use Magento\Sales\Model\Order;
9+
10+
/**
11+
* Adminhtml sales totals block
12+
*/
813
class Totals extends \Magento\Sales\Block\Order\Totals
914
{
1015
/**
@@ -67,12 +72,16 @@ protected function _initTotals()
6772
if (!$this->getSource()->getIsVirtual() && ((double)$this->getSource()->getShippingAmount() ||
6873
$this->getSource()->getShippingDescription())
6974
) {
75+
$shippingLabel = __('Shipping & Handling');
76+
if ($this->isFreeShipping($this->getOrder()) && $this->getSource()->getDiscountDescription()) {
77+
$shippingLabel .= sprintf(' (%s)', $this->getSource()->getDiscountDescription());
78+
}
7079
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
7180
[
7281
'code' => 'shipping',
7382
'value' => $this->getSource()->getShippingAmount(),
7483
'base_value' => $this->getSource()->getBaseShippingAmount(),
75-
'label' => __('Shipping & Handling'),
84+
'label' => $shippingLabel,
7685
]
7786
);
7887
}
@@ -109,4 +118,23 @@ protected function _initTotals()
109118

110119
return $this;
111120
}
121+
122+
/**
123+
* Availability of free shipping in at least one order item
124+
*
125+
* @param Order $order
126+
* @return bool
127+
*/
128+
private function isFreeShipping(Order $order): bool
129+
{
130+
$isFreeShipping = false;
131+
foreach ($order->getItems() as $orderItem) {
132+
if ($orderItem->getFreeShipping() == '1') {
133+
$isFreeShipping = true;
134+
break;
135+
}
136+
}
137+
138+
return $isFreeShipping;
139+
}
112140
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Block\Adminhtml;
9+
10+
use Magento\Framework\View\LayoutInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\Sales\Model\OrderFactory;
13+
14+
/**
15+
* Test class for \Magento\Sales\Block\Adminhtml\Totals
16+
*/
17+
class TotalsTest extends \Magento\TestFramework\TestCase\AbstractBackendController
18+
{
19+
/** @var LayoutInterface */
20+
private $layout;
21+
22+
/** @var Totals */
23+
private $block;
24+
25+
/** @var OrderFactory */
26+
private $orderFactory;
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
protected function setUp()
32+
{
33+
parent::setUp();
34+
$this->layout = $this->_objectManager->get(LayoutInterface::class);
35+
$this->block = $this->layout->createBlock(Totals::class, 'totals_block');
36+
$this->orderFactory = $this->_objectManager->get(OrderFactory::class);
37+
}
38+
39+
/**
40+
* @magentoDataFixture Magento/Sales/_files/order_with_free_shipping_by_coupon.php
41+
*/
42+
public function testShowShippingCoupon()
43+
{
44+
/** @var Order $order */
45+
$order = $this->orderFactory->create();
46+
$order->loadByIncrementId('100000001');
47+
48+
$this->block->setOrder($order);
49+
$this->block->toHtml();
50+
51+
$shippingTotal = $this->block->getTotal('shipping');
52+
$this->assertNotFalse($shippingTotal, 'Shipping method is absent on the total\'s block.');
53+
$this->assertContains(
54+
'1234567890',
55+
$shippingTotal->getLabel(),
56+
'Coupon code is absent in the shipping method label name.'
57+
);
58+
}
59+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Sales\Api\OrderRepositoryInterface;
9+
use Magento\Sales\Model\Order;
10+
use Magento\Sales\Model\Order\Item as OrderItem;
11+
12+
require __DIR__ . '/../../../Magento/Sales/_files/order.php';
13+
/** @var \Magento\Catalog\Model\Product $product */
14+
15+
/** @var OrderItem $orderItem */
16+
$orderItem = $objectManager->create(OrderItem::class);
17+
$orderItem->setProductId($product->getId())
18+
->setQtyOrdered(2)
19+
->setBasePrice($product->getPrice())
20+
->setPrice($product->getPrice())
21+
->setRowTotal($product->getPrice())
22+
->setProductType('simple')
23+
->setName($product->getName())
24+
->setFreeShipping('1');
25+
26+
/** @var Order $order */
27+
$order->setShippingDescription('Flat Rate - Fixed')
28+
->setShippingAmount(0)
29+
->setCouponCode('1234567890')
30+
->setDiscountDescription('1234567890')
31+
->addItem($orderItem);
32+
33+
/** @var OrderRepositoryInterface $orderRepository */
34+
$orderRepository = $objectManager->create(OrderRepositoryInterface::class);
35+
$orderRepository->save($order);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
require 'default_rollback.php';

0 commit comments

Comments
 (0)