Quantity Increment and Decrement Button not work in Magento 2Magento 1.8 order product quantity per 0.1...

Deletion of copy-ctor & copy-assignment - public, private or protected?

Am I eligible for the Eurail Youth pass? I am 27.5 years old

Should I use acronyms in dialogues before telling the readers what it stands for in fiction?

Writing in a Christian voice

Loading the leaflet Map in Lightning Web Component

How to define limit operations in general topological spaces? Are nets able to do this?

Variable completely messes up echoed string

PTIJ: Why do we blow Shofar on Rosh Hashana and use a Lulav on Sukkos?

What (if any) is the reason to buy in small local stores?

In what cases must I use 了 and in what cases not?

PTIJ: Do Irish Jews have "the luck of the Irish"?

Why are there no stars visible in cislunar space?

Pronounciation of the combination "st" in spanish accents

Practical application of matrices and determinants

I seem to dance, I am not a dancer. Who am I?

gerund and noun applications

Optimising a list searching algorithm

What does Jesus mean regarding "Raca," and "you fool?" - is he contrasting them?

I got the following comment from a reputed math journal. What does it mean?

Is it insecure to send a password in a `curl` command?

Generic TVP tradeoffs?

How to generate binary array whose elements with values 1 are randomly drawn

Would it be believable to defy demographics in a story?

Suggestions on how to spend Shaabath (constructively) alone



Quantity Increment and Decrement Button not work in Magento 2


Magento 1.8 order product quantity per 0.1 decimalsProduct QTY Increment Magento 1.8shopping cart page increment and decrement buttonIncrement and decrement qty button on shopping cart pageProduct quantity incremet/decrement on home pageQuantity increment buttonquantity increment button based on _qtyIncrements valueMagento 2 product list quantity increment buttonsQuantity increment validation failurehow to add quantity increment and decreament (+ and - button) in minicart magento 2?













1















I'm using custom modules to show quantity increment/decrement in quantity box
using KnockoutJS.



Making custom modules for every folder is correct.but it nothing happpend, after click on increment/decrement button on product details page in magentov2.1.9.



I followed this link during this task:



https://magenticians.com/quantity-increment-decrement-magento-2/



what are missing from my side.



enter image description here










share|improve this question

























  • How can we help you? Can you post what kind of error you receive or code you have written?

    – Bartosz Herba
    Nov 15 '17 at 7:11











  • @BartoszHerba, I mentioned above link to follows.but in my case script not work in this task.hope you understand.

    – Anikesh Shahi
    Nov 15 '17 at 7:17











  • Great to have documentation of module but how i am suppose to guess what is wrong with YOUR code if you are not sharing it nor the error logs?

    – Bartosz Herba
    Nov 15 '17 at 7:22
















1















I'm using custom modules to show quantity increment/decrement in quantity box
using KnockoutJS.



Making custom modules for every folder is correct.but it nothing happpend, after click on increment/decrement button on product details page in magentov2.1.9.



I followed this link during this task:



https://magenticians.com/quantity-increment-decrement-magento-2/



what are missing from my side.



enter image description here










share|improve this question

























  • How can we help you? Can you post what kind of error you receive or code you have written?

    – Bartosz Herba
    Nov 15 '17 at 7:11











  • @BartoszHerba, I mentioned above link to follows.but in my case script not work in this task.hope you understand.

    – Anikesh Shahi
    Nov 15 '17 at 7:17











  • Great to have documentation of module but how i am suppose to guess what is wrong with YOUR code if you are not sharing it nor the error logs?

    – Bartosz Herba
    Nov 15 '17 at 7:22














1












1








1








I'm using custom modules to show quantity increment/decrement in quantity box
using KnockoutJS.



Making custom modules for every folder is correct.but it nothing happpend, after click on increment/decrement button on product details page in magentov2.1.9.



I followed this link during this task:



https://magenticians.com/quantity-increment-decrement-magento-2/



what are missing from my side.



enter image description here










share|improve this question
















I'm using custom modules to show quantity increment/decrement in quantity box
using KnockoutJS.



Making custom modules for every folder is correct.but it nothing happpend, after click on increment/decrement button on product details page in magentov2.1.9.



I followed this link during this task:



https://magenticians.com/quantity-increment-decrement-magento-2/



what are missing from my side.



enter image description here







quantity magento-2.1.9 qty-increment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 mins ago









Teja Bhagavan Kollepara

3,00641949




3,00641949










asked Nov 15 '17 at 6:03









Anikesh ShahiAnikesh Shahi

152215




