Skip to content

Commit 6972e25

Browse files
authored
Merge pull request magento#5505 from magento-tsg-csl3/2.3-develop-pr40
[TSG-CSL3] For 2.3 (pr40)
2 parents e7df25c + 0408d09 commit 6972e25

File tree

12 files changed

+328
-45
lines changed

12 files changed

+328
-45
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public function initialize(
118118
$product->getStore()->getWebsiteId()
119119
);
120120

121+
if ($result->getHasError() === true && in_array($result->getErrorCode(), ['qty_available', 'out_stock'])) {
122+
$quoteItem->setHasError(true);
123+
}
124+
121125
/* We need to ensure that any possible plugin will not erase the data */
122126
$backOrdersQty = $this->stockStateProvider->checkQuoteItemQty($stockItem, $rowQty, $qtyForCheck, $qty)
123127
->getItemBackorders();

app/code/Magento/CatalogInventory/Model/StockStateProvider.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Framework\Math\Division as MathDivision;
1515

1616
/**
17-
* Interface StockStateProvider
17+
* Provider stocks state
1818
*/
1919
class StockStateProvider implements StockStateProviderInterface
2020
{
@@ -156,6 +156,7 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
156156

157157
if (!$stockItem->getIsInStock()) {
158158
$result->setHasError(true)
159+
->setErrorCode('out_stock')
159160
->setMessage(__('This product is out of stock.'))
160161
->setQuoteMessage(__('Some of the products are out of stock.'))
161162
->setQuoteMessageIndex('stock');
@@ -165,7 +166,11 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
165166

166167
if (!$this->checkQty($stockItem, $summaryQty) || !$this->checkQty($stockItem, $qty)) {
167168
$message = __('The requested qty is not available');
168-
$result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qty');
169+
$result->setHasError(true)
170+
->setErrorCode('qty_available')
171+
->setMessage($message)
172+
->setQuoteMessage($message)
173+
->setQuoteMessageIndex('qty');
169174
return $result;
170175
} else {
171176
if ($stockItem->getQty() - $summaryQty < 0) {

app/code/Magento/CatalogInventory/etc/adminhtml/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
</argument>
1515
</arguments>
1616
</type>
17-
<type name="Magento\CatalogInventory\Model\Spi\StockStateProviderInterface">
18-
<arguments>
19-
<argument name="qtyCheckApplicable" xsi:type="boolean">false</argument>
20-
</arguments>
21-
</type>
2217
<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
2318
<arguments>
2419
<argument name="addFieldStrategies" xsi:type="array">

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@
157157
<click selector="{{AdminInvoicePaymentShippingSection.shippingMethod}}" stepKey="chooseShippingMethod"/>
158158
<waitForPageLoad stepKey="waitForShippingMethodLoad"/>
159159
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder"/>
160-
<waitForPageLoad stepKey="waitForSuccess"/>
161-
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeSuccessMessage"/>
160+
<waitForPageLoad stepKey="waitForError"/>
161+
<!-- Check that error remains -->
162+
<actionGroup ref="AssertAdminItemOrderedErrorActionGroup" stepKey="assertProductErrorRemains">
163+
<argument name="productName" value="$createConfigChildProduct2.name$"/>
164+
<argument name="messageType" value="error"/>
165+
<argument name="message" value="This product is out of stock."/>
166+
</actionGroup>
162167
</test>
163168
</tests>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Test\Unit\ViewModel\Customer;
10+
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use PHPUnit\Framework\TestCase;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
use Magento\Customer\ViewModel\Customer\Website as CustomerWebsite;
15+
use Magento\Store\Model\System\Store as SystemStore;
16+
17+
/**
18+
* Test for customer's website view model
19+
*/
20+
class WebsiteTest extends TestCase
21+
{
22+
/** @var ObjectManagerHelper */
23+
private $objectManagerHelper;
24+
25+
/**
26+
* @var CustomerWebsite
27+
*/
28+
private $customerWebsite;
29+
30+
/**
31+
* @var SystemStore
32+
*/
33+
private $systemStore;
34+
35+
/**
36+
* @var ScopeConfigInterface
37+
*/
38+
private $scopeConfig;
39+
40+
protected function setUp()
41+
{
42+
$this->systemStore = $this->createMock(SystemStore::class);
43+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
44+
$this->objectManagerHelper = new ObjectManagerHelper($this);
45+
$this->customerWebsite = $this->objectManagerHelper->getObject(
46+
CustomerWebsite::class,
47+
[
48+
'systemStore' => $this->systemStore,
49+
'scopeConfig' => $this->scopeConfig
50+
]
51+
);
52+
}
53+
54+
/**
55+
* Test that method return correct array of options
56+
*
57+
* @param array $options
58+
* @dataProvider dataProviderOptionsArray
59+
* @return void
60+
*/
61+
public function testToOptionArray(array $options): void
62+
{
63+
$this->scopeConfig->method('getValue')
64+
->willReturn(1);
65+
66+
$this->systemStore->method('getWebsiteValuesForForm')
67+
->willReturn([
68+
[
69+
'label' => 'Main Website',
70+
'value' => '1',
71+
],
72+
[
73+
'label' => 'Second Website',
74+
'value' => '2',
75+
],
76+
]);
77+
78+
$this->assertEquals($options, $this->customerWebsite->toOptionArray());
79+
}
80+
81+
/**
82+
* Data provider for testToOptionArray test
83+
*
84+
* @return array
85+
*/
86+
public function dataProviderOptionsArray(): array
87+
{
88+
return [
89+
[
90+
'options' => [
91+
[
92+
'label' => 'Main Website',
93+
'value' => '1',
94+
'group_id' => '1',
95+
],
96+
[
97+
'label' => 'Second Website',
98+
'value' => '2',
99+
'group_id' => '1',
100+
],
101+
],
102+
],
103+
];
104+
}
105+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\ViewModel\Customer;
10+
11+
use Magento\Customer\Model\GroupManagement;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Data\OptionSourceInterface;
14+
use Magento\Store\Model\ScopeInterface;
15+
use Magento\Store\Model\System\Store as SystemStore;
16+
17+
/**
18+
* Customer's website view model
19+
*/
20+
class Website implements OptionSourceInterface
21+
{
22+
/**
23+
* @var SystemStore
24+
*/
25+
private $systemStore;
26+
27+
/**
28+
* @var ScopeConfigInterface
29+
*/
30+
private $scopeConfig;
31+
32+
/**
33+
* Store constructor.
34+
*
35+
* @param SystemStore $systemStore
36+
* @param ScopeConfigInterface $scopeConfig
37+
*/
38+
public function __construct(
39+
SystemStore $systemStore,
40+
ScopeConfigInterface $scopeConfig
41+
) {
42+
$this->systemStore = $systemStore;
43+
$this->scopeConfig = $scopeConfig;
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
public function toOptionArray(): array
50+
{
51+
return $this->getWebsiteOptions();
52+
}
53+
54+
/**
55+
* Adding group ID to options list
56+
*
57+
* @return array
58+
*/
59+
private function getWebsiteOptions(): array
60+
{
61+
$options = $this->systemStore->getWebsiteValuesForForm();
62+
foreach ($options as $key => $option) {
63+
$websiteId = $option['value'];
64+
$groupId = $this->scopeConfig->getValue(
65+
GroupManagement::XML_PATH_DEFAULT_ID,
66+
ScopeInterface::SCOPE_WEBSITE,
67+
$websiteId
68+
);
69+
$options[$key]['group_id'] = $groupId;
70+
}
71+
72+
return $options;
73+
}
74+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/form/element/website',
8+
'uiRegistry'
9+
], function (Website, registry) {
10+
'use strict';
11+
12+
return Website.extend({
13+
/**
14+
* On value change handler.
15+
*
16+
* @param {String} value
17+
*/
18+
onUpdate: function (value) {
19+
var groupIdFieldKey = 'group_id',
20+
groupId = registry.get('index = ' + groupIdFieldKey),
21+
option = this.getOption(value);
22+
23+
if (groupId) {
24+
groupId.value(option[groupIdFieldKey]);
25+
}
26+
27+
return this._super();
28+
}
29+
});
30+
});

app/code/Magento/Customer/view/base/ui_component/customer_form.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
<visible>false</visible>
118118
</settings>
119119
</field>
120-
<field name="website_id" component="Magento_Ui/js/form/element/website" formElement="select">
120+
<field name="website_id" component="Magento_Customer/js/form/element/website" formElement="select">
121121
<argument name="data" xsi:type="array">
122122
<item name="config" xsi:type="array">
123123
<item name="source" xsi:type="string">customer</item>
@@ -136,6 +136,13 @@
136136
<link name="customerId">${ $.provider }:data.customer.entity_id</link>
137137
</imports>
138138
</settings>
139+
<formElements>
140+
<select>
141+
<settings>
142+
<options class="Magento\Customer\ViewModel\Customer\Website"/>
143+
</settings>
144+
</select>
145+
</formElements>
139146
</field>
140147
<field name="prefix" formElement="input">
141148
<argument name="data" xsi:type="array">

0 commit comments

Comments
 (0)