update cart - prestashop

function changeQuantity(minimal_quantity, operator, id, id_attribute, quantincart){
var token = prestashop.static_token; //important for logged user
if (operator == 1){ //subtract
var actionURL = '/index.php';
var query= 'controller=cart&add=1&action=update&ajax=true&qty=1&op=down&token='+token+'&id_product='+ id +'&ipa='+ id_attribute;
$.post(actionURL, query, null, 'json').then(function (resp) {
prestashop.emit('updateCart', {
        reason: resp
      });
console.log(resp);
}).fail(function (resp) {
    prestashop.emit('handleError', { eventType: 'addProductToCart', resp: resp });
   });

}else if (operator == 2){ //sum
var actionURL = '/index.php';
var query= 'controller=cart&add=1&action=update&ajax=true&qty=1&op=up&token='+token+'&id_product='+ id +'&ipa='+ id_attribute;
$.post(actionURL, query, null, 'json').then(function (resp) {
prestashop.emit('updateCart', {
        reason: resp
      });
console.log(resp);
}).fail(function (resp) {
    prestashop.emit('handleError', { eventType: 'addProductToCart', resp: resp });
  });

}else if (operator == 3){ //delete
var actionURL = '/index.php';
var query= 'controller=cart&add=1&action=update&ajax=true&qty='+quantincart+'&op=down&token='+token+'&id_product='+ id +'&ipa='+ id_attribute;
$.post(actionURL, query, null, 'json').then(function (resp) {
prestashop.emit('updateCart', {
        reason: resp
      });
console.log(resp);
}).fail(function (resp) {
    prestashop.emit('handleError', { eventType: 'addProductToCart', resp: resp });
  });
}
}

Comments

Popular Posts