Skip to content

Commit ed9fecc

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.3-develop
Accepted Community Pull Requests: - #24476: Fix lib-button-as-link not using color argument (by @Leland) - #24478: add validation greater than zero number for MySQL Message Queue Cleanup (by @ravi-chandra3197) - #24467: Fix issue with "Apply Discount Code" input hidden, when code is applied (by @iGerchak) - #24380: fix issue #24366 - Updating cart quantity (by @GDauer) - #24457: Fix for bug: If multiple children had the same sort order only one of� (by @oskarolaussen) - #24077: Added changes to make product price level field disabled when alert are enabled (by @arushibansal013) - #24274: Resolve error when call getRssUrl() method (by @edenduong) - #21424: Magento2 attribute option does not validate for existing records before insert 16852 (by @novikor) Fixed GitHub Issues: - #24366: Updating cart with quantity that results in error, causes wrong error message to be displayed when backorders involved. (reported by @gwharton) has been fixed in #24380 by @GDauer in 2.3-develop branch Related commits: 1. 48ae1fc 2. cc78567 3. 0a67f76 4. d2a09d3 5. 720799b 6. 57a3546 7. 650c215 - #23890: Price attribute is enabled for dynamic price type on bundle product edit page in admin (reported by @katesuykovskaya) has been fixed in #24077 by @arushibansal013 in 2.3-develop branch Related commits: 1. 7170102 2. 87732f3 3. 375efd1 4. 035800e 5. 1951578 6. 09cd623 - #16852: Magento2 Attribute option does not validate for existing records before insert (reported by @zeeshan2523806) has been fixed in #21424 by @novikor in 2.3-develop branch Related commits: 1. e79e57b 2. a8ec393
2 parents 90b9c43 + 3f33e57 commit ed9fecc

File tree

15 files changed

+849
-102
lines changed

15 files changed

+849
-102
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __construct(
3939
$this->locator = $locator;
4040
$this->arrayManager = $arrayManager;
4141
}
42-
42+
4343
/**
44-
* {@inheritdoc}
44+
* @inheritdoc
4545
*/
4646
public function modifyMeta(array $meta)
4747
{
@@ -64,7 +64,7 @@ public function modifyMeta(array $meta)
6464
$this->arrayManager->findPath(
6565
ProductAttributeInterface::CODE_PRICE,
6666
$meta,
67-
null,
67+
self::DEFAULT_GENERAL_PANEL . '/children',
6868
'children'
6969
) . static::META_CONFIG_PATH,
7070
$meta,
@@ -94,7 +94,7 @@ public function modifyMeta(array $meta)
9494
}
9595

9696
/**
97-
* {@inheritdoc}
97+
* @inheritdoc
9898
*/
9999
public function modifyData(array $data)
100100
{

app/code/Magento/Catalog/Block/Product/View/Details.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public function getGroupSortedChildNames(string $groupName, string $callback): a
3737
$alias = $layout->getElementAlias($childName);
3838
$sortOrder = (int)$this->getChildData($alias, 'sort_order') ?? 0;
3939

40-
$childNamesSortOrder[$sortOrder] = $childName;
40+
$childNamesSortOrder[$childName] = $sortOrder;
4141
}
4242

43-
ksort($childNamesSortOrder, SORT_NUMERIC);
43+
asort($childNamesSortOrder, SORT_NUMERIC);
4444

45-
return $childNamesSortOrder;
45+
return array_keys($childNamesSortOrder);
4646
}
4747
}

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

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88
namespace Magento\Checkout\Controller\Cart;
99

1010
use Magento\Checkout\Model\Cart\RequestQuantityProcessor;
11+
use Magento\Checkout\Model\Session as CheckoutSession;
12+
use Magento\Framework\App\Action\Action;
1113
use Magento\Framework\App\Action\Context;
14+
use Magento\Framework\App\Action\HttpPostActionInterface;
15+
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
1216
use Magento\Framework\Exception\LocalizedException;
13-
use Magento\Checkout\Model\Session as CheckoutSession;
17+
use Magento\Framework\Exception\NotFoundException;
1418
use Magento\Framework\Serialize\Serializer\Json;
15-
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
1619
use Magento\Quote\Model\Quote\Item;
1720
use Psr\Log\LoggerInterface;
1821

