Jump to content

Configure Up and Down Buttons in cart-summary.js


Javier M.

Recommended Posts

Hi everyone:
I am using prestashop 1.6.1.1 and basicly I have two types of products: The first group are fabrics that are sold in increments of 10 cm with a minimum quantity of 30cm. The second group are the rest of products that are sold 1 by 1 with a minimum quantity of 1.


When I am doing the queckout, the "shopping-cart-product-line.tpl" file runs "themes/default/js/cart-summary.js" javascript file. This file defines the number of units to up or down the total quantity of the product.


My problem is: if the total quantity of the product is >=30 units I want to increase the total quantity in 10 units (because the product is a fabric). If the total quantity of the product is < 30 units I want to increase the total quantity in 1 unit (because the product isn´t a fabric). In order to do this, I studied the code of the "cart-summary.js" file but I don´t find the way to do it because I don´t find the variable that contains the total quantity of the product.

Any idea how i could get it?


Thanks in advance.

 

  1. function upQuantity(id, qty)
  2. {
  3.     if (typeof(qty) == 'undefined' || !qty)
  4.         qty = 1;
  5.     var customizationId = 0;
  6.     var productId = 0;
  7.     var productAttributeId = 0;
  8.     var id_address_delivery = 0;
  9.     var ids = 0;
  10.     ids = id.split('_');
  11.     productId = parseInt(ids[0]);
  12.     if (typeof(ids[1]) !== 'undefined')
  13.         productAttributeId = parseInt(ids[1]);
  14.     if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
  15.         customizationId = parseInt(ids[2]);
  16.     if (typeof(ids[3]) !== 'undefined')
  17.         id_address_delivery = parseInt(ids[3]);
  18.  
  19.     $.ajax({
  20.         type: 'POST',
  21.         headers: { "cache-control": "no-cache" },
  22.         url: baseUri + '?rand=' + new Date().getTime(),
  23.         async: true,
  24.         cache: false,
  25.         dataType: 'json',
  26.         data: 'controller=cart'
  27.             + '&ajax=true'
  28.             + '&add=true'
  29.             + '&getproductprice=true'
  30.             + '&summary=true'
  31.             + '&id_product=' + productId
  32.             + '&ipa=' + productAttributeId
  33.             + '&id_address_delivery=' + id_address_delivery
  34.             + ((customizationId !== 0) ? '&id_customization=' + customizationId : '')
  35.             + '&qty=' + qty
  36.             + '&token=' + static_token
  37.             + '&allow_refresh=1',
  38.         success: function(jsonData)
  39.         {
  40.             if (jsonData.hasError)
  41.             {
  42.                 var errors = '';
  43.                 for(var error in jsonData.errors)
  44.                     //IE6 bug fix
  45.                     if(error !== 'indexOf')
  46.                         errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
  47.                 if (!!$.prototype.fancybox)
  48.                  $.fancybox.open([
  49.              {
  50.              type: 'inline',
  51.              autoScale: true,
  52.              minHeight: 30,
  53.              content: '<p class="fancybox-error">' + errors + '</p>'
  54.              }],
  55.                     {
  56.                  padding: 0
  57.                  });
  58.                 else
  59.                  alert(errors);
  60.                 $('input[name=quantity_'+ id +]').val($('input[name=quantity_'+ id +'_hidden]').val());
  61.             }
  62.             else
  63.             {
  64.                 if (jsonData.refresh)
  65.                     location.reload();
  66.                 updateCartSummary(jsonData.summary);
  67.                 if (window.ajaxCart != undefined)
  68.                     ajaxCart.updateCart(jsonData);
  69.                 if (customizationId !== 0)
  70.                     updateCustomizedDatas(jsonData.customizedDatas);
  71.                 updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
  72.                 updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
  73.                 if (typeof(getCarrierListAndUpdate) !== 'undefined')
  74.                     getCarrierListAndUpdate();
  75.                 if (typeof(updatePaymentMethodsDisplay) !== 'undefined')
  76.                     updatePaymentMethodsDisplay();                    
  77.             }
  78.         },
  79.         error: function(XMLHttpRequest, textStatus, errorThrown) {
  80.             if (textStatus !== 'abort')
  81.             {
  82.                 error = "TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus;
  83.                 if (!!$.prototype.fancybox)
  84.                  $.fancybox.open([
  85.              {
  86.              type: 'inline',
  87.              autoScale: true,
  88.              minHeight: 30,
  89.              content: '<p class="fancybox-error">' + error + '</p>'
  90.              }],
  91.                     {
  92.                  padding: 0
  93.                  });
  94.                 else
  95.                  alert(error);
  96.             }
  97.         }
  98.     });
  99. }
  100.  
  101.  
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...