Skip to content

Commit 960a51f

Browse files
authored
Merge pull request #6490 from magento-tsg-csl3/2.4-develop-pr48
[TSG-CSL3] For 2.4 (pr48)
2 parents 1c3837c + 07313e6 commit 960a51f

File tree

13 files changed

+671
-199
lines changed

13 files changed

+671
-199
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/grid/extended.phtml

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* getPagerVisibility()
1515
* getVarNamePage()
1616
*/
17-
$numColumns = count($block->getColumns());
1817

1918
/**
2019
* @var \Magento\Backend\Block\Widget\Grid\Extended $block
2120
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
2221
*/
22+
$numColumns = count($block->getColumns());
23+
2324
?>
2425
<?php if ($block->getCollection()): ?>
2526
<?php if ($block->canDisplayContainer()): ?>
@@ -285,7 +286,9 @@ $numColumns = count($block->getColumns());
285286
</table>
286287

287288
</div>
289+
<?php if ($block->canDisplayContainer()): ?>
288290
</div>
291+
<?php endif; ?>
289292
<?php
290293
/** @var \Magento\Framework\Json\Helper\Data $jsonHelper */
291294
$jsonHelper = $block->getData('jsonHelper');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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\Bundle\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
9+
10+
use Magento\Bundle\Model\Product\Attribute\Source\Shipment\Type as ShipmentType;
11+
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePanel;
12+
use Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\BundlePrice;
13+
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Catalog\Model\Locator\LocatorInterface;
15+
use Magento\Framework\Stdlib\ArrayManager;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use Magento\Framework\UrlInterface;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test for bundle panel
23+
*/
24+
class BundlePanelTest extends TestCase
25+
{
26+
/**
27+
* @var UrlInterface|MockObject
28+
*/
29+
private $urlBuilder;
30+
31+
/**
32+
* @var ShipmentType|MockObject
33+
*/
34+
private $shipmentType;
35+
36+
/**
37+
* @var LocatorInterface|MockObject
38+
*/
39+
private $locatorMock;
40+
41+
/**
42+
* @var ProductInterface|MockObject
43+
*/
44+
private $productMock;
45+
46+
/**
47+
* @var ArrayManager|MockObject
48+
*/
49+
private $arrayManagerMock;
50+
51+
/**
52+
* @var BundlePanel
53+
*/
54+
private $bundlePanelModel;
55+
56+
/**
57+
* @return void
58+
*/
59+
protected function setUp(): void
60+
{
61+
$this->objectManager = new ObjectManager($this);
62+
$this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$this->arrayManagerMock->expects($this->any())
66+
->method('get')
67+
->willReturn([]);
68+
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
69+
->getMockForAbstractClass();
70+
$this->shipmentType = $this->getMockBuilder(ShipmentType::class)
71+
->getMockForAbstractClass();
72+
$this->productMock = $this->getMockBuilder(ProductInterface::class)
73+
->addMethods(['getStoreId'])
74+
->getMockForAbstractClass();
75+
$this->productMock->method('getId')
76+
->willReturn(true);
77+
$this->productMock->method('getStoreId')
78+
->willReturn(0);
79+
$this->locatorMock = $this->getMockBuilder(LocatorInterface::class)
80+
->onlyMethods(['getProduct'])
81+
->getMockForAbstractClass();
82+
$this->locatorMock->method('getProduct')
83+
->willReturn($this->productMock);
84+
85+
$this->bundlePanelModel = $this->objectManager->getObject(
86+
BundlePanel::class,
87+
[
88+
'locator' => $this->locatorMock,
89+
'urlBuilder' => $this->urlBuilder,
90+
'shipmentType' => $this->shipmentType,
91+
'arrayManager' => $this->arrayManagerMock,
92+
]
93+
);
94+
}
95+
96+
/**
97+
* Test for modify meta
98+
*
99+
* @param string $shipmentTypePath
100+
* @param string $dataScope
101+
*
102+
* @return void
103+
* @dataProvider getDataModifyMeta
104+
*/
105+
public function testModifyMeta(string $shipmentTypePath, string $dataScope): void
106+
{
107+
$sourceMeta = [
108+
'bundle-items' => [
109+
'children' => [
110+
BundlePrice::CODE_PRICE_TYPE => []
111+
]
112+
]
113+
];
114+
$this->arrayManagerMock->method('findPath')
115+
->willReturnMap(
116+
[
117+
[
118+
BundlePanel::CODE_SHIPMENT_TYPE,
119+
[],
120+
null,
121+
'children',
122+
ArrayManager::DEFAULT_PATH_DELIMITER,
123+
$shipmentTypePath
124+
],
125+
]
126+
);
127+
$this->arrayManagerMock->method('merge')
128+
->willReturn([]);
129+
$this->arrayManagerMock->method('remove')
130+
->willReturn([]);
131+
$this->arrayManagerMock->method('set')
132+
->willReturn([]);
133+
$this->arrayManagerMock->expects($this->at(12))
134+
->method('merge')
135+
->with(
136+
$shipmentTypePath . BundlePanel::META_CONFIG_PATH,
137+
[],
138+
[
139+
'dataScope' => $dataScope,
140+
'validation' => [
141+
'required-entry' => false
142+
]
143+
]
144+
);
145+
$this->bundlePanelModel->modifyMeta($sourceMeta);
146+
}
147+
148+
/**
149+
* Data provider for modify meta test
150+
*
151+
* @return string[][]
152+
*/
153+
public function getDataModifyMeta(): array
154+
{
155+
return [
156+
[
157+
'bundle-items/children',
158+
'data.product.shipment_type'
159+
],
160+
[
161+
'someAttrGroup/children',
162+
'shipment_type'
163+
],
164+
];
165+
}
166+
}

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,19 @@ public function modifyData(array $data)
252252
*/
253253
private function modifyShipmentType(array $meta)
254254
{
255+
$actualPath = $this->arrayManager->findPath(
256+
static::CODE_SHIPMENT_TYPE,
257+
$meta,
258+
null,
259+
'children'
260+
);
261+
255262
$meta = $this->arrayManager->merge(
256-
$this->arrayManager->findPath(
257-
static::CODE_SHIPMENT_TYPE,
258-
$meta,
259-
null,
260-
'children'
261-
) . static::META_CONFIG_PATH,
263+
$actualPath . static::META_CONFIG_PATH,
262264
$meta,
263265
[
264-
'dataScope' => 'data.product.shipment_type',
266+
'dataScope' => stripos($actualPath, self::CODE_BUNDLE_DATA) === 0
267+
? 'data.product.shipment_type' : 'shipment_type',
265268
'validation' => [
266269
'required-entry' => false
267270
]

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,17 @@ public function validate(Observer $observer)
157157
if ($stockStatus->getStockStatus() === Stock::STOCK_OUT_OF_STOCK
158158
|| $parentStockStatus && $parentStockStatus->getStockStatus() == Stock::STOCK_OUT_OF_STOCK
159159
) {
160-
$quoteItem->addErrorInfo(
161-
'cataloginventory',
162-
Data::ERROR_QTY,
163-
__('This product is out of stock.')
164-
);
160+
$hasError = $quoteItem->getStockStateResult()
161+
? $quoteItem->getStockStateResult()->getHasError() : false;
162+
if (!$hasError) {
163+
$quoteItem->addErrorInfo(
164+
'cataloginventory',
165+
Data::ERROR_QTY,
166+
__('This product is out of stock.')
167+
);
168+
} else {
169+
$quoteItem->addErrorInfo(null, Data::ERROR_QTY);
170+
}
165171
$quoteItem->getQuote()->addErrorInfo(
166172
'stock',
167173
'cataloginventory',

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

+48-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function setUp(): void
153153
->getMock();
154154
$this->storeMock = $this->createMock(Store::class);
155155
$this->quoteItemMock = $this->getMockBuilder(Item::class)
156-
->addMethods(['getProductId', 'getHasError'])
156+
->addMethods(['getProductId', 'getHasError', 'getStockStateResult'])
157157
->onlyMethods(
158158
[
159159
'getQuote',
@@ -460,6 +460,53 @@ public function testException()
460460
$this->quantityValidator->validate($this->observerMock);
461461
}
462462

463+
/**
464+
* This tests the scenario when the error is in the quote item already
465+
*
466+
* @return void
467+
*/
468+
public function testValidateOutStockWithAlreadyErrorInQuoteItem(): void
469+
{
470+
$this->createInitialStub(1);
471+
$resultMock = $this->getMockBuilder(DataObject::class)
472+
->addMethods(['checkQtyIncrements', 'getMessage', 'getQuoteMessage', 'getHasError'])
473+
->getMock();
474+
$resultMock->method('getHasError')
475+
->willReturn(true);
476+
$this->stockRegistryMock->method('getStockItem')
477+
->willReturn($this->stockItemMock);
478+
$this->stockRegistryMock->expects($this->at(1))
479+
->method('getStockStatus')
480+
->willReturn($this->stockStatusMock);
481+
$this->quoteItemMock->method('getParentItem')
482+
->willReturn($this->parentItemMock);
483+
$this->quoteItemMock->method('getStockStateResult')
484+
->willReturn($resultMock);
485+
$this->stockRegistryMock->expects($this->at(2))
486+
->method('getStockStatus')
487+
->willReturn($this->parentStockItemMock);
488+
$this->parentStockItemMock->method('getStockStatus')
489+
->willReturn(0);
490+
$this->stockStatusMock->expects($this->atLeastOnce())
491+
->method('getStockStatus')
492+
->willReturn(1);
493+
$this->quoteItemMock->expects($this->once())
494+
->method('addErrorInfo')
495+
->with(
496+
null,
497+
Data::ERROR_QTY,
498+
);
499+
$this->quoteMock->expects($this->once())
500+
->method('addErrorInfo')
501+
->with(
502+
'stock',
503+
'cataloginventory',
504+
Data::ERROR_QTY,
505+
__('Some of the products are out of stock.')
506+
);
507+
$this->quantityValidator->validate($this->observerMock);
508+
}
509+
463510
/**
464511
* @param $qty
465512
* @param $hasError

app/code/Magento/ConfigurableProduct/Test/Mftf/Test/NoOptionAvailableToConfigureDisabledProductTest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<actionGroup ref="AdminSetStockStatusActionGroup" stepKey="outOfStockStatus">
126126
<argument name="stockStatus" value="Out of Stock"/>
127127
</actionGroup>
128-
128+
129129
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveSecondProductForm"/>
130130
<!-- Go to created customer page -->
131131
<comment userInput="Go to created customer page" stepKey="goToCreatedCustomerPage"/>
@@ -158,7 +158,7 @@
158158
<waitForPageLoad stepKey="waitForPageLoad"/>
159159
<click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickToAddProductToOrder"/>
160160
<waitForPageLoad stepKey="waitForNewOrderPageLoad"/>
161-
<see userInput="This product is out of stock." stepKey="seeTheErrorMessageDisplayed"/>
161+
<see userInput="There are no source items with the in stock status" stepKey="seeTheErrorMessageDisplayed"/>
162162

163163
<actionGroup ref="NavigateToNewOrderPageExistingCustomerActionGroup" stepKey="createNewOrderThirdTime">
164164
<argument name="customer" value="$createCustomer$"/>

0 commit comments

Comments
 (0)