Skip to content

Commit e6146ec

Browse files
committed
Merge branch 'php8-develop' of github.com:magento-commerce/magento2ce into php8-develop-merge
2 parents c493b7b + a30a07e commit e6146ec

File tree

46 files changed

+4000
-1734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4000
-1734
lines changed

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,12 @@ protected function insertOptions()
573573

574574
$optionIds = $this->connection->fetchAssoc(
575575
$this->connection->select()->from(
576-
$this->_resource->getTableName('catalog_product_bundle_option'),
576+
['bo' => $this->_resource->getTableName('catalog_product_bundle_option')],
577577
['option_id', 'position', 'parent_id']
578+
)->joinLeft(
579+
['bov' => $this->_resource->getTableName('catalog_product_bundle_option_value')],
580+
'bo.option_id = bov.option_id',
581+
['title']
578582
)->where(
579583
'parent_id IN (?)',
580584
$productIds
@@ -600,8 +604,10 @@ protected function populateInsertOptionValues(array $optionIds): array
600604
foreach ($this->_cachedOptions as $entityId => $options) {
601605
foreach ($options as $key => $option) {
602606
foreach ($optionIds as $optionId => $assoc) {
603-
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index']
604-
&& $assoc['parent_id'] == $entityId) {
607+
if ($assoc['position'] == $this->_cachedOptions[$entityId][$key]['index'] &&
608+
$assoc['parent_id'] == $entityId &&
609+
(empty($assoc['title']) || $assoc['title'] == $this->_cachedOptions[$entityId][$key]['name'])
610+
) {
605611
$option['parent_id'] = $entityId;
606612
$optionValues[] = $this->populateOptionValueTemplate($option, $optionId);
607613
$this->_cachedOptions[$entityId][$key]['option_id'] = $optionId;

app/code/Magento/BundleImportExport/Test/Unit/Model/Import/Product/Type/BundleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ public function testSaveData($skus, $bunch, $allowImport)
289289
'type' => 'bundle',
290290
'value_id' => '6',
291291
'title' => 'Bundle6',
292+
'name' => 'Bundle6',
292293
'selections' => [
293294
[
294295
'name' => 'Bundlen6',

app/code/Magento/Catalog/view/adminhtml/web/catalog/product/composite/configure.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ define([
6464
click: function () {
6565
self.onConfirmBtn();
6666
}
67-
}]
67+
}],
68+
closed: function () {
69+
self.clean('window');
70+
},
6871
});
6972
});
7073
},
@@ -406,6 +409,7 @@ define([
406409
this.blockMsgError.innerHTML = response.message;
407410
this._showWindow();
408411

412+
jQuery(this.blockForm).trigger('processStop');
409413
return false;
410414
}
411415
}

app/code/Magento/CatalogGraphQl/Model/Category/DepthCalculator.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CatalogGraphQl\Model\Category;
99

10+
use GraphQL\Language\AST\Node;
1011
use GraphQL\Language\AST\FieldNode;
1112
use GraphQL\Language\AST\InlineFragmentNode;
1213
use GraphQL\Language\AST\NodeKind;
@@ -26,22 +27,35 @@ class DepthCalculator
2627
*/
2728
public function calculate(ResolveInfo $resolveInfo, FieldNode $fieldNode) : int
2829
{
29-
$selections = $fieldNode->selectionSet->selections ?? [];
30+
return $this->calculateRecursive($resolveInfo, $fieldNode);
31+
}
32+
33+
/**
34+
* Calculate recursive the total depth of a category tree inside a GraphQL request
35+
*
36+
* @param ResolveInfo $resolveInfo
37+
* @param Node $node
38+
* @return int
39+
*/
40+
private function calculateRecursive(ResolveInfo $resolveInfo, Node $node) : int
41+
{
42+
if ($node->kind === NodeKind::FRAGMENT_SPREAD) {
43+
$selections = isset($resolveInfo->fragments[$node->name->value]) ?
44+
$resolveInfo->fragments[$node->name->value]->selectionSet->selections : [];
45+
} else {
46+
$selections = $node->selectionSet->selections ?? [];
47+
}
3048
$depth = count($selections) ? 1 : 0;
3149
$childrenDepth = [0];
32-
foreach ($selections as $node) {
33-
if (isset($node->alias) && null !== $node->alias) {
50+
foreach ($selections as $subNode) {
51+
if (isset($subNode->alias) && null !== $subNode->alias) {
3452
continue;
3553
}
3654

37-
if ($node->kind === NodeKind::INLINE_FRAGMENT) {
38-
$childrenDepth[] = $this->addInlineFragmentDepth($resolveInfo, $node);
39-
} elseif ($node->kind === NodeKind::FRAGMENT_SPREAD && isset($resolveInfo->fragments[$node->name->value])) {
40-
foreach ($resolveInfo->fragments[$node->name->value]->selectionSet->selections as $spreadNode) {
41-
$childrenDepth[] = $this->calculate($resolveInfo, $spreadNode);
42-
}
55+
if ($subNode->kind === NodeKind::INLINE_FRAGMENT) {
56+
$childrenDepth[] = $this->addInlineFragmentDepth($resolveInfo, $subNode);
4357
} else {
44-
$childrenDepth[] = $this->calculate($resolveInfo, $node);
58+
$childrenDepth[] = $this->calculateRecursive($resolveInfo, $subNode);
4559
}
4660
}
4761

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function execute(\Iterator $iterator): array
6767
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
6868
}
6969
}
70-
return $tree;
70+
71+
return $this->sortTree($tree);
7172
}
7273

7374
/**
@@ -141,4 +142,24 @@ private function explodePathToArray(array $pathElements, int $index): array
141142
}
142143
return $tree;
143144
}
145+
146+
/**
147+
* Recursive method to sort tree
148+
*
149+
* @param array $tree
150+
* @return array
151+
*/
152+
private function sortTree(array $tree): array
153+
{
154+
foreach ($tree as &$node) {
155+
if ($node['children']) {
156+
uasort($node['children'], function ($element1, $element2) {
157+
return $element1['position'] > $element2['position'];
158+
});
159+
$node['children'] = $this->sortTree($node['children']);
160+
}
161+
}
162+
163+
return $tree;
164+
}
144165
}

app/code/Magento/CatalogInventory/Model/Stock/StockItemRepository.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Magento\Framework\Stdlib\DateTime\DateTime;
2626
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
2727
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
28+
use Psr\Log\LoggerInterface as PsrLogger;
2829

2930
/**
3031
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -98,8 +99,11 @@ class StockItemRepository implements StockItemRepositoryInterface
9899
protected $productCollectionFactory;
99100

100101
/**
101-
* Constructor
102-
*
102+
* @var PsrLogger
103+
*/
104+
private $psrLogger;
105+
106+
/**
103107
* @param StockConfigurationInterface $stockConfiguration
104108
* @param StockStateProviderInterface $stockStateProvider
105109
* @param StockItemResource $resource
@@ -111,7 +115,8 @@ class StockItemRepository implements StockItemRepositoryInterface
111115
* @param TimezoneInterface $localeDate
112116
* @param Processor $indexProcessor
113117
* @param DateTime $dateTime
114-
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory|null $collectionFactory
118+
* @param CollectionFactory|null $productCollectionFactory
119+
* @param PsrLogger|null $psrLogger
115120
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
116121
*/
117122
public function __construct(
@@ -126,7 +131,8 @@ public function __construct(
126131
TimezoneInterface $localeDate,
127132
Processor $indexProcessor,
128133
DateTime $dateTime,
129-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory = null
134+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory = null,
135+
PsrLogger $psrLogger = null
130136
) {
131137
$this->stockConfiguration = $stockConfiguration;
132138
$this->stockStateProvider = $stockStateProvider;
@@ -141,6 +147,8 @@ public function __construct(
141147
$this->dateTime = $dateTime;
142148
$this->productCollectionFactory = $productCollectionFactory ?: ObjectManager::getInstance()
143149
->get(CollectionFactory::class);
150+
$this->psrLogger = $psrLogger ?: ObjectManager::getInstance()
151+
->get(PsrLogger::class);
144152
}
145153

146154
/**
@@ -184,6 +192,7 @@ public function save(\Magento\CatalogInventory\Api\Data\StockItemInterface $stoc
184192

185193
$this->resource->save($stockItem);
186194
} catch (\Exception $exception) {
195+
$this->psrLogger->error($exception->getMessage());
187196
throw new CouldNotSaveException(__('The stock item was unable to be saved. Please try again.'), $exception);
188197
}
189198
return $stockItem;

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,47 +105,46 @@ public function verifyNotification(StockItemInterface $stockItem)
105105
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
106106
* @SuppressWarnings(PHPMD.NPathComplexity)
107107
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
108+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
108109
*/
109110
public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQty, $origQty = 0)
110111
{
111112
$result = $this->objectFactory->create();
112113
$result->setHasError(false);
113-
114114
$qty = $this->getNumber($qty);
115-
116-
/**
117-
* Check quantity type
118-
*/
119-
$result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal());
120-
if (!$stockItem->getIsQtyDecimal()) {
121-
$result->setHasQtyOptionUpdate(true);
122-
$qty = (int) $qty ?: 1;
123-
/**
124-
* Adding stock data to quote item
125-
*/
126-
$result->setItemQty($qty);
127-
$result->setOrigQty((int)$this->getNumber($origQty) ?: 1);
128-
}
115+
$quoteMessage = __('Please correct the quantity for some products.');
129116

130117
if ($stockItem->getMinSaleQty() && $qty < $stockItem->getMinSaleQty()) {
131118
$result->setHasError(true)
132119
->setMessage(__('The fewest you may purchase is %1.', $stockItem->getMinSaleQty() * 1))
133120
->setErrorCode('qty_min')
134-
->setQuoteMessage(__('Please correct the quantity for some products.'))
121+
->setQuoteMessage($quoteMessage)
135122
->setQuoteMessageIndex('qty');
136123
return $result;
137124
}
138125

139126
if ($stockItem->getMaxSaleQty() && $qty > $stockItem->getMaxSaleQty()) {
140127
$result->setHasError(true)
141-
->setMessage(__('The most you may purchase is %1.', $stockItem->getMaxSaleQty() * 1))
128+
->setMessage(__('The requested qty exceeds the maximum qty allowed in shopping cart'))
142129
->setErrorCode('qty_max')
143-
->setQuoteMessage(__('Please correct the quantity for some products.'))
130+
->setQuoteMessage($quoteMessage)
144131
->setQuoteMessageIndex('qty');
145132
return $result;
146133
}
147134

148135
$result->addData($this->checkQtyIncrements($stockItem, $qty)->getData());
136+
137+
$result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal());
138+
if (!$stockItem->getIsQtyDecimal() && (floor($qty) !== $qty)) {
139+
$result->setHasError(true)
140+
->setMessage(__('You cannot use decimal quantity for this product.'))
141+
->setErrorCode('qty_decimal')
142+
->setQuoteMessage($quoteMessage)
143+
->setQuoteMessageIndex('qty');
144+
145+
return $result;
146+
}
147+
149148
if ($result->getHasError()) {
150149
return $result;
151150
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockStateProviderTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use PHPUnit\Framework\TestCase;
2222

2323
/**
24+
* Unit tests for \Magento\CatalogInventory\Model\StockStateProvider class.
25+
*
2426
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2527
*/
2628
class StockStateProviderTest extends TestCase
@@ -115,6 +117,9 @@ class StockStateProviderTest extends TestCase
115117
'getProductName',
116118
];
117119

120+
/**
121+
* @inheritDoc
122+
*/
118123
protected function setUp(): void
119124
{
120125
$this->objectManagerHelper = new ObjectManagerHelper($this);
@@ -383,7 +388,7 @@ protected function getVariations()
383388
'suggestQty' => 51,
384389
'getStockQty' => $stockQty,
385390
'checkQtyIncrements' => false,
386-
'checkQuoteItemQty' => false,
391+
'checkQuoteItemQty' => true,
387392
],
388393
],
389394
[
@@ -411,7 +416,7 @@ protected function getVariations()
411416
'getStockQty' => $stockQty,
412417
'checkQtyIncrements' => false,
413418
'checkQuoteItemQty' => true,
414-
]
419+
],
415420
],
416421
[
417422
'values' => [
@@ -438,8 +443,8 @@ protected function getVariations()
438443
'getStockQty' => null,
439444
'checkQtyIncrements' => false,
440445
'checkQuoteItemQty' => true,
441-
]
442-
]
446+
],
447+
],
443448
];
444449
}
445450

app/code/Magento/CatalogInventory/i18n/en_US.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ Stock,Stock
7171
"Qty Uses Decimals","Qty Uses Decimals"
7272
"Allow Multiple Boxes for Shipping","Allow Multiple Boxes for Shipping"
7373
"Done","Done"
74+
"The requested qty exceeds the maximum qty allowed in shopping cart","The requested qty exceeds the maximum qty allowed in shopping cart"
75+
"You cannot use decimal quantity for this product.","You cannot use decimal quantity for this product."

0 commit comments

Comments
 (0)