19-
class UpdateItemQty extends \Magento\Framework\App\Action\Action
22+
/**
23+
* UpdateItemQty ajax request
24+
*
25+
* @package Magento\Checkout\Controller\Cart
26+
*/
27+
class UpdateItemQty extends Action implements HttpPostActionInterface
2028
{
29+
2130
/**
2231
* @var RequestQuantityProcessor
2332
*/
@@ -44,13 +53,16 @@ class UpdateItemQty extends \Magento\Framework\App\Action\Action
4453
private $logger;
4554

4655
/**
47-
* @param Context $context,
56+
* UpdateItemQty constructor
57+
*
58+
* @param Context $context
4859
* @param RequestQuantityProcessor $quantityProcessor
4960
* @param FormKeyValidator $formKeyValidator
5061
* @param CheckoutSession $checkoutSession
5162
* @param Json $json
5263
* @param LoggerInterface $logger
5364
*/
65+
5466
public function __construct(
5567
Context $context,
5668
RequestQuantityProcessor $quantityProcessor,
@@ -68,30 +80,26 @@ public function __construct(
6880
}
6981

7082
/**
83+
* Controller execute method
84+
*
7185
* @return void
7286
*/
7387
public function execute()
7488
{
7589
try {
76-
if (!$this->formKeyValidator->validate($this->getRequest())) {
77-
throw new LocalizedException(
78-
__('Something went wrong while saving the page. Please refresh the page and try again.')
79-
);
80-
}
90+
$this->validateRequest();
91+
$this->validateFormKey();
8192

8293
$cartData = $this->getRequest()->getParam('cart');
83-
if (!is_array($cartData)) {
84-
throw new LocalizedException(
85-
__('Something went wrong while saving the page. Please refresh the page and try again.')
86-
);
87-
}
94+
95+
$this->validateCartData($cartData);
8896

8997
$cartData = $this->quantityProcessor->process($cartData);
9098
$quote = $this->checkoutSession->getQuote();
9199

92100
foreach ($cartData as $itemId => $itemInfo) {
93101
$item = $quote->getItemById($itemId);
94-
$qty = isset($itemInfo['qty']) ? (double)$itemInfo['qty'] : 0;
102+
$qty = isset($itemInfo['qty']) ? (double) $itemInfo['qty'] : 0;
95103
if ($item) {
96104
$this->updateItemQuantity($item, $qty);
97105
}
@@ -111,11 +119,13 @@ public function execute()
111119
*
112120
* @param Item $item
113121
* @param float $qty
122+
* @return void
114123
* @throws LocalizedException
115124
*/
116125
private function updateItemQuantity(Item $item, float $qty)
117126
{
118127
if ($qty > 0) {
128+
$item->clearMessage();
119129
$item->setQty($qty);
120130

121131
if ($item->getHasError()) {
@@ -145,9 +155,7 @@ private function jsonResponse(string $error = '')
145155
*/
146156
private function getResponseData(string $error = ''): array
147157
{
148-
$response = [
149-
'success' => true,
150-
];
158+
$response = ['success' => true];
151159

152160
if (!empty($error)) {
153161
$response = [
@@ -158,4 +166,48 @@ private function getResponseData(string $error = ''): array
158166

159167
return $response;
160168
}
169+
170+
/**
171+
* Validates the Request HTTP method
172+
*
173+
* @return void
174+
* @throws NotFoundException
175+
*/
176+
private function validateRequest()
177+
{
178+
if ($this->getRequest()->isPost() === false) {
179+
throw new NotFoundException(__('Page Not Found'));
180+
}
181+
}
182+
183+
/**
184+
* Validates form key
185+
*
186+
* @return void
187+
* @throws LocalizedException
188+
*/
189+
private function validateFormKey()
190+
{
191+
if (!$this->formKeyValidator->validate($this->getRequest())) {
192+
throw new LocalizedException(
193+
__('Something went wrong while saving the page. Please refresh the page and try again.')
194+
);
195+
}
196+
}
197+
198+
/**
199+
* Validates cart data
200+
*
201+
* @param array|null $cartData
202+
* @return void
203+
* @throws LocalizedException
204+
*/
205+
private function validateCartData($cartData = null)
206+
{
207+
if (!is_array($cartData)) {
208+
throw new LocalizedException(
209+
__('Something went wrong while saving the page. Please refresh the page and try again.')
210+
);
211+
}
212+
}
161213
}

app/code/Magento/Checkout/view/frontend/templates/cart/coupon.phtml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
/**
88
* @var \Magento\Framework\View\Element\AbstractBlock $block
99
*/
10+
11+
// We should use strlen function because coupon code could be "0", converted to bool will lead to false
12+
$hasCouponCode = (bool) strlen($block->getCouponCode());
1013
?>
1114
<div class="block discount"
1215
id="block-discount"
13-
data-mage-init='{"collapsible":{"openedState": "active", "saveState": false}}'
16+
data-mage-init='{"collapsible":{"active": <?= $hasCouponCode ? 'true' : 'false' ?>, "openedState": "active", "saveState": false}}'
1417
>
1518
<div class="title" data-role="title">
1619
<strong id="block-discount-heading" role="heading" aria-level="2"><?= $block->escapeHtml(__('Apply Discount Code')) ?></strong>
@@ -23,7 +26,7 @@
2326
"removeCouponSelector": "#remove-coupon",
2427
"applyButton": "button.action.apply",
2528
"cancelButton": "button.action.cancel"}}'>
26-
<div class="fieldset coupon<?= strlen($block->getCouponCode()) ? ' applied' : '' ?>">
29+
<div class="fieldset coupon<?= $hasCouponCode ? ' applied' : '' ?>">
2730
<input type="hidden" name="remove" id="remove-coupon" value="0" />
2831
<div class="field">
2932
<label for="coupon_code" class="label"><span><?= $block->escapeHtml(__('Enter discount code')) ?></span></label>
@@ -34,14 +37,14 @@
3437
name="coupon_code"
3538
value="<?= $block->escapeHtmlAttr($block->getCouponCode()) ?>"
3639
placeholder="<?= $block->escapeHtmlAttr(__('Enter discount code')) ?>"
37-
<?php if (strlen($block->getCouponCode())) :?>
40+
<?php if ($hasCouponCode) :?>
3841
disabled="disabled"
3942
<?php endif; ?>
4043
/>
4144
</div>
4245
</div>
4346
<div class="actions-toolbar">
44-
<?php if (!strlen($block->getCouponCode())) :?>
47+
<?php if (!$hasCouponCode) :?>
4548
<div class="primary">
4649
<button class="action apply primary" type="button" value="<?= $block->escapeHtmlAttr(__('Apply Discount')) ?>">
4750
<span><?= $block->escapeHtml(__('Apply Discount')) ?></span>
@@ -54,7 +57,7 @@
5457
<?php endif; ?>
5558
</div>
5659
</div>
57-
<?php if (!strlen($block->getCouponCode())) : ?>
60+
<?php if (!$hasCouponCode) : ?>
5861
<?= /* @noEscape */ $block->getChildHtml('captcha') ?>
5962
<?php endif; ?>
6063
</form>

0 commit comments

Comments
 (0)