I want to call this on the templates/cart/item/default.phtml page so that I can use step on my qty box.
$block->getProductDefaultQty()
This line works on the product page qty box, but not on the checkout page:
step="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
Thanks in advance!
Solved! Go to Solution.
I've managed to sort it by just using the weight + 0.5 which works for my use. Thanks for the help!
First i want to clear few points here.
$block->getProductDefaultQty()
It means fetching getProductDefaultQty() which is there in the block of that file.
Now you are using this same on checkout but may be this function is not there in the block of checkout.
So try to use the function which is there on the checkout block.
Thanks
---
If you've found my answer useful, please give"Kudos" and "Accept as Solution".
How can I see what is available on the checkout block? I've been using trial and error to try and find it but I can't.
Can you please let me know what exactly you want to achieve so that i can give you some suggestions on that.
Thanks
---
If you've found my answer useful, please give"Kudos" and "Accept as Solution".
I want to use the item incremental value or defualt qty to be able to use them to have a step for the qty box so users have to use the icremental values rather than type what they want. e.g. 1.5, 3, 4.5 etc.
I have it working on the product page:
You can refer this link and where default_qty is calculated they are multiplying it by 1 just replace it by 1.5.
https://magenticians.com/quantity-increment-decrement-magento-2/
Hope it helps!
Thanks
---
If you've found my answer useful, please give"Kudos" and "Accept as Solution".
Hi, thanks, but that only works for the product page, not in the cart. The issue I have is that a customer could get to the basket and change the value to anything.
Sorry, here is the code for the product page:
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** @var $block \Magento\Catalog\Block\Product\View */ ?> <?php $_product = $block->getProduct(); ?> <?php $buttonTitle = __('Add to Cart'); ?> <?php if ($_product->isSaleable()): ?> <div class="box-tocart"> <div class="fieldset"> <?php if ($block->shouldRenderQuantity()): ?> <div class="field qty"> <label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label> <div class="control"> <input type="number" name="qty" id="qty" step="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>" value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>" title="<?= /* @escapeNotVerified */ __('Qty') ?>" class="input-text qty" data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>" /> </div> </div> <?php endif; ?> <div class="actions"> <button type="submit" title="<?= /* @escapeNotVerified */ $buttonTitle ?>" class="action primary tocart" id="product-addtocart-button"> <span><?= /* @escapeNotVerified */ $buttonTitle ?></span> </button> <?= $block->getChildHtml('', true) ?> </div> </div> </div> <?php endif; ?> <script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/js/validate-product": {} } } </script>