File tree Expand file tree Collapse file tree 4 files changed +54
-3
lines changed
templates/catalog/product/view/type/bundle/option Expand file tree Collapse file tree 4 files changed +54
-3
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Bundle \ViewModel ;
9
+
10
+ use Magento \CatalogInventory \Model \StockRegistry ;
11
+ use Magento \Framework \View \Element \Block \ArgumentInterface ;
12
+ use Magento \Catalog \Block \Product \View as ProductView ;
13
+
14
+ /**
15
+ * ViewModel for Bundle Option Block
16
+ */
17
+
18
+ class ValidateQuantity implements ArgumentInterface
19
+ {
20
+ /**
21
+ * @var ProductView
22
+ */
23
+ private $ productView ;
24
+
25
+ /**
26
+ * @param ProductView $productView
27
+ */
28
+ public function __construct (ProductView $ productView )
29
+ {
30
+ $ this ->productView = $ productView ;
31
+ }
32
+
33
+ public function getQuantityValidators (): array
34
+ {
35
+ return $ this ->productView ->getQuantityValidators ();
36
+ }
37
+ }
Original file line number Diff line number Diff line change 32
32
<block class =" Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Select" name =" product.info.bundle.options.select" as =" select" >
33
33
<arguments >
34
34
<argument name =" tier_price_renderer" xsi : type =" object" >\Magento\Bundle\Block\DataProviders\OptionPriceRenderer</argument >
35
+ <argument name =" validateQuantityViewModel" xsi : type =" object" >Magento\Bundle\ViewModel\ValidateQuantity</argument >
35
36
</arguments >
36
37
</block >
37
38
<block class =" Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Multi" name =" product.info.bundle.options.multi" as =" multi" />
38
39
<block class =" Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Radio" name =" product.info.bundle.options.radio" as =" radio" >
39
40
<arguments >
40
41
<argument name =" tier_price_renderer" xsi : type =" object" >\Magento\Bundle\Block\DataProviders\OptionPriceRenderer</argument >
42
+ <argument name =" validateQuantityViewModel" xsi : type =" object" >Magento\Bundle\ViewModel\ValidateQuantity</argument >
41
43
</arguments >
42
44
</block >
43
45
<block class =" Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox" name =" product.info.bundle.options.checkbox" as =" checkbox" >
49
51
</referenceBlock >
50
52
<referenceBlock name =" product.info.form.options" >
51
53
<container name =" bundle.product.options.wrapper" htmlTag =" div" htmlClass =" bundle-options-wrapper" />
52
- </referenceBlock >
54
+ </referenceBlock >
53
55
<move element =" product.info.options.wrapper" destination =" bundle.product.options.wrapper" before =" -" />
54
56
<move element =" product.info.options.wrapper.bottom" destination =" bundle.product.options.wrapper" after =" product.info.options.wrapper" />
55
57
<move element =" product.price.tier" destination =" product.info.options.wrapper.bottom" before =" -" />
Original file line number Diff line number Diff line change 3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ use Magento \Bundle \ViewModel \ValidateQuantity ;
6
7
?>
7
8
<?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Radio */ ?>
8
9
<?php $ _option = $ block ->getOption (); ?>
9
10
<?php $ _selections = $ _option ->getSelections (); ?>
10
11
<?php $ _default = $ _option ->getDefaultSelection (); ?>
11
12
<?php list ($ _defaultQty , $ _canChangeQty ) = $ block ->getDefaultValues (); ?>
12
-
13
+ <?php
14
+ /** @var ValidateQuantity $viewModel */
15
+ $ viewModel = $ block ->getData ('validateQuantityViewModel ' );
16
+ ?>
13
17
<div class="field option <?= ($ _option ->getRequired ()) ? ' required ' : '' ?> ">
14
18
<label class="label">
15
19
<span><?= $ block ->escapeHtml ($ _option ->getTitle ()) ?> </span>
71
75
id="bundle-option-<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> -qty-input"
72
76
class="input-text qty<?php if (!$ _canChangeQty ) { echo ' qty-disabled ' ; } ?> "
73
77
type="number"
78
+ min="0"
79
+ data-validate="<?= $ block ->escapeHtml (json_encode ($ viewModel ->getQuantityValidators ())) ?> "
74
80
name="bundle_option_qty[<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> ]"
75
81
data-selector="bundle_option_qty[<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> ]"
76
82
value="<?= $ block ->escapeHtmlAttr ($ _defaultQty ) ?> "/>
Original file line number Diff line number Diff line change 3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ use Magento \Bundle \ViewModel \ValidateQuantity ;
6
7
?>
7
-
8
8
<?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Select */ ?>
9
9
<?php $ _option = $ block ->getOption (); ?>
10
10
<?php $ _selections = $ _option ->getSelections (); ?>
11
11
<?php $ _default = $ _option ->getDefaultSelection (); ?>
12
12
<?php list ($ _defaultQty , $ _canChangeQty ) = $ block ->getDefaultValues (); ?>
13
+ <?php
14
+ /** @var ValidateQuantity $viewModel */
15
+ $ viewModel = $ block ->getData ('validateQuantityViewModel ' );
16
+ ?>
13
17
<div class="field option <?= ($ _option ->getRequired ()) ? ' required ' : '' ?> ">
14
18
<label class="label" for="bundle-option-<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> ">
15
19
<span><?= $ block ->escapeHtml ($ _option ->getTitle ()) ?> </span>
57
61
id="bundle-option-<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> -qty-input"
58
62
class="input-text qty<?php if (!$ _canChangeQty ) { echo ' qty-disabled ' ; } ?> "
59
63
type="number"
64
+ min="0"
65
+ data-validate="<?= $ block ->escapeHtml (json_encode ($ viewModel ->getQuantityValidators ())) ?> "
60
66
name="bundle_option_qty[<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> ]"
61
67
data-selector="bundle_option_qty[<?= $ block ->escapeHtmlAttr ($ _option ->getId ()) ?> ]"
62
68
value="<?= $ block ->escapeHtmlAttr ($ _defaultQty ) ?> "/>
You can’t perform that action at this time.
0 commit comments