Skip to content

Commit f9a1b3d

Browse files
committed
Merge branch '2.3-develop' into MC-16618
2 parents c984c81 + 6e534ad commit f9a1b3d

File tree

16 files changed

+126
-35
lines changed

16 files changed

+126
-35
lines changed

app/code/Magento/Bundle/view/frontend/templates/sales/order/creditmemo/items/renderer.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</td>
6868
<td class="col discount" data-th="<?= $block->escapeHtml(__('Discount Amount')) ?>">
6969
<?php if ($block->canShowPriceInfo($_item)) : ?>
70-
<?= $block->escapeHtml($block->getOrder()->formatPrice(-$_item->getDiscountAmount())) ?>
70+
<?= $block->escapeHtml($block->getOrder()->formatPrice(-$_item->getDiscountAmount()), ['span']) ?>
7171
<?php else : ?>
7272
&nbsp;
7373
<?php endif; ?>

app/code/Magento/Catalog/view/frontend/templates/product/view/details.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
data-toggle="trigger"
2727
href="#<?= $block->escapeUrl($alias) ?>"
2828
id="tab-label-<?= $block->escapeHtmlAttr($alias) ?>-title">
29-
<?= $block->escapeHtml($label) ?>
29+
<?= /* @noEscape */ $label ?>
3030
</a>
3131
</div>
3232
<div class="data item content"

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/StockItem.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
use Magento\Catalog\Model\ProductTypes\ConfigInterface;
99
use Magento\CatalogInventory\Api\StockStateInterface;
10+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1011
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList;
12+
use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Quote\Model\Quote\Item;
1115

