Skip to content

Commit ff10216

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3-develop' into libs-upgrade
2 parents 623bc6a + 8088a14 commit ff10216

File tree

13 files changed

+462
-44
lines changed

13 files changed

+462
-44
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public function execute()
113113
$options
114114
);
115115
$valueOptions = (isset($options['value']) && is_array($options['value'])) ? $options['value'] : [];
116+
foreach (array_keys($valueOptions) as $key) {
117+
if (!empty($options['delete'][$key])) {
118+
unset($valueOptions[$key]);
119+
}
120+
}
116121
$this->checkEmptyOption($response, $valueOptions);
117122
}
118123

app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ protected function modifyPriceData($object, $data)
358358
{
359359
/** @var array $priceItem */
360360
foreach ($data as $key => $priceItem) {
361-
if (isset($priceItem['price']) && $priceItem['price'] > 0) {
361+
if (array_key_exists('price', $priceItem)) {
362362
$data[$key]['website_price'] = $priceItem['price'];
363363
}
364364
if ($priceItem['all_groups']) {

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ public function provideUniqueData()
249249
]
250250
], false
251251
],
252+
'empty and deleted' => [
253+
[
254+
'value' => [
255+
"option_0" => [1, 0],
256+
"option_1" => [2, 0],
257+
"option_2" => ["", ""],
258+
],
259+
'delete' => [
260+
"option_0" => "",
261+
"option_1" => "",
262+
"option_2" => "1",
263+
]
264+
], false
265+
],
252266
];
253267
}
254268

