Jump to content

Error deleting or decreasing products in cart


Recommended Posts

Hi!

 

I'm having a big problem that I've been trying to solve for some time now. I have searched the forum and Google for an answer but no fix helps. I really need help with this since I believe that this error causing me to loose many sales.

 

If I try to delete a product from the cart or decrease the quantity I get the following error message:

 

TECHNICAL ERROR: unable to save update quantity Details: Error thrown: [object Object] Text status: parsererror

 

If I hit refresh the product has actually been deleted but I dont think all my customers will try that, they will also get a blank screen if it was only one product in the cart and blanks screens are of course not good.

 

I run Prestashop 1.6.0.9

My site is www .afrostore.se

 

Is there some one who has a fix for this?

 

Hoping for the best!

Anni
 

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...

This is definetely an error in the returned json response, which probably contains some exception instead of a properly formatted json response. I have seen this before. 

 

One of your modules might throw an error. I would try first to disable all non-standard modules (there's an option in the backoffice to do that, you don't have to go through all modules) and see if it works. If yes, then go one by one through the additional modules you have installed, disabling them and testing again until you find the culprit. 

 

If however you get still the same error with the non-standard modules disabled, then the error must occur somewhere from the original code. 

 

In general, you need to see the responde the javascript is getting back usually, this should give you the hints needed to figure out the proble. If you are a developer this should be easy. You find in cart-summary.js an ajax call and in it's success function, you add a console.log() output.

 

Take as example this function: 

function deleteProductFromSummary(id)
{
	var customizationId = 0;
	var productId = 0;
	var productAttributeId = 0;
	var id_address_delivery = 0;
	var ids = 0;
	ids = id.split('_');
	productId = parseInt(ids[0]);
	if (typeof(ids[1]) !== 'undefined')
		productAttributeId = parseInt(ids[1]);
	if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
		customizationId = parseInt(ids[2]);
	if (typeof(ids[3]) !== 'undefined')
		id_address_delivery = parseInt(ids[3]);
	$.ajax({
		type: 'POST',
		headers: { "cache-control": "no-cache" },
		url: baseUri + '?rand=' + new Date().getTime(),
		async: true,
		cache: false,
		dataType: 'json',
		data: 'controller=cart'
			+ '&ajax=true&delete=true&summary=true'
			+ '&id_product='+productId
			+ '&ipa='+productAttributeId
			+ '&id_address_delivery='+id_address_delivery
			+ ((customizationId !== 0) ? '&id_customization=' + customizationId : '')
			+ '&token=' + static_token
			+ '&allow_refresh=1',
		success: function(jsonData)
		{
                        console.log(jsonData);
			if (jsonData.hasError)
			{
				var errors = '';
				for(var error in jsonData.errors)
					//IE6 bug fix
					if(error !== 'indexOf')
						errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
									if (!!$.prototype.fancybox)
											$.fancybox.open([
													{
															type: 'inline',
															autoScale: true,
															minHeight: 30,
															content: '<p class="fancybox-error">' + errors + '</p>'
													}],
													{
															padding: 0
													});
									else
											alert(errors);
			}
			else
			{
				if (jsonData.refresh)
					location.reload();
				if (parseInt(jsonData.summary.products.length) == 0)
				{
					if (typeof(orderProcess) == 'undefined' || orderProcess !== 'order-opc')
						document.location.href = document.location.href; // redirection
					else
					{
						$('#center_column').children().each(function() {
							if ($(this).attr('id') !== 'emptyCartWarning' && $(this).attr('class') !== 'breadcrumb' && $(this).attr('id') !== 'cart_title')
							{
								$(this).fadeOut('slow', function () {
									$(this).remove();
								});
							}
						});
						$('#summary_products_label').remove();
						$('#emptyCartWarning').fadeIn('slow');
					}
				}
				else
				{
					$('#product_' + id).fadeOut('slow', function() {
						$(this).remove();
						cleanSelectAddressDelivery();
						if (!customizationId)
							refreshOddRow();
					});
					var exist = false;
					for (i=0;i<jsonData.summary.products.length;i++)
					{
						if (jsonData.summary.products[i].id_product == productId
							&& jsonData.summary.products[i].id_product_attribute == productAttributeId
							&& jsonData.summary.products[i].id_address_delivery == id_address_delivery
							&& (parseInt(jsonData.summary.products[i].customization_quantity) > 0))
								exist = true;
					}
					// if all customization removed => delete product line
					if (!exist && customizationId)
						$('#product_' + productId + '_' + productAttributeId + '_0_' + id_address_delivery).fadeOut('slow', function() {
							$(this).remove();
							var line = $('#product_' + productId + '_' + productAttributeId + '_nocustom_' + id_address_delivery);
							if (line.length > 0)
							{
								line.find('input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){
									if (typeof($(this).attr('name')) != 'undefined')
										$(this).attr('name', $(this).attr('name').replace(/nocustom/, '0'));
									if (typeof($(this).attr('id')) != 'undefined')
										$(this).attr('id', $(this).attr('id').replace(/nocustom/, '0'));
								});
								line.find('span[id^=total_product_price_]').each(function(){
									$(this).attr('id', $(this).attr('id').replace(/_nocustom/, ''));
								});
								line.attr('id', line.attr('id').replace(/nocustom/, '0'));
							}
							refreshOddRow();
						});
				}
				updateCartSummary(jsonData.summary);
				if (window.ajaxCart != undefined)
					ajaxCart.updateCart(jsonData);
				updateCustomizedDatas(jsonData.customizedDatas);
				updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
				updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
				if (typeof(getCarrierListAndUpdate) !== 'undefined' && jsonData.summary.products.length > 0)
					getCarrierListAndUpdate();
				if (typeof(updatePaymentMethodsDisplay) !== 'undefined')
					updatePaymentMethodsDisplay();
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			if (textStatus !== 'abort')
			{
				var error = "TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus;
				if (!!$.prototype.fancybox)
				    $.fancybox.open([
			        {
			            type: 'inline',
			            autoScale: true,
			            minHeight: 30,
			            content: '<p class="fancybox-error">' + error + '</p>'
			        }],
					{
				        padding: 0
				    });
				else
				    alert(error);
			}
		}
	});
}

I've added below that line: 

success: function(jsonData)

the following:

console.log(jsonData);

Now open the browser inspector, try reducing the quantity (if the quantity turns zero, the delete function modified here is called too) or delete the product from cart and check your console output. It should be showing you what the response and as that the possible exception was. 

Link to comment
Share on other sites

Correction after seeing the error message again, I had something else in mind that doesn't apply here. 

 

You need actually to output the data in the error: section of the ajax call, not the success: section. As that's the part that is being executed here. 

 

The code: 

console.log(XMLHttpRequest);

This will show you all the data, that is shown only as "[object Object]" in Prestashop's error message, which isn't helpful. 

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

Ugh, this doesn't show anything suspicious, you can try temporary comment this code below, remove this code from me and try to comment these two lines with if clause

 

After all you can try to disable non native modules and overrides by switichng options in Advanced Parameters -> Performance

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

Totti, the function updateCarrierSelectionAndGift() is required only for the one-page-checkout, not the 5-step checkout. It also is defined in the javascript that is only loaded with the one-page-checkout. 

 

On your page you have the 5-step checkout active though. You might be using some module that doesn't properly distinguish between them. 

 

As you have the option to compress Javascripts I can't see in which file this occurs. Can you deactivate it, so I might be able to tell you then exactly what to modify?

Link to comment
Share on other sites

×
×
  • Create New...