3

I have configured a product with the "Qty increments" (100) / and " Minimum Qty Allowed in Shopping Cart" (100). When I go to the product page, the quantity is 100 by default but when I click on "+", the quantity is increase to 101 and not 200. enter image description here

enter image description here

Can you help me?

Thanks in advance.

5
  • if you use bootstrap on your website then let me know, I have solution for this Jul 7, 2017 at 7:35
  • Yes, I used the "Porto" theme from ThemeForest. It's a bootstrap theme.
    – Vianney03
    Jul 7, 2017 at 8:05
  • did you got the solution or Should I need to post the answer? Jul 7, 2017 at 8:06
  • No, I didn't find the solution. Can you post it? Thanks
    – Vianney03
    Jul 7, 2017 at 8:33
  • please wait , will post in 30 mints , thanks Jul 7, 2017 at 8:34

4 Answers 4

3

Here I am guiding you adding plus/minus functionality with increment of 100 in default file. Use the code accordingly.

In catalog module edit your Quantity function which comes by default in addtocart.phtml like below code

<div class="field qty">
            <label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
            <div class="control">
                <input type="number"
                       name="qty"
                       id="qty"
                       maxlength="12"
                       value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
                       title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty"
                       data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                       />
            </div>
        </div>

Update the code below adding class to input field and pass input id/name to buttons data field and for

<div class="field qty">

                <div class="control qty-numbers">
                    <div class="input-group">


                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default btn-number quantity-left-minus"  data-type="minus" data-field="qty">
                              <span class="glyphicon glyphicon-minus"></span>
                            </button>
                        </span>


                        <input type="number"
                        name="qty"
                        class="form-control input-number"
                        id="qty"
                        min="1"
                        maxlength="12"
                         value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
                                 title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty"
                                 data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                                 />


                        <!--plus button-->
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-default btn-number quantity-left-plus" data-type="plus" data-field="qty">
                                <span class="glyphicon glyphicon-plus"></span>
                            </button>
                        </span>
                    </div>
                </div>
            </div>

do it carefully and then add below script in bootstrap.js

$(document).ready(function(){

var quantitiy=100;
   $('.quantity-right-plus').click(function(e){

        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        var quantity = parseInt($('#qty').val());

        // If is not undefined

            $('#qty').val(quantity + 100);


            // Increment

    });

     $('.quantity-left-minus').click(function(e){
        // Stop acting like a button
        e.preventDefault();
        // Get the field name
        var quantity = parseInt($('#qty').val());

        // If is not undefined

            // Increment
            if(quantity>100){
            $('#qty').val(quantity - 100);
            }
    });

});

This works on default, if doesn't work with your then please pass me the quantity or add to cart code.

I hope this solve your problem.

Thanks

7
  • Thanks for your reply. I have a question, I have a lot of product with different incremant quantity. For this article, I need to increase the value from 100 to 200, but for example, on another product, the value have to increase one by one. Is it working with your code?
    – Vianney03
    Jul 7, 2017 at 9:43
  • this require more customization and I haven't tested that way. Currently this code is for you current requirement . if this fulfill that then I will check that case too if possible today , I help you out Jul 7, 2017 at 9:45
  • I just tested that way and it works with little tweaks in the code . Test this first if it works then I will help you out for that case too Jul 7, 2017 at 9:52
  • I post under the custom addtocart.phtml file that my website use to increase the value of the qty when I click on "+/-". Sorry for the mistake
    – Vianney03
    Jul 7, 2017 at 10:08
  • use that file i sent and ( your theme custom file , right ?) , I hope you have added js in your bootstrap.js... Jul 7, 2017 at 10:23
2

You have customized the (+) and (-) increments in product details page. You should fetch the database value qty increments and assign to your (+) and (-). Then it will be incremented as you excepted.

Hope it will help you!

If possible please share your code.

1

catalog_product_view:

<container name="product.info.form.content" as="product_info_form_content">
                    <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="product/view/addtocart.phtml"/>
                </container>

addtocart.phtml:

<?php
/**
 * Copyright © 2013-2017 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><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
            <div class="control">
                <input type="number"
                       name="qty"
                       id="qty"
                       maxlength="12"
                       value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
                       title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty"
                       data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                       />
            </div>
        </div>
        <?php endif; ?>
        <div class="actions">
            <button type="submit"
                    title="<?php /* @escapeNotVerified */ echo $buttonTitle ?>"
                    class="action primary tocart"
                    id="product-addtocart-button">
                <span><?php /* @escapeNotVerified */ echo $buttonTitle ?></span>
            </button>
            <?php echo $block->getChildHtml('', true) ?>
        </div>
    </div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "Magento_Catalog/product/view/validation": {
                "radioCheckboxClosest": ".nested"
            }
        }
    }
</script>
<?php if (!$block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "catalogAddToCart": {
                "bindSubmit": false
            }
        }
    }
</script>
<?php endif; ?>

Thanks,

1

Custom addtocart.phtml file :

<div class="box-tocart">
<div class="fieldset">
    <?php if ($block->shouldRenderQuantity()): ?>
    <div class="field qty">
        <label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>
        <div class="control">
            <input type="number"
                   name="qty"
                   id="qty"
                   maxlength="12"
                   value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
                   title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty"
                   data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                   />
        </div>
        <div class="qty-changer">
            <a href="javascript:void(0)" class="qty-inc"><i class="porto-icon-up-dir"></i></a>
            <a href="javascript:void(0)" class="qty-dec"><i class="porto-icon-down-dir"></i></a>
        </div>
    </div>
    <?php endif; ?>
    <div class="actions">
        <button type="submit"
                title="<?php /* @escapeNotVerified */ echo $buttonTitle ?>"
                class="action primary tocart"
                id="product-addtocart-button">
            <span><?php /* @escapeNotVerified */ echo $buttonTitle ?></span>
        </button>
        <?php echo $block->getChildHtml('', true) ?>
    </div>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.