@@ -321,7 +335,34 @@ public function provideEmptyOption()
321335
(object) [
322336
'error' => false,
323337
]
324-
]
338+
],
339+
'empty admin scope options and deleted' => [
340+
[
341+
'value' => [
342+
"option_0" => [''],
343+
],
344+
'delete' => [
345+
'option_0' => '1',
346+
],
347+
],
348+
(object) [
349+
'error' => false,
350+
],
351+
],
352+
'empty admin scope options and not deleted' => [
353+
[
354+
'value' => [
355+
"option_0" => [''],
356+
],
357+
'delete' => [
358+
'option_0' => '0',
359+
],
360+
],
361+
(object) [
362+
'error' => true,
363+
'message' => 'The value of Admin scope can\'t be empty.',
364+
],
365+
],
325366
];
326367
}
327368
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Backend/TierpriceTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public function testSetPriceData()
141141
{
142142
$attributeName = 'tier_price';
143143
$tierPrices = [
144+
[
145+
'price' => 0,
146+
'all_groups' => 1,
147+
],
144148
[
145149
'price' => 10,
146150
'all_groups' => 1,
@@ -153,6 +157,12 @@ public function testSetPriceData()
153157
$productPrice = 20;
154158
$allCustomersGroupId = 32000;
155159
$finalTierPrices = [
160+
[
161+
'price' => 0,
162+
'all_groups' => 1,
163+
'website_price' => 0,
164+
'cust_group' => 32000,
165+
],
156166
[
157167
'price' => 10,
158168
'all_groups' => 1,
@@ -170,8 +180,11 @@ public function testSetPriceData()
170180
->disableOriginalConstructor()->getMock();
171181
$allCustomersGroup = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class)
172182
->disableOriginalConstructor()->getMock();
173-
$this->groupManagement->expects($this->once())->method('getAllCustomersGroup')->willReturn($allCustomersGroup);
174-
$allCustomersGroup->expects($this->once())->method('getId')->willReturn($allCustomersGroupId);
183+
$this->groupManagement
184+
->expects($this->exactly(2))
185+
->method('getAllCustomersGroup')
186+
->willReturn($allCustomersGroup);
187+
$allCustomersGroup->expects($this->exactly(2))->method('getId')->willReturn($allCustomersGroupId);
175188
$object->expects($this->once())->method('getPrice')->willReturn($productPrice);
176189
$this->attribute->expects($this->atLeastOnce())->method('isScopeGlobal')->willReturn(true);
177190
$object->expects($this->once())->method('getStoreId')->willReturn(null);

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ define([
7272
output = {},
7373
streetObject;
7474

75+
$.each(addrs, function (key) {
76+
if (addrs.hasOwnProperty(key) && !$.isFunction(addrs[key])) {
77+
output[self.toUnderscore(key)] = addrs[key];
78+
}
79+
});
80+
7581
if ($.isArray(addrs.street)) {
7682
streetObject = {};
7783
addrs.street.forEach(function (value, index) {
7884
streetObject[index] = value;
7985
});
80-
addrs.street = streetObject;
86+
output.street = streetObject;
8187
}
8288

83-
$.each(addrs, function (key) {
84-
if (addrs.hasOwnProperty(key) && !$.isFunction(addrs[key])) {
85-
output[self.toUnderscore(key)] = addrs[key];
86-
}
87-
});
88-
8989
return output;
9090
},
9191

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,24 @@ public function submit(QuoteEntity $quote, $orderData = [])
411411
*/
412412
protected function resolveItems(QuoteEntity $quote)
413413
{
414-
$quoteItems = [];
415-
foreach ($quote->getAllItems() as $quoteItem) {
416-
/** @var \Magento\Quote\Model\ResourceModel\Quote\Item $quoteItem */
417-
$quoteItems[$quoteItem->getId()] = $quoteItem;
418-
}
419414
$orderItems = [];
420-
foreach ($quoteItems as $quoteItem) {
421-
$parentItem = (isset($orderItems[$quoteItem->getParentItemId()])) ?
422-
$orderItems[$quoteItem->getParentItemId()] : null;
423-
$orderItems[$quoteItem->getId()] =
424-
$this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]);
415+
foreach ($quote->getAllItems() as $quoteItem) {
416+
$itemId = $quoteItem->getId();
417+
418+
if (!empty($orderItems[$itemId])) {
419+
continue;
420+
}
421+
422+
$parentItemId = $quoteItem->getParentItemId();
423+
/** @var \Magento\Quote\Model\ResourceModel\Quote\Item $parentItem */
424+
if ($parentItemId && !isset($orderItems[$parentItemId])) {
425+
$orderItems[$parentItemId] = $this->quoteItemToOrderItem->convert(
426+
$quoteItem->getParentItem(),
427+
['parent_item' => null]
428+
);
429+
}
430+
$parentItem = isset($orderItems[$parentItemId]) ? $orderItems[$parentItemId] : null;
431+
$orderItems[$itemId] = $this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]);
425432
}
426433
return array_values($orderItems);
427434
}

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,20 @@ protected function _afterLoad()
156156
{
157157
parent::_afterLoad();
158158

159-
/**
160-
* Assign parent items
161-
*/
159+
$productIds = [];
162160
foreach ($this as $item) {
161+
// Assign parent items
163162
if ($item->getParentItemId()) {
164163
$item->setParentItem($this->getItemById($item->getParentItemId()));
165164
}
166165
if ($this->_quote) {
167166
$item->setQuote($this->_quote);
168167
}
168+
// Collect quote products ids
169+
$productIds[] = (int)$item->getProductId();
169170
}
170-
171+
$this->_productIds = array_merge($this->_productIds, $productIds);
172+
$this->removeItemsWithAbsentProducts();
171173
/**
172174
* Assign options and products
173175
*/
@@ -205,12 +207,6 @@ protected function _assignOptions()
205207
protected function _assignProducts()
206208
{
207209
\Magento\Framework\Profiler::start('QUOTE:' . __METHOD__, ['group' => 'QUOTE', 'method' => __METHOD__]);
208-
$productIds = [];
209-
foreach ($this as $item) {
210-
$productIds[] = (int)$item->getProductId();
211-
}
212-
$this->_productIds = array_merge($this->_productIds, $productIds);
213-
214210
$productCollection = $this->_productCollectionFactory->create()->setStoreId(
215211
$this->getStoreId()
216212
)->addIdFilter(
@@ -305,4 +301,24 @@ private function addTierPriceData(ProductCollection $productCollection)
305301
$productCollection->addTierPriceDataByGroupId($this->_quote->getCustomerGroupId());
306302
}
307303
}
304+
305+
/**
306+
* Find and remove quote items with non existing products
307+
*
308+
* @return void
309+
*/
310+
private function removeItemsWithAbsentProducts()
311+
{
312+
$productCollection = $this->_productCollectionFactory->create()->addIdFilter($this->_productIds);
313+
$existingProductsIds = $productCollection->getAllIds();
314+
$absentProductsIds = array_diff($this->_productIds, $existingProductsIds);
315+
// Remove not existing products from items collection
316+
if (!empty($absentProductsIds)) {
317+
foreach ($absentProductsIds as $productIdToExclude) {
318+
/** @var \Magento\Quote\Model\Quote\Item $quoteItem */
319+
$quoteItem = $this->getItemByColumnValue('product_id', $productIdToExclude);
320+
$this->removeItemByKey($quoteItem->getId());
321+
}
322+
}
323+
}
308324
}

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Cms/Test/AdminSwitchWYSIWYGOptionsCest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<group value="skip"/>
2020
<!-- Skipped; see MAGETWO-89417 -->
2121
<testCaseId value="MAGETWO-82936"/>
22+
<!--Skip because of issue MAGETWO-89417-->
23+
<group value="skip"/>
2224
</annotations>
2325
<before>
2426
<actionGroup ref="LoginActionGroup" stepKey="loginGetFromGeneralFile"/>

0 commit comments

Comments
 (0)