152215













  • How can we help you? Can you post what kind of error you receive or code you have written?

    – Bartosz Herba
    Nov 15 '17 at 7:11











  • @BartoszHerba, I mentioned above link to follows.but in my case script not work in this task.hope you understand.

    – Anikesh Shahi
    Nov 15 '17 at 7:17











  • Great to have documentation of module but how i am suppose to guess what is wrong with YOUR code if you are not sharing it nor the error logs?

    – Bartosz Herba
    Nov 15 '17 at 7:22



















  • How can we help you? Can you post what kind of error you receive or code you have written?

    – Bartosz Herba
    Nov 15 '17 at 7:11











  • @BartoszHerba, I mentioned above link to follows.but in my case script not work in this task.hope you understand.

    – Anikesh Shahi
    Nov 15 '17 at 7:17











  • Great to have documentation of module but how i am suppose to guess what is wrong with YOUR code if you are not sharing it nor the error logs?

    – Bartosz Herba
    Nov 15 '17 at 7:22

















How can we help you? Can you post what kind of error you receive or code you have written?

– Bartosz Herba
Nov 15 '17 at 7:11





How can we help you? Can you post what kind of error you receive or code you have written?

– Bartosz Herba
Nov 15 '17 at 7:11













@BartoszHerba, I mentioned above link to follows.but in my case script not work in this task.hope you understand.

– Anikesh Shahi
Nov 15 '17 at 7:17





@BartoszHerba, I mentioned above link to follows.but in my case script not work in this task.hope you understand.

– Anikesh Shahi
Nov 15 '17 at 7:17













Great to have documentation of module but how i am suppose to guess what is wrong with YOUR code if you are not sharing it nor the error logs?

– Bartosz Herba
Nov 15 '17 at 7:22





Great to have documentation of module but how i am suppose to guess what is wrong with YOUR code if you are not sharing it nor the error logs?

– Bartosz Herba
Nov 15 '17 at 7:22










1 Answer
1






active

oldest

votes


















2














=> Go to your theme Folder and create file called addtocart.phtml and
past below code.



Quantity Increment and Decrement Button working fine by using below code



E.g :