16+
/**
17+
* Class StockItem initializes stock item and populates it with data
18+
*/
1219
class StockItem
1320
{
1421
/**
@@ -26,26 +33,35 @@ class StockItem
2633
*/
2734
protected $stockState;
2835

36+
/**
37+
* @var StockStateProviderInterface
38+
*/
39+
private $stockStateProvider;
40+
2941
/**
3042
* @param ConfigInterface $typeConfig
3143
* @param QuoteItemQtyList $quoteItemQtyList
3244
* @param StockStateInterface $stockState
45+
* @param StockStateProviderInterface|null $stockStateProvider
3346
*/
3447
public function __construct(
3548
ConfigInterface $typeConfig,
3649
QuoteItemQtyList $quoteItemQtyList,
37-
StockStateInterface $stockState
50+
StockStateInterface $stockState,
51+
StockStateProviderInterface $stockStateProvider = null
3852
) {
3953
$this->quoteItemQtyList = $quoteItemQtyList;
4054
$this->typeConfig = $typeConfig;
4155
$this->stockState = $stockState;
56+
$this->stockStateProvider = $stockStateProvider ?: ObjectManager::getInstance()
57+
->get(StockStateProviderInterface::class);
4258
}
4359

4460
/**
4561
* Initialize stock item
4662
*
47-
* @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
48-
* @param \Magento\Quote\Model\Quote\Item $quoteItem
63+
* @param StockItemInterface $stockItem
64+
* @param Item $quoteItem
4965
* @param int $qty
5066
*
5167
* @return \Magento\Framework\DataObject
@@ -54,11 +70,14 @@ public function __construct(
5470
* @SuppressWarnings(PHPMD.NPathComplexity)
5571
*/
5672
public function initialize(
57-
\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem,
58-
\Magento\Quote\Model\Quote\Item $quoteItem,
73+
StockItemInterface $stockItem,
74+
Item $quoteItem,
5975
$qty
6076
) {
6177
$product = $quoteItem->getProduct();
78+
$quoteItemId = $quoteItem->getId();
79+
$quoteId = $quoteItem->getQuoteId();
80+
$productId = $product->getId();
6281
/**
6382
* When we work with subitem
6483
*/
@@ -68,14 +87,14 @@ public function initialize(
6887
* we are using 0 because original qty was processed
6988
*/
7089
$qtyForCheck = $this->quoteItemQtyList
71-
->getQty($product->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), 0);
90+
->getQty($productId, $quoteItemId, $quoteId, 0);
7291
} else {
7392
$increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
7493
$rowQty = $qty;
7594
$qtyForCheck = $this->quoteItemQtyList->getQty(
76-
$product->getId(),
77-
$quoteItem->getId(),
78-
$quoteItem->getQuoteId(),
95+
$productId,
96+
$quoteItemId,
97+
$quoteId,
7998
$increaseQty
8099
);
81100
}
@@ -90,14 +109,20 @@ public function initialize(
90109

91110
$stockItem->setProductName($product->getName());
92111

112+
/** @var \Magento\Framework\DataObject $result */
93113
$result = $this->stockState->checkQuoteItemQty(
94-
$product->getId(),
114+
$productId,
95115
$rowQty,
96116
$qtyForCheck,
97117
$qty,
98118
$product->getStore()->getWebsiteId()
99119
);
100120

121+
/* We need to ensure that any possible plugin will not erase the data */
122+
$backOrdersQty = $this->stockStateProvider->checkQuoteItemQty($stockItem, $rowQty, $qtyForCheck, $qty)
123+
->getItemBackorders();
124+
$result->setItemBackorders($backOrdersQty);
125+
101126
if ($stockItem->hasIsChildItem()) {
102127
$stockItem->unsIsChildItem();
103128
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/StockItemTest.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList;
99

1010
/**
11+
* Class StockItemTest
1112
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1213
*/
1314
class StockItemTest extends \PHPUnit\Framework\TestCase
@@ -28,10 +29,18 @@ class StockItemTest extends \PHPUnit\Framework\TestCase
2829
protected $typeConfig;
2930

3031
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject
32+
* @var \Magento\CatalogInventory\Api\StockStateInterface\PHPUnit_Framework_MockObject_MockObject
3233
*/
3334
protected $stockStateMock;
3435

36+
/**
37+
* @var \Magento\CatalogInventory\Model\StockStateProviderInterface| \PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $stockStateProviderMock;
40+
41+
/**
42+
* @inheritdoc
43+
*/
3544
protected function setUp()
3645
{
3746
$this->quoteItemQtyList = $this
@@ -48,17 +57,25 @@ protected function setUp()
4857
$this->stockStateMock = $this->getMockBuilder(\Magento\CatalogInventory\Api\StockStateInterface::class)
4958
->disableOriginalConstructor()
5059
->getMock();
60+
61+
$this->stockStateProviderMock = $this
62+
->getMockBuilder(\Magento\CatalogInventory\Model\StockStateProvider::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
5166
$this->model = $objectManagerHelper->getObject(
5267
\Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\StockItem::class,
5368
[
5469
'quoteItemQtyList' => $this->quoteItemQtyList,
5570
'typeConfig' => $this->typeConfig,
56-
'stockState' => $this->stockStateMock
71+
'stockState' => $this->stockStateMock,
72+
'stockStateProvider' => $this->stockStateProviderMock
5773
]
5874
);
5975
}
6076

6177
/**
78+
* Test initialize with Subitem
6279
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
6380
*/
6481
public function testInitializeWithSubitem()
@@ -141,6 +158,10 @@ public function testInitializeWithSubitem()
141158
->method('checkQuoteItemQty')
142159
->withAnyParameters()
143160
->will($this->returnValue($result));
161+
$this->stockStateProviderMock->expects($this->once())
162+
->method('checkQuoteItemQty')
163+
->withAnyParameters()
164+
->will($this->returnValue($result));
144165
$product->expects($this->once())
145166
->method('getCustomOption')
146167
->with('product_type')
@@ -177,13 +198,16 @@ public function testInitializeWithSubitem()
177198
$quoteItem->expects($this->once())->method('setUseOldQty')->with('item')->will($this->returnSelf());
178199
$result->expects($this->exactly(2))->method('getMessage')->will($this->returnValue('message'));
179200
$quoteItem->expects($this->once())->method('setMessage')->with('message')->will($this->returnSelf());
180-
$result->expects($this->exactly(2))->method('getItemBackorders')->will($this->returnValue('backorders'));
201+
$result->expects($this->exactly(3))->method('getItemBackorders')->will($this->returnValue('backorders'));
181202
$quoteItem->expects($this->once())->method('setBackorders')->with('backorders')->will($this->returnSelf());
182203
$quoteItem->expects($this->once())->method('setStockStateResult')->with($result)->will($this->returnSelf());
183204

184205
$this->model->initialize($stockItem, $quoteItem, $qty);
185206
}
186207

208+
/**
209+
* Test initialize without Subitem
210+
*/
187211
public function testInitializeWithoutSubitem()
188212
{
189213
$qty = 3;
@@ -234,6 +258,10 @@ public function testInitializeWithoutSubitem()
234258
->with($productId, 'quote_item_id', 'quote_id', $qty)
235259
->will($this->returnValue('summary_qty'));
236260
$this->stockStateMock->expects($this->once())
261+
->method('checkQuoteItemQty')
262+
->withAnyParameters()
263+
->will($this->returnValue($result));
264+
$this->stockStateProviderMock->expects($this->once())
237265
->method('checkQuoteItemQty')
238266
->withAnyParameters()
239267
->will($this->returnValue($result));
@@ -256,7 +284,7 @@ public function testInitializeWithoutSubitem()
256284
$result->expects($this->once())->method('getHasQtyOptionUpdate')->will($this->returnValue(false));
257285
$result->expects($this->once())->method('getItemUseOldQty')->will($this->returnValue(null));
258286
$result->expects($this->once())->method('getMessage')->will($this->returnValue(null));
259-
$result->expects($this->once())->method('getItemBackorders')->will($this->returnValue(null));
287+
$result->expects($this->exactly(2))->method('getItemBackorders')->will($this->returnValue(null));
260288

261289
$this->model->initialize($stockItem, $quoteItem, $qty);
262290
}

app/code/Magento/Checkout/view/frontend/templates/cart/item/price/sidebar.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<span class="price-label"><?= $block->escapeHtml(__('Price')) ?></span>
1414
<span class="price-wrapper">
1515
<?= $block->escapeHtml(
16-
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getCalculationPrice())
16+
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getCalculationPrice()),
17+
['span']
1718
) ?>
1819
</span>
1920
</div>

app/code/Magento/Checkout/view/frontend/templates/item/price/row.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ $_item = $block->getItem();
1313
<span class="price-excluding-tax" data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">
1414
<span class="cart-price">
1515
<?= $block->escapeHtml(
16-
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getRowTotal())
16+
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getRowTotal()),
17+
['span']
1718
) ?>
1819
</span>
1920
</span>

