Skip to content

Commit f54c386

Browse files
committed
MC-42249: No form validation for negative quantity on bundle products
- Fixed CR comments
1 parent c89d353 commit f54c386

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

app/code/Magento/Bundle/ViewModel/ValidateQuantity.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,41 @@
77

88
namespace Magento\Bundle\ViewModel;
99

10-
use Magento\CatalogInventory\Model\StockRegistry;
10+
use Magento\Framework\Serialize\Serializer\Json;
1111
use Magento\Framework\View\Element\Block\ArgumentInterface;
1212
use Magento\Catalog\Block\Product\View as ProductView;
1313

1414
/**
1515
* ViewModel for Bundle Option Block
1616
*/
17-
1817
class ValidateQuantity implements ArgumentInterface
1918
{
19+
/**
20+
* @var Json
21+
*/
22+
private Json $serializer;
23+
2024
/**
2125
* @var ProductView
2226
*/
23-
private $productView;
27+
private ProductView $productView;
2428

2529
/**
30+
* @param Json $serializer
2631
* @param ProductView $productView
2732
*/
28-
public function __construct(ProductView $productView)
29-
{
33+
public function __construct(
34+
Json $serializer,
35+
ProductView $productView
36+
) {
37+
$this->serializer = $serializer;
3038
$this->productView = $productView;
3139
}
3240

33-
public function getQuantityValidators(): array
41+
public function getQuantityValidators(): string
3442
{
35-
return $this->productView->getQuantityValidators();
43+
return $this->serializer->serialize(
44+
$this->productView->getQuantityValidators()
45+
);
3646
}
3747
}

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/radio.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ $viewModel = $block->getData('validateQuantityViewModel');
7676
class="input-text qty<?php if (!$_canChangeQty) { echo ' qty-disabled'; } ?>"
7777
type="number"
7878
min="0"
79-
data-validate="<?= $block->escapeHtml(json_encode($viewModel->getQuantityValidators())) ?>"
79+
data-validate="<?= $block->escapeHtmlAttr($viewModel->getQuantityValidators()) ?>"
8080
name="bundle_option_qty[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
8181
data-selector="bundle_option_qty[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
8282
value="<?= $block->escapeHtmlAttr($_defaultQty) ?>"/>

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/select.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ $viewModel = $block->getData('validateQuantityViewModel');
6262
class="input-text qty<?php if (!$_canChangeQty) { echo ' qty-disabled'; } ?>"
6363
type="number"
6464
min="0"
65-
data-validate="<?= $block->escapeHtml(json_encode($viewModel->getQuantityValidators())) ?>"
65+
data-validate="<?= $block->escapeHtmlAttr($viewModel->getQuantityValidators()) ?>"
6666
name="bundle_option_qty[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
6767
data-selector="bundle_option_qty[<?= $block->escapeHtmlAttr($_option->getId()) ?>]"
6868
value="<?= $block->escapeHtmlAttr($_defaultQty) ?>"/>

0 commit comments

Comments
 (0)