Jump to content
philoupin

[PARTIALLY SOLVED] PS 1.7 Add product to cart not working

Recommended Posts

Posted (edited)

+++ 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.

 

 

 

Edited by philoupin
Clarification of issue / solution (see edit history)

Share this post


Link to post
Share on other sites

Possibly part of the same problem we get reposts that the final "order" button isn't working for these same customers. There too the POSTing is done via Javascript. 

In my opinion the "add to cart" and "place order" buttons are among the most important buttons in the shop and should be as compatible as possible also with older browsers.

I am trying to gather more info about the customer PC system on which the error occurs, we can currently only reproduce it on Internet Explorer on Windows 10. Not the most modern setup, however, customers who can't order are always right 🙂

 

Any help or pointers would be much appreciated!

P.

 

Share this post


Link to post
Share on other sites

Our problem was due to the module Newsletter Pro which now has received an update to version 4.8.6 which solves our problem.

Share this post


Link to post
Share on other sites

Hi, I have this problem. Internet Explorer 11 = does not allow anyone add to cart.

 

What did you do to fix this? I am really desperate to get this fixed ASAP. Could you explain what exactly fixed this problem for you?

 

Thank you !

Share this post


Link to post
Share on other sites
On 1/11/2019 at 11:13 AM, philoupin said:

Our problem was due to the module Newsletter Pro which now has received an update to version 4.8.6 which solves our problem.

Quote for notification. I would appreciate any help!! Thank you.

Share this post


Link to post
Share on other sites

I made the change you put in your original post - It now adds to cart on Internet Explorer, but only on the product page (not on the homepage "quick add to cart" button).

 

I also noticed it doesn't let you modify the amount ordered in the checkout on IE. And on all the other browsers, if you choose a quantity of 2, it doubles to 4.

 

:( This is really disappointing. I need this fixed or I am going to give up with PrestaShop. It has been nothing but trouble since installing it. Cannot even update to the latest version without it breaking my store. Really annoying me now and I am sick of the constant problems.

Share this post


Link to post
Share on other sites

Hi Sampsonzak,

I would not recommend that you use the fix I posted above, as it did not solve the source of the problem, just fix some symptoms. If I remember well, the source of the problem was in a javascript not loading in IE. For us this javascript was part of the Newsletter Pro plugin. i suggest you look at the javascript console of Internet Explorer, there it may tell you what javascript is causing problems, if this is in fact the same problem you are having.

Best regards,

p.

Share this post


Link to post
Share on other sites
4 minutes ago, philoupin said:

Hi Sampsonzak,

I would not recommend that you use the fix I posted above, as it did not solve the source of the problem, just fix some symptoms. If I remember well, the source of the problem was in a javascript not loading in IE. For us this javascript was part of the Newsletter Pro plugin. i suggest you look at the javascript console of Internet Explorer, there it may tell you what javascript is causing problems, if this is in fact the same problem you are having.

Best regards,

p.

Hi, thanks for the reply.

 

I am really clueless about errors with javascript - I only know basic PHP/HTML/CSS. No idea about Javascript or jQuery though.

 

The "error" IE is showing in it's console is a "syntax error", which points to this line of JavaScript code RE the cart:

> prestashop.on('updateCart',(params)=>{if(typeof(params)!=='undefined'&&typeof(prestashop.cart)!=='undefined'){var iso_code=prestashop.currency.iso_code,products=prestashop.cart.products,my_id=params.reason.idProduct,

 

Does anything in that maybe stick out to you as incorrect syntax?

 

Really appreciate if you could help. I only have the default modules installed: Newsletter Block / and a Newsletter Block which came with my theme also ?

Share this post


Link to post
Share on other sites

It's actually saying the invalid syntax is this bit:

 

prestashop.on('updateCart',(params)=>{    <---- {{{{{

 

Any idea if this is right by taking a quick look? 😕 No idea what to do here.

 

Share this post


Link to post
Share on other sites

Wow ! Never mind, I have found the problem!!

 

If anyone has this issue, my issue is caused by the 'Official Facebook Pixel' plugin by PrestaShop. Wow!!

 

Works flawlessly on Internet Explorer now. Now I need to find a fix for this Pixel plugin. Did not expect that to be the issue!!

 

Thank you OP for making me look into the javascript error a bit more. Thank you ! :D

Share this post


Link to post
Share on other sites

Did you learn any javascript debugging? I am clueless on how to do this.

We have bug that need javascript debugging/comparison:

Changing product quantity on check-out page on 1.6.1.4 v is causing bug in our webpage. The strange thing is that if we continue to payment and then go back to checkout it is possible to change product quantity and the bug does not occur.

Share this post


Link to post
Share on other sites
6 minutes ago, MacMaster said:

Did you learn any javascript debugging? I am clueless on how to do this.

We have bug that need javascript debugging/comparison:

Changing product quantity on check-out page on 1.6.1.4 v is causing bug in our webpage. The strange thing is that if we continue to payment and then go back to checkout it is possible to change product quantity and the bug does not occur.

I just inspected element in microsoft and I saw the issue was pointing to a bracket - I followed the bracket until the end and then I noticed javascript relating to a plugin was at the end of it, disabled the plugin and it worked flawlessly.

 

If you send me your link and the steps I will take a look and see if I can find anything by the same way I checked mine out if you'd like

Share this post


Link to post
Share on other sites

Just sent you details in message. Let me know if you have questions. Would prefer not to share webpage details publicly since webshop is live.

Edited by MacMaster (see edit history)

Share this post


Link to post
Share on other sites

I managed to resolve the issue. I uninstalled the "Advanced One Page Checkout". Installed the  "One Page Checkout for Prestashop v2.3.2" with error. Uninstalled it again and reinstalled the  "Advanced One Page Checkout" again. Suddenly it worked correctly.

(It seems some table or stuff was missing in the override, because just uninstalling and reinstall the "Advanced One Page Checkout" did not fix it. It required temporary installation of other checkout to reset the issue. )

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More