cancel
Showing results for 
Search instead for 
Did you mean: 

Get default product qty on basket page

SOLVED

Get default product qty on basket page

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! Smiley Very Happy

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Get default product qty on basket page

I've managed to sort it by just using the weight + 0.5 which works for my use. Thanks for the help! Smiley Happy

View solution in original post

9 REPLIES 9

Re: Get default product qty on basket page

Hi @neil_widdowson 

 

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".

Re: Get default product qty on basket page

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.

Re: Get default product qty on basket page

Hi @neil_widdowson 

 

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".

Re: Get default product qty on basket page

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:

https://theyarnstore.co.uk/newstore/cashmere-2-28.html

Re: Get default product qty on basket page

Hi @neil_widdowson 

 

Can you show me the code which you are using on product page?

 

Thanks!

Re: Get default product qty on basket page

Hi @neil_widdowson 

 

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".

Re: Get default product qty on basket page

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.

Re: Get default product qty on basket page

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>

Re: Get default product qty on basket page

I've managed to sort it by just using the weight + 0.5 which works for my use. Thanks for the help! Smiley Happy