Skip to content

Commit 0deac76

Browse files
committed
Merge remote-tracking branch 'remotes/mainline/2.4-develop' into MC-40624
2 parents a463f80 + 9798804 commit 0deac76

File tree

16 files changed

+277
-112
lines changed

16 files changed

+277
-112
lines changed

app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function execute()
3434
/** @var $export \Magento\ImportExport\Model\Export */
3535
$export = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
3636
$export->setData($data);
37-
$attrFilterBlock->prepareCollection(
38-
$export->filterAttributeCollection($export->getEntityAttributeCollection())
37+
$export->filterAttributeCollection(
38+
$attrFilterBlock->prepareCollection($export->getEntityAttributeCollection())
3939
);
4040
return $resultLayout;
4141
} catch (\Exception $e) {

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation;
99

1010
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Select;
1112
use Magento\Store\Model\Store;
1213

1314
/**
@@ -95,6 +96,8 @@ public function getOptions(array $optionIds, ?int $storeId, array $attributeCode
9596
)->where(
9697
'a.attribute_id = options.attribute_id AND option_value.store_id = ?',
9798
Store::DEFAULT_STORE_ID
99+
)->order(
100+
'options.sort_order ' . Select::SQL_ASC
98101
);
99102

100103
$select->where('option_value.option_id IN (?)', $optionIds);
@@ -112,11 +115,11 @@ public function getOptions(array $optionIds, ?int $storeId, array $attributeCode
112115
/**
113116
* Format result
114117
*
115-
* @param \Magento\Framework\DB\Select $select
118+
* @param Select $select
116119
* @return array
117120
* @throws \Zend_Db_Statement_Exception
118121
*/
119-
private function formatResult(\Magento\Framework\DB\Select $select): array
122+
private function formatResult(Select $select): array
120123
{
121124
$statement = $this->resourceConnection->getConnection()->query($select);
122125

@@ -131,7 +134,9 @@ private function formatResult(\Magento\Framework\DB\Select $select): array
131134
'options' => [],
132135
];
133136
}
134-
$result[$option['attribute_code']]['options'][$option['option_id']] = $option['option_label'];
137+
if (!empty($option['option_id'])) {
138+
$result[$option['attribute_code']]['options'][$option['option_id']] = $option['option_label'];
139+
}
135140
}
136141

137142
return $result;

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Attribute.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
8686
$attribute['attribute_code'] ?? $bucketName
8787
);
8888

89-
foreach ($bucket->getValues() as $value) {
90-
$metrics = $value->getMetrics();
89+
$options = $this->getSortedOptions($bucket,$attribute['options'] ?: []);
90+
foreach ($options as $option) {
9191
$result[$bucketName]['options'][] = $this->layerFormatter->buildItem(
92-
$attribute['options'][$metrics['value']] ?? $metrics['value'],
93-
$metrics['value'],
94-
$metrics['count']
92+
$option['label'],
93+
$option['value'],
94+
$option['count']
9595
);
9696
}
9797
}
@@ -161,4 +161,36 @@ function (AggregationValueInterface $value) {
161161
$attributes
162162
);
163163
}
164+
165+
/**
166+
* Get sorted options
167+
*
168+
* @param BucketInterface $bucket
169+
* @param array $optionLabels
170+
* @return array
171+
*/
172+
private function getSortedOptions(BucketInterface $bucket, array $optionLabels): array
173+
{
174+
/**
175+
* Option labels array has been sorted
176+
*/
177+
$options = $optionLabels;
178+
foreach ($bucket->getValues() as $value) {
179+
$metrics = $value->getMetrics();
180+
$optionValue = $metrics['value'];
181+
$optionLabel = $optionLabels[$optionValue] ?? $optionValue;
182+
$options[$optionValue] = $metrics + ['label' => $optionLabel];
183+
}
184+
185+
/**
186+
* Delete options without bucket values
187+
*/
188+
foreach ($options as $optionId => $option) {
189+
if (!is_array($options[$optionId])) {
190+
unset($options[$optionId]);
191+
}
192+
}
193+
194+
return array_values($options);
195+
}
164196
}

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77
namespace Magento\Checkout\Controller\Cart;
88

9+
use Magento\Checkout\Model\Cart\RequestQuantityProcessor;
910
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1011
use Magento\Catalog\Api\ProductRepositoryInterface;
1112
use Magento\Checkout\Model\Cart as CustomerCart;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\App\ResponseInterface;
1315
use Magento\Framework\Controller\ResultInterface;
1416
use Magento\Framework\Exception\NoSuchEntityException;
@@ -25,6 +27,11 @@ class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInt
2527
*/
2628
protected $productRepository;
2729

