Jump to content

Edit History

philoupin

philoupin


Clarification of issue / solution

+++ EDIT September 2019 ++++

Don't apply the "fix" described below in PHP,  since it just fixes some symptoms (not all) and is not a solution to the source of the problem.

You probably have a javascript error somewhere, preventing correct execution of another script. Most probably this error is due to an incompatibility of a module/plugin.

+++ END EDIT +++

On our installation of PS 1.7.4.4 we got reports of some customers, that they could not add products to the cart. A click on the button "Add to cart" took the customer to the view of the cart contents which said "no items in cart" or something like this. The modal dialog "product added to cart" we ourselves usually see at this point with the option to continue shopping or go to checkout was not appearing. The customer was using Windows 10 with the "lastest version of Firefox" but we could only duplicate this faulty behaviour with Internet Explorer on Windows 10.

The option to "disable ajax" in the shopping cart module settings did not solve this problem.

Finally we discovered that in controllers/front/CartController.php around line 231 this condition was failing:

if (Tools::getIsset('add') || Tools::getIsset('update')) {
    $this->processChangeProductInCart();
}

On the faulty system the POST values did not contain the variables add=1 action=update which were being POSTed on a setup where adding to cart was working for us as expected. It seems that in themes/core.js around line 1753 these values are added via javascript (see last line):

$body.on('click', '[data-button-action="add-to-cart"]', function (event) {
  event.preventDefault();
  if ((0, _jquery2['default'])('#quantity_wanted').val() > (0, _jquery2['default'])('[data-stock]').data('stock') && (0, _jquery2['default'])('[data-allow-oosp]').data('allow-oosp').length === 0) {
    (0, _jquery2['default'])('[data-button-action="add-to-cart"]').attr('disabled', 'disabled');
  } else {
    var _ret = (function () {
      var $form = (0, _jquery2['default'])(event.target).closest('form');
      var query = $form.serialize() + '&add=1&action=update';

Our solution consisted in modifying /themes/YOURTHEME/templates/catalog/product.tpl to add two hidden fields with name="add" and name="action" around line 101:

<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
  <input type="hidden" name="token" value="{$static_token}">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="action" value="update">
  <input type="hidden" name="id_product" value="{$product.id}" id="product_page_product_id">
  <input type="hidden" name="id_customization" value="{$product.id_customization}" id="product_customization_id">

In our previously functioning environment, these values are now posted twice, resulting in "add" and "action" becoming arrays, but it still seems to be working. These are the POSTed values

token	93865fd2ed163bfa72111fcbe7a39xyz
add	[…]
0	1
1	1
action	[…]
0	update
1	update
id_product	4
id_customization	0
group[1]	25
group[5]	31
qty	1

Although we have resolved our immediate problem for now, we would prefer to understand why the add-to-cart-button doesn't degrade gracefully to still function on an older browser or system. As I stated above our customer was himself on the "current version" of Firefox (we were unfortunately not able to confirm the version number), so it definitely is not just a a problem of very old browsers.

Any hints would be appreciated and if nothing else, maybe this will help someone stumbling upon the same issue.

 

 

 

philoupin

philoupin

On our installation of PS 1.7.4.4 we got reports of some customers, that they could not add products to the cart. A click on the button "Add to cart" took the customer to the view of the cart contents which said "no items in cart" or something like this. The modal dialog "product added to cart" we ourselves usually see at this point with the option to continue shopping or go to checkout was not appearing. The customer was using Windows 10 with the "lastest version of Firefox" but we could only duplicate this faulty behaviour with Internet Explorer on Windows 10.

The option to "disable ajax" in the shopping cart module settings did not solve this problem.

Finally we discovered that in controllers/front/CartController.php around line 231 this condition was failing:

if (Tools::getIsset('add') || Tools::getIsset('update')) {
    $this->processChangeProductInCart();
}

On the faulty system the POST values did not contain the variables add=1 action=update which were being POSTed on a setup where adding to cart was working for us as expected. It seems that in themes/core.js around line 1753 these values are added via javascript (see last line):

$body.on('click', '[data-button-action="add-to-cart"]', function (event) {
  event.preventDefault();
  if ((0, _jquery2['default'])('#quantity_wanted').val() > (0, _jquery2['default'])('[data-stock]').data('stock') && (0, _jquery2['default'])('[data-allow-oosp]').data('allow-oosp').length === 0) {
    (0, _jquery2['default'])('[data-button-action="add-to-cart"]').attr('disabled', 'disabled');
  } else {
    var _ret = (function () {
      var $form = (0, _jquery2['default'])(event.target).closest('form');
      var query = $form.serialize() + '&add=1&action=update';

Our solution consisted in modifying /themes/YOURTHEME/templates/catalog/product.tpl to add two hidden fields with name="add" and name="action" around line 101:

<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
  <input type="hidden" name="token" value="{$static_token}">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="action" value="update">
  <input type="hidden" name="id_product" value="{$product.id}" id="product_page_product_id">
  <input type="hidden" name="id_customization" value="{$product.id_customization}" id="product_customization_id">

In our previously functioning environment, these values are now posted twice, resulting in "add" and "action" becoming arrays, but it still seems to be working. These are the POSTed values

token	93865fd2ed163bfa72111fcbe7a39xyz
add	[…]
0	1
1	1
action	[…]
0	update
1	update
id_product	4
id_customization	0
group[1]	25
group[5]	31
qty	1

Although we have resolved our immediate problem for now, we would prefer to understand why the add-to-cart-button doesn't degrade gracefully to still function on an older browser or system. As I stated above our customer was himself on the "current version" of Firefox (we were unfortunately not able to confirm the version number), so it definitely is not just a a problem of very old browsers.

Any hints would be appreciated and if nothing else, maybe this will help someone stumbling upon the same issue.

 

 

 

×
×
  • Create New...