app/code/Magento/Checkout/view/frontend/templates/item/price/unit.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ $_item = $block->getItem();
1313
<span class="price-including-tax" data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">
1414
<span class="cart-price">
1515
<?= $block->escapeHtml(
16-
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getCalculationPrice())
16+
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getCalculationPrice()),
17+
['span']
1718
) ?>
1819
</span>
1920
</span>

app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_excl_tax.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
$_item = $block->getItem();
1212
?>
1313
<span class="cart-price">
14-
<?= $block->escapeHtml($this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getRowTotal())) ?>
14+
<?= $block->escapeHtml(
15+
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getRowTotal()),
16+
['span']
17+
) ?>
1518
</span>

app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_incl_tax.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ $_item = $block->getItem();
1212
?>
1313
<?php $_incl = $this->helper(Magento\Checkout\Helper\Data::class)->getSubtotalInclTax($_item); ?>
1414
<span class="cart-price">
15-
<?= $block->escapeHtml($this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_incl)) ?>
15+
<?= $block->escapeHtml(
16+
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_incl),
17+
['span']
18+
) ?>
1619
</span>

app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_excl_tax.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ $_item = $block->getItem();
1212
?>
1313
<span class="cart-price">
1414
<?= $block->escapeHtml(
15-
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getCalculationPrice())
15+
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($_item->getCalculationPrice()),
16+
['span']
1617
) ?>
1718
</span>

0 commit comments

Comments
 (0)