30+
/**
31+
* @var RequestQuantityProcessor
32+
*/
33+
private $quantityProcessor;
34+
2835
/**
2936
* @param \Magento\Framework\App\Action\Context $context
3037
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -33,6 +40,7 @@ class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInt
3340
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
3441
* @param CustomerCart $cart
3542
* @param ProductRepositoryInterface $productRepository
43+
* @param RequestQuantityProcessor|null $quantityProcessor
3644
* @codeCoverageIgnore
3745
*/
3846
public function __construct(
@@ -42,7 +50,8 @@ public function __construct(
4250
\Magento\Store\Model\StoreManagerInterface $storeManager,
4351
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
4452
CustomerCart $cart,
45-
ProductRepositoryInterface $productRepository
53+
ProductRepositoryInterface $productRepository,
54+
?RequestQuantityProcessor $quantityProcessor = null
4655
) {
4756
parent::__construct(
4857
$context,
@@ -53,6 +62,8 @@ public function __construct(
5362
$cart
5463
);
5564
$this->productRepository = $productRepository;
65+
$this->quantityProcessor = $quantityProcessor
66+
?? ObjectManager::getInstance()->get(RequestQuantityProcessor::class);
5667
}
5768

5869
/**
@@ -99,6 +110,7 @@ public function execute()
99110
\Magento\Framework\Locale\ResolverInterface::class
100111
)->getLocale()]
101112
);
113+
$params['qty'] = $this->quantityProcessor->prepareQuantity($params['qty']);
102114
$params['qty'] = $filter->filter($params['qty']);
103115
}
104116

app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
namespace Magento\Checkout\Controller\Sidebar;
77

8+
use Magento\Checkout\Model\Cart\RequestQuantityProcessor;
89
use Magento\Checkout\Model\Sidebar;
910
use Magento\Framework\App\Action\Action;
1011
use Magento\Framework\App\Action\Context;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\App\Response\Http;
1214
use Magento\Framework\Exception\LocalizedException;
1315
use Magento\Framework\Json\Helper\Data;
@@ -30,23 +32,32 @@ class UpdateItemQty extends Action
3032
*/
3133
protected $jsonHelper;
3234

35+
/**
36+
* @var RequestQuantityProcessor
37+
*/
38+
private $quantityProcessor;
39+
3340
/**
3441
* @param Context $context
3542
* @param Sidebar $sidebar
3643
* @param LoggerInterface $logger
3744
* @param Data $jsonHelper
45+
* @param RequestQuantityProcessor|null $quantityProcessor
3846
* @codeCoverageIgnore
3947
*/
4048
public function __construct(
4149
Context $context,
4250
Sidebar $sidebar,
4351
LoggerInterface $logger,
44-
Data $jsonHelper
52+
Data $jsonHelper,
53+
?RequestQuantityProcessor $quantityProcessor = null
4554
) {
4655
$this->sidebar = $sidebar;
4756
$this->logger = $logger;
4857
$this->jsonHelper = $jsonHelper;
4958
parent::__construct($context);
59+
$this->quantityProcessor = $quantityProcessor
60+
?? ObjectManager::getInstance()->get(RequestQuantityProcessor::class);
5061
}
5162

5263
/**
@@ -56,6 +67,7 @@ public function execute()
5667
{
5768
$itemId = (int)$this->getRequest()->getParam('item_id');
5869
$itemQty = $this->getRequest()->getParam('item_qty') * 1;
70+
$itemQty = $this->quantityProcessor->prepareQuantity($itemQty);
5971

6072
try {
6173
$this->sidebar->checkQuoteItem($itemId);

app/code/Magento/Checkout/Model/Cart/RequestQuantityProcessor.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,39 @@ public function process(array $cartData): array
4141

4242
foreach ($cartData as $index => $data) {
4343
if (isset($data['qty'])) {
44+
$data['qty'] = $this->prepareQuantity($data['qty']);
4445
$data['qty'] = is_string($data['qty']) ? trim($data['qty']) : $data['qty'];
4546
$cartData[$index]['qty'] = $filter->filter($data['qty']);
4647
}
4748
}
4849

4950
return $cartData;
5051
}
52+
53+
/**
54+
* Prepare quantity with taking into account decimal separator by locale
55+
*
56+
* @param int|float|string|array $quantity
57+
* @return int|float|string|array
58+
* @throws \Zend_Locale_Exception
59+
*/
60+
public function prepareQuantity($quantity)
61+
{
62+
$formatter = new \NumberFormatter($this->localeResolver->getLocale(), \NumberFormatter::CURRENCY);
63+
$decimalSymbol = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
64+
65+
if (is_array($quantity)) {
66+
foreach ($quantity as $key => $qty) {
67+
if (strpos((string)$qty, '.') !== false && $decimalSymbol !== '.') {
68+
$quantity[$key] = str_replace('.', $decimalSymbol, $qty);
69+
}
70+
}
71+
} else {
72+
if (strpos((string)$quantity, '.') !== false && $decimalSymbol !== '.') {
73+
$quantity = str_replace('.', $decimalSymbol, (string)$quantity);
74+
}
75+
}
76+
77+
return $quantity;
78+
}
5179
}

app/code/Magento/Checkout/Test/Unit/Controller/Sidebar/UpdateItemQtyTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Checkout\Test\Unit\Controller\Sidebar;
99

1010
use Magento\Checkout\Controller\Sidebar\UpdateItemQty;
11+
use Magento\Checkout\Model\Cart\RequestQuantityProcessor;
1112
use Magento\Checkout\Model\Sidebar;
1213
use Magento\Framework\App\RequestInterface;
1314
use Magento\Framework\App\ResponseInterface;
@@ -41,11 +42,15 @@ class UpdateItemQtyTest extends TestCase
4142
/** @var ResponseInterface|MockObject */
4243
protected $responseMock;
4344

45+
/** @var RequestQuantityProcessor|MockObject */
46+
private $quantityProcessor;
47+
4448
protected function setUp(): void
4549
{
4650
$this->sidebarMock = $this->createMock(Sidebar::class);
4751
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
4852
$this->jsonHelperMock = $this->createMock(Data::class);
53+
$this->quantityProcessor = $this->createMock(RequestQuantityProcessor::class);
4954
$this->requestMock = $this->getMockForAbstractClass(RequestInterface::class);
5055
$this->responseMock = $this->getMockForAbstractClass(
5156
ResponseInterface::class,
@@ -64,6 +69,7 @@ protected function setUp(): void
6469
'sidebar' => $this->sidebarMock,
6570
'logger' => $this->loggerMock,
6671
'jsonHelper' => $this->jsonHelperMock,
72+
'quantityProcessor' => $this->quantityProcessor,
6773
'request' => $this->requestMock,
6874
'response' => $this->responseMock,
6975
]
@@ -115,6 +121,11 @@ public function testExecute()
115121
)
116122
->willReturn('json encoded');
117123

124+
$this->quantityProcessor->expects($this->once())
125+
->method('prepareQuantity')
126+
->with(2)
127+
->willReturn(2);
128+
118129
$this->responseMock->expects($this->once())
119130
->method('representJson')
120131
->with('json encoded')

app/code/Magento/Checkout/Test/Unit/Model/Cart/RequestQuantityProcessorTest.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ protected function setUp(): void
2828
{
2929
$this->localeResolver = $this->getMockBuilder(ResolverInterface::class)
3030
->getMockForAbstractClass();
31-
32-
$this->localeResolver->method('getLocale')
33-
->willReturn('en_US');
34-
35-
$this->requestProcessor = new RequestQuantityProcessor(
36-
$this->localeResolver
37-
);
3831
}
3932

4033
/**
4134
* Test of cart data processing.
4235
*
4336
* @param array $cartData
37+
* @param string $locale
4438
* @param array $expected
4539
* @dataProvider cartDataProvider
4640
*/
47-
public function testProcess($cartData, $expected)
41+
public function testProcess(array $cartData, string $locale, array $expected): void
4842
{
43+
$this->localeResolver->method('getLocale')
44+
->willReturn($locale);
45+
$this->requestProcessor = new RequestQuantityProcessor(
46+
$this->localeResolver
47+
);
48+
4949
$this->assertEquals($this->requestProcessor->process($cartData), $expected);
5050
}
5151

@@ -57,13 +57,15 @@ public function cartDataProvider()
5757
return [
5858
'empty_array' => [
5959
'cartData' => [],
60+
'locale' => 'en_US',
6061
'expected' => [],
6162
],
6263
'strings_array' => [
6364
'cartData' => [
6465
['qty' => ' 10 '],
6566
['qty' => ' 0.5 ']
6667
],
68+
'locale' => 'en_US',
6769
'expected' => [
6870
['qty' => 10],
6971
['qty' => 0.5]
@@ -74,6 +76,7 @@ public function cartDataProvider()
7476
['qty' => 1],
7577
['qty' => 0.002]
7678
],
79+
'locale' => 'en_US',
7780
'expected' => [
7881
['qty' => 1],
7982
['qty' => 0.002]
@@ -83,10 +86,22 @@ public function cartDataProvider()
8386
'cartData' => [
8487
['qty' => [1, 2 ,3]],
8588
],
89+
'locale' => 'en_US',
8690
'expected' => [
8791
['qty' => [1, 2, 3]],
8892
],
8993
],
94+
'strings_array_spain_locale' => [
95+
'cartData' => [
96+
['qty' => ' 10 '],
97+
['qty' => ' 0.5 ']
98+
],
99+
'locale' => 'es_CL',
100+
'expected' => [
101+
['qty' => 10],
102+
['qty' => 0.5]
103+
],
104+
],
90105
];
91106
}
92107
}

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ define([
238238

239239
// Add defaultvalue attribute to state/province select element
240240
regionList.attr('defaultvalue', this.options.defaultRegion);
241+
this.options.form.find('[type="submit"]').removeAttr('disabled').show();
241242
},
242243

243244
/**

0 commit comments

Comments
 (0)