Jump to content

Cart.js and step PrestaShop : 1.7.3.2


Recommended Posts

Hi,

I want to update the cart quantity of a product by step and stop to the max quantity available.

So in cart.js, I add the max and step property of the spinner

 

function createSpin()
{
  $.each($(spinnerSelector), function (index, spinner) {
     $(spinner).TouchSpin({
       verticalbuttons: true,
       verticalupclass: 'fa fa-angle-up touchspin-up',
       verticaldownclass: 'fa fa-angle-down touchspin-down',
       buttondown_class: 'btn btn-touchspin  js-touchspin js-increase-product-quantity',
       buttonup_class: 'btn btn-touchspin js-decrease-product-quantity',
       min: parseInt($(spinner).attr('min'), 10),
       max: parseInt($(spinner).attr('max'), 10),
       step: parseInt($(spinner).attr('step'), 10)   
    });
  });

  CheckUpdateQuantityOperations.switchErrorStat();
}

and in the cart-detailed-product-line.tpl

div class="col col-auto col-md qty">
                {if isset($product.is_gift) && $product.is_gift}
                    <span class="gift-quantity">{$product.quantity}</span>
                {else}
                    <input
                            class="js-cart-line-product-quantity"
                            data-down-url="{$product.down_quantity_url}"
                            data-up-url="{$product.up_quantity_url}"
                            data-update-url="{$product.update_quantity_url}"
                            data-product-id="{$product.id_product}"
                            type="text"
                            value="{$product.quantity}"
                            name="product-quantity-spin"
                            min="{$product.minimal_quantity}"
                            step="{$product.minimal_quantity}"
                            max="{$product.quantity_available}"
                    />
                {/if}
            </div>

so..it works with the spinner but just after that, the right block is refresh (sub total and total) with +1 and not with the step and the js-cart-line-product-quantity zone class is refresh (where the spinner is) with +1 quantity two.

So, the spinner don't give the quantity to the link "http://www.prestashop.lenclosdesvins.com/panier?update=1&id_product=25&id_product_attribute=46&token=bfd9f14c6636ce0491077ff97106e997&op=up"

but I don"t kwon where modify this ...:/

Thank you for your help

Regards

Edited by guil182 (see edit history)
Link to comment
Share on other sites

So, I progress....I think.

There is two different behaviors :

In the cart page, if I change the quantity directly in the input it works with quantity and the post parameters are :

ajax=1
qty=6
action=update
op=up

and when I clic the spinner, it doesn't work :

the post parameters are :

ajax=1
action=update

and I don't find where the two different URL are build ...:/

regards

Link to comment
Share on other sites

I found or almost :

cart.js ...around line 140 :

let requestData = {
      ajax: '1',
      action: 'update',
    };

to change to :

let requestData = {
      ajax: '1',
      qty: '6',    
      action: 'update',
      op: 'up'
    };

 

now....I have to try the change dynamically qty and op...if you have an idea ?

 

 regards

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

I'm trying to achieve the exact same thing.

I edited the cart.js and  cart-detailed-product-line.tpl files, but this has no effect. I think that the minimized theme.js file has the touchspin main configuration code, which is used to update the quantity values.

Does anyone know how I can update the quantity by step, and consequently update the total cart price ?

Link to comment
Share on other sites

  • 1 month later...

This code for catalog/_partials/product-add-to-cart.tpl
(you need to set step="{$product.minimal_quantity}") works fine.


Change theme.js

 !function() {
            var t = (0, o.default)("#quantity_wanted");
            t.TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin",
                buttonup_class: "btn btn-touchspin js-touchspin",
                min: parseInt(t.attr("min"), 10),
                max: 1e6
            });

to

!function() {
            var t = (0, o.default)("#quantity_wanted");
            t.TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin",
                buttonup_class: "btn btn-touchspin js-touchspin",
                min: parseInt(t.attr("min"), 10),
                step: parseInt(t.attr("step"), 10),
                max: parseInt(t.attr("max"), 10)
            });

 

But this change is a bit of a hack and does require some additional clicks to work. Please solve this problem. This code change for checkout/_partials/cart-detailed-product-line.tpl  (you need to set step="{$product.minimal_quantity}") does work but is buggy. So I have clearly done something wrong...

    function o() {
        s.default.each((0, s.default)(c), function(t, e) {
            (0, s.default)(e).TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin js-increase-product-quantity",
                buttonup_class: "btn btn-touchspin js-touchspin js-decrease-product-quantity",
                min: parseInt((0, s.default)(e).attr("min"), 10),
                max: 1e6
            })
        }), f.switchErrorStat()
    }

to

    function o() {
        s.default.each((0, s.default)(c), function(t, e) {
            (0, s.default)(e).TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin js-increase-product-quantity",
                buttonup_class: "btn btn-touchspin js-touchspin js-decrease-product-quantity",
                min: parseInt((0, s.default)(e).attr("min"), 10),
                step: parseInt((0, s.default)(e).attr("step"), 10),
                max: 1e6
            })
        }), f.switchErrorStat()
    }

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
On 9/24/2018 at 11:40 PM, hjelmuap said:

This code for catalog/_partials/product-add-to-cart.tpl
(you need to set step="{$product.minimal_quantity}") works fine.


Change theme.js

 !function() {
            var t = (0, o.default)("#quantity_wanted");
            t.TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin",
                buttonup_class: "btn btn-touchspin js-touchspin",
                min: parseInt(t.attr("min"), 10),
                max: 1e6
            });

to

!function() {
            var t = (0, o.default)("#quantity_wanted");
            t.TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin",
                buttonup_class: "btn btn-touchspin js-touchspin",
                min: parseInt(t.attr("min"), 10),
                step: parseInt(t.attr("step"), 10),
                max: parseInt(t.attr("max"), 10)
            });

 

But this change is a bit of a hack and does require some additional clicks to work. Please solve this problem. This code change for checkout/_partials/cart-detailed-product-line.tpl  (you need to set step="{$product.minimal_quantity}") does work but is buggy. So I have clearly done something wrong...

    function o() {
        s.default.each((0, s.default)(c), function(t, e) {
            (0, s.default)(e).TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin js-increase-product-quantity",
                buttonup_class: "btn btn-touchspin js-touchspin js-decrease-product-quantity",
                min: parseInt((0, s.default)(e).attr("min"), 10),
                max: 1e6
            })
        }), f.switchErrorStat()
    }

to

    function o() {
        s.default.each((0, s.default)(c), function(t, e) {
            (0, s.default)(e).TouchSpin({
                verticalbuttons: !0,
                verticalupclass: "material-icons touchspin-up",
                verticaldownclass: "material-icons touchspin-down",
                buttondown_class: "btn btn-touchspin js-touchspin js-increase-product-quantity",
                buttonup_class: "btn btn-touchspin js-touchspin js-decrease-product-quantity",
                min: parseInt((0, s.default)(e).attr("min"), 10),
                step: parseInt((0, s.default)(e).attr("step"), 10),
                max: 1e6
            })
        }), f.switchErrorStat()
    }

 

thank you very mush 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...