app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var $block MagentoCatalogBlockProductView */
?>
<?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>
<?php /*Add Plus Button */ ?>
<input type='button' value='+' class='qtyplus' field='qty' />
<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())) ?>"
/>
<?php /*Add Minus Button */ ?>
<input type='button' value='-' class='qtyminus' field='qty' />
</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; ?>
<?php /*JS FOR +-*/ ?>
<script type="text/javascript">
//&lt;![CDATA[
require(['jquery'], function ($) {
setTimeout(function () {
// This button will increment the value
jQuery('.qtyplus').click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
jQuery('input[name=' + fieldName + ']').val(currentVal + 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
// This button will decrement the value till 0
jQuery(".qtyminus").click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
jQuery('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
}, 100);
});
//]]&gt;
</script>





share|improve this answer


























  • After apply above code its not working in my case.only shows default box not increnment/decrement section.

    – Anikesh Shahi
    Nov 27 '17 at 6:57











  • any error in console ? Can you please share your code

    – Navin Bhudiya
    Nov 29 '17 at 4:47











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f201574%2fquantity-increment-and-decrement-button-not-work-in-magento-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














=> Go to your theme Folder and create file called addtocart.phtml and
past below code.



Quantity Increment and Decrement Button working fine by using below code



E.g :




app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var $block MagentoCatalogBlockProductView */
?>
<?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>
<?php /*Add Plus Button */ ?>
<input type='button' value='+' class='qtyplus' field='qty' />
<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())) ?>"
/>
<?php /*Add Minus Button */ ?>
<input type='button' value='-' class='qtyminus' field='qty' />
</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; ?>
<?php /*JS FOR +-*/ ?>
<script type="text/javascript">
//&lt;![CDATA[
require(['jquery'], function ($) {
setTimeout(function () {
// This button will increment the value
jQuery('.qtyplus').click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
jQuery('input[name=' + fieldName + ']').val(currentVal + 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
// This button will decrement the value till 0
jQuery(".qtyminus").click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
jQuery('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
}, 100);
});
//]]&gt;
</script>





share|improve this answer


























  • After apply above code its not working in my case.only shows default box not increnment/decrement section.

    – Anikesh Shahi
    Nov 27 '17 at 6:57











  • any error in console ? Can you please share your code

    – Navin Bhudiya
    Nov 29 '17 at 4:47
















2














=> Go to your theme Folder and create file called addtocart.phtml and
past below code.



Quantity Increment and Decrement Button working fine by using below code



E.g :




app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var $block MagentoCatalogBlockProductView */
?>
<?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>
<?php /*Add Plus Button */ ?>
<input type='button' value='+' class='qtyplus' field='qty' />
<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())) ?>"
/>
<?php /*Add Minus Button */ ?>
<input type='button' value='-' class='qtyminus' field='qty' />
</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; ?>
<?php /*JS FOR +-*/ ?>
<script type="text/javascript">
//&lt;![CDATA[
require(['jquery'], function ($) {
setTimeout(function () {
// This button will increment the value
jQuery('.qtyplus').click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
jQuery('input[name=' + fieldName + ']').val(currentVal + 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
// This button will decrement the value till 0
jQuery(".qtyminus").click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
jQuery('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
}, 100);
});
//]]&gt;
</script>





share|improve this answer


























  • After apply above code its not working in my case.only shows default box not increnment/decrement section.

    – Anikesh Shahi
    Nov 27 '17 at 6:57











  • any error in console ? Can you please share your code

    – Navin Bhudiya
    Nov 29 '17 at 4:47














2












2








2







=> Go to your theme Folder and create file called addtocart.phtml and
past below code.



Quantity Increment and Decrement Button working fine by using below code



E.g :




app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var $block MagentoCatalogBlockProductView */
?>
<?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>
<?php /*Add Plus Button */ ?>
<input type='button' value='+' class='qtyplus' field='qty' />
<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())) ?>"
/>
<?php /*Add Minus Button */ ?>
<input type='button' value='-' class='qtyminus' field='qty' />
</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; ?>
<?php /*JS FOR +-*/ ?>
<script type="text/javascript">
//&lt;![CDATA[
require(['jquery'], function ($) {
setTimeout(function () {
// This button will increment the value
jQuery('.qtyplus').click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
jQuery('input[name=' + fieldName + ']').val(currentVal + 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
// This button will decrement the value till 0
jQuery(".qtyminus").click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
jQuery('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
}, 100);
});
//]]&gt;
</script>





share|improve this answer















=> Go to your theme Folder and create file called addtocart.phtml and
past below code.



Quantity Increment and Decrement Button working fine by using below code



E.g :




app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/addtocart.phtml




<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var $block MagentoCatalogBlockProductView */
?>
<?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>
<?php /*Add Plus Button */ ?>
<input type='button' value='+' class='qtyplus' field='qty' />
<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())) ?>"
/>
<?php /*Add Minus Button */ ?>
<input type='button' value='-' class='qtyminus' field='qty' />
</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; ?>
<?php /*JS FOR +-*/ ?>
<script type="text/javascript">
//&lt;![CDATA[
require(['jquery'], function ($) {
setTimeout(function () {
// This button will increment the value
jQuery('.qtyplus').click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
jQuery('input[name=' + fieldName + ']').val(currentVal + 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
// This button will decrement the value till 0
jQuery(".qtyminus").click(function (e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = jQuery(this).attr('field');
// Get its current value
var currentVal = parseInt(jQuery('input[name=' + fieldName + ']').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
jQuery('input[name=' + fieldName + ']').val(currentVal - 1);
} else {
// Otherwise put a 0 there
jQuery('input[name=' + fieldName + ']').val(0);
}
});
}, 100);
});
//]]&gt;
</script>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '17 at 6:10









Rohan Hapani

6,56831864




6,56831864










answered Nov 17 '17 at 6:01









Navin BhudiyaNavin Bhudiya

7491024




7491024













  • After apply above code its not working in my case.only shows default box not increnment/decrement section.

    – Anikesh Shahi
    Nov 27 '17 at 6:57











  • any error in console ? Can you please share your code

    – Navin Bhudiya
    Nov 29 '17 at 4:47



















  • After apply above code its not working in my case.only shows default box not increnment/decrement section.

    – Anikesh Shahi
    Nov 27 '17 at 6:57











  • any error in console ? Can you please share your code

    – Navin Bhudiya
    Nov 29 '17 at 4:47

















After apply above code its not working in my case.only shows default box not increnment/decrement section.

– Anikesh Shahi
Nov 27 '17 at 6:57





After apply above code its not working in my case.only shows default box not increnment/decrement section.

– Anikesh Shahi
Nov 27 '17 at 6:57













any error in console ? Can you please share your code

– Navin Bhudiya
Nov 29 '17 at 4:47





any error in console ? Can you please share your code

– Navin Bhudiya
Nov 29 '17 at 4:47


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f201574%2fquantity-increment-and-decrement-button-not-work-in-magento-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

“%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...