Jump to content

product page ProductSpin 1.7.6


Recommended Posts

hi,

I want to stop ProductSpin with max = $product.quantity.

So, I modify product-add-to-cart.tpl :

 <input
                                type="number"
                                name="qty"
                                id="quantity_wanted"
                                value="{$product.quantity_wanted}"
                                class="input-group"
                                min="{$product.minimal_quantity}"
                                max="{$product.quantity}"
                                step="{$product.minimal_quantity}"
                        >

et j'ai surchargé product.js en créant un product.js dans un theme enfant.

And I create a product.js in a child theme

$(document).ready(function () {
  createProductSpin();

  prestashop.on('updatedProduct', function (event) {

    if (event && event.product_minimal_quantity) {
      const minimalProductQuantity = parseInt(event.product_minimal_quantity, 10);
      const quantityInputSelector = '#quantity_wanted';
      let quantityInput = $(quantityInputSelector);
      let quantityMax = parseInt($('#pmax').text());

      // @see http://www.virtuosoft.eu/code/bootstrap-touchspin/ about Bootstrap TouchSpin
      quantityInput.trigger('touchspin.updatesettings', {min: minimalProductQuantity,step: minimalProductQuantity,max: quantityMax});
    }

  });

  function createProductSpin()
  {
    const $quantityInput = $('#quantity_wanted');

    $quantityInput.TouchSpin({
      verticalbuttons: true,
      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($quantityInput.attr('min'), 10),
      max: parseInt($quantityInput.attr('max'), 10),
      step: parseInt($quantityInput.attr('step'), 10)
    });

    $('body').on('change keyup', '#quantity_wanted', (e) => {
      $(e.currentTarget).trigger('touchspin.stopspin');
      prestashop.emit('updateProduct', {
          eventType: 'updatedProductQuantity',
          event: e
      });
    });
  }
});

I work...almost !
Indeed, when we arrive on the page, we can quickly press the "up", the quantity is not blocked .... it is blocked after the Ajax response of updated cart 😕

The result : http://prestashop.lenclosdesvins.com/pomerol/20-chateau-la-conseillante-2010.html

Thank for your help

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