jeudi 4 juin 2015

Update product quantity Ajax prestashop

If you search for the js code to update quantity in prestashop 1.6, you can find it under prestashop/js/admin-products.js line 1451

This code is responsible for product quantity update, in quantities tab under product admin page.
$('.available_quantity').find('input').change(function(e, init_val){
self.ajaxCall({actionQty: 'set_qty', 
id_product_attribute: $(this).parent().attr('id').split('_')[1], value: $(this).val()});
});
 
 
You can search for ajaxCall in the same file,
 
 
product_tabs['Quantities'] = new function(){
 var self = this;
 this.ajaxCall = function(data){
  data.ajaxProductQuantity = 1;
  data.id_product = id_product;
  data.token = token;
  data.ajax = 1;
  data.controller = "AdminProducts";
  data.action = "productQuantity";

  $.ajax({
   type: "POST",
   url: "ajax-tab.php",
   data: data,
   dataType: 'json',
   async : true,
   beforeSend: function(xhr, settings)
   {
    $('.product_quantities_button').attr('disabled', 'disabled');
   },
   complete: function(xhr, status)
   {
    $('.product_quantities_button').removeAttr('disabled');
   },
   success: function(msg)
   {
    if (msg.error)
    {
     showErrorMessage(msg.error);
     return;
    }
    showSuccessMessage(quantities_ajax_success);
   },
   error: function(jqXHR, textStatus, errorThrown)
   {
    if (textStatus != 'error' || errorThrown != '')
     showErrorMessage(textStatus + ': ' + errorThrown);    
   }
  });
 };
 
Hope this helps! 

0 commentaires :

Enregistrer un commentaire