Jump to content

PS 1.7.x: Problem with Cookies? Sometime not working AddToCart


Pechy.cz

Recommended Posts

Hi,

first i want to apologize for bad English...

 

So..

I have big troubles with PS 1.7. ...

Problems was in version 1.7.0, now also in 1.7.2.

 

Sometime, when i click to Add product to cart, nothing happens (empty modal shows).

To explain it:

First is called ajax for adding to cart. -> result is success

Second is called ajax for refresh cart and display modal -> here is problem visible, because modal is show without product due to cart is still empty.

When i have some product in cart, this problem will not happen.

Its only when is cart empty and what's worst, only sometime.

I was spend lot of hours of debug and trying to reproduce, but without result.

 

So I discovered one problem, but I did not understand.

It will be something with cookies, because:

 

Several cases looked like when adding to a cart, a new cart was created, but after ajax/refresh this cart was not in cookie->id_cart. So every, when i click to add to cart, a new cart was created and ajax to show cart return empty cart.

More cases was after placing order. Cart was not removed from cookie after order. So immediately FrontController::init log error with loading cart, which has already been used for the order.

The customer also reported one problem that even after his logout, his cart remained at his disposal.

 

That's why I think there's a problem with Cookie...

Maybe bad server conf, i do not know.... 

 

I do not know what to do next...

Now iam on PS 1.7.2.0 and Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/7.0.21

Localhost is on PHP7.0.9, Windows, MAMP with Apache.

I have PS on SSL.

 

Has anyone encountered this problem?

Is there any quick fix for repair?

Edited by Pechy.cz (see edit history)
Link to comment
Share on other sites

Same here.

 

Prestashop 1.7.2.2

 

When adding to cart the first time its OK.

If I change to combination that has 2 minimal quantity I can add it to cart.

When I change back to where minimal quantity is 1 can't add to cart. In the html the minimal quantity is set to 2 (from the last product), not error message, nothing. The button doesn't work. Sometimes it adds for the second time 2 x last option selected (not the actual one).

Only can add minimum 2 where Minimum Quantity Required for this Option is 1.

 

It's happening from 1.7.2.0 I think.

 

Help please.

Link to comment
Share on other sites

  • 2 weeks later...

Same issue here. We even deleted and re-installed a fresh installation of 1.7.2...still having the issue, but can't replicate consistently or narrow down the exact cause.

 

Some notes:

1. Only happens when the cart is empty.

2. Sometimes turning ajax cart on and off in module settings will work but I don't understand why that would be.

3. Using Dev Console - Cart shows post to cart as "True" and ajax shows "sucessfully added to cart"...but no picture/price/qty shows in the cart display. Clicking to checkout shows you have an empty cart.

 

This is output when it works:

Cart Output:

  1. success: true, id_product: 1, id_product_attribute: 0, quantity: 1,…}
    1. cart:{products: [,…], totals: {total: {type: "total", label: "Total", amount: 15.75, value: "CA$15.75"},…},…}
    2. id_product:1
    3. id_product_attribute:0
    4. quantity:1
    5. success:true
    6.  
    7.  
    8.  

Ajax output:

  1.  
    1. {,…}
      1. modal:"<div id="blockcart-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">↵ <div class="modal-dialog" role="document">↵ <div class="modal-content">↵ <div class="modal-header">↵ <button type="button" class="close" data-dismiss="modal" aria-label="Close">↵ <span aria-hidden="true">×</span>↵ </button>↵ <h4 class="modal-title h6 text-sm-center" id="myModalLabel"><i class="material-icons"></i>Product successfully added to your shopping cart</h4>↵ </div>↵ <div class="modal-body">↵ <div class="row">↵ <div class="col-md-5 divide-right">↵ <div class="row">↵ <div class="col-md-6">↵ <img class="product-image" src="https://myshopnamehere.com/shop/1-home_default/laundry-soap.jpg" alt="" title="" itemprop="image">↵ </div>↵ <div class="col-md-6">↵ <h6 class="h6 product-name">Laundry Soap</h6>↵ <p>CA$10.50</p>↵ ↵ <p><strong>Quantity:</strong> 1</p>↵ </div>↵ </div>↵ </div>↵ <div class="col-md-7">↵ <div class="cart-content">↵ <p class="cart-products-count">There is 1 item in your cart.</p>↵ <p><strong>Total products:</strong> CA$10.50</p>↵ <p><strong>Total shipping:</strong> CA$5.25 </p>↵ <p><strong>Included taxes</strong> CA$0.75</p>↵ <p><strong>Total:</strong> CA$15.75 (tax incl.)</p>↵ <div class="cart-content-btn">↵ <button type="button" class="btn btn-secondary" data-dismiss="modal">Continue shopping</button>↵ <a href="//myshopnamehere.com/shop/en/cart?action=show" class="btn btn-primary"><i class="material-icons"></i>Proceed to checkout</a>↵ </div>↵ </div>↵ </div>↵ </div>↵ </div>↵ </div>↵ </div>↵</div>↵"
      2. preview:"<div id="_desktop_cart">↵ <div class="blockcart cart-preview active" data-refresh-url="//myshopnamehere.com/shop/en/module/ps_shoppingcart/ajax">↵ <div class="header">↵ <a rel="nofollow" href="//myshopnamehere.com/shop/en/cart?action=show">↵ <i class="material-icons shopping-cart">shopping_cart</i>↵ <span class="hidden-sm-down">Cart</span>↵ <span class="cart-products-count">(1)</span>↵ </a>↵ </div>↵ </div>↵</div>↵"
    2.  
    3.  
    4.  
    5.  
  2.  
  3.  
  4. Output when it doesn't:
  5. Cart Output:
    1. {success: true, id_product: 1, id_product_attribute: 0, quantity: 1,…}
      1. cart:{products: [,…], totals: {total: {type: "total", label: "Total", amount: 15.75, value: "CA$15.75"},…},…}
      2. id_product:1
      3. id_product_attribute:0
      4. quantity:1
      5. success:true
      6.  
      7.  

Ajax output:

 

    1. {,…}
      1. modal:"<div id="blockcart-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">↵ <div class="modal-dialog" role="document">↵ <div class="modal-content">↵ <div class="modal-header">↵ <button type="button" class="close" data-dismiss="modal" aria-label="Close">↵ <span aria-hidden="true">×</span>↵ </button>↵ <h4 class="modal-title h6 text-sm-center" id="myModalLabel"><i class="material-icons"></i>Product successfully added to your shopping cart</h4>↵ </div>↵ <div class="modal-body">↵ <div class="row">↵ <div class="col-md-5 divide-right">↵ <div class="row">↵ <div class="col-md-6">↵ <img class="product-image" src="" alt="" title="" itemprop="image">↵ </div>↵ <div class="col-md-6">↵ <h6 class="h6 product-name"></h6>↵ <p></p>↵ ↵ <p><strong>Quantity:</strong> </p>↵ </div>↵ </div>↵ </div>↵ <div class="col-md-7">↵ <div class="cart-content">↵ <p class="cart-products-count">There is 0 item in your cart.</p>↵ <p><strong>Total products:</strong> CA$0.00</p>↵ <p><strong>Total shipping:</strong> Free </p>↵ <p><strong>Included taxes</strong> CA$0.00</p>↵ <p><strong>Total:</strong> CA$0.00 (tax incl.)</p>↵ <div class="cart-content-btn">↵ <button type="button" class="btn btn-secondary" data-dismiss="modal">Continue shopping</button>↵ <a href="//myshopnamehere.com/shop/en/cart?action=show" class="btn btn-primary"><i class="material-icons"></i>Proceed to checkout</a>↵ </div>↵ </div>↵ </div>↵ </div>↵ </div>↵ </div>↵ </div>↵</div>↵"
      2. preview:"<div id="_desktop_cart">↵ <div class="blockcart cart-preview inactive" data-refresh-url="//myshopnamehere.com/shop/en/module/ps_shoppingcart/ajax">↵ <div class="header">↵ <i class="material-icons shopping-cart">shopping_cart</i>↵ <span class="hidden-sm-down">Cart</span>↵ <span class="cart-products-count">(0)</span>↵ </div>↵ </div>↵</div>↵"

 

 

Any ideas??? Fighting this ghost for 2 weeks now.

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

Hi,

i dont know, if is issue for you, but we finally found our problem.

 

We have fresh install PS 1.7.x, but we migrate data from old store (customers/products/orders).

And here was the problem.

 

We migrate old orders, where have id_cart saved.

But carts are not migrated, then started with id from 1.

 

So, when id_cart was same with id_cart from old order, here was a problem a cart cannot be use. (Due to protection of using carts with finished orders)

 

So solution was go to database and increase AUTOINCREMENT for column id in table cart to higher, than is higher id_cart in orders.

Edited by Pechy.cz (see edit history)
  • Like 4
  • Thanks 1
Link to comment
Share on other sites

Genius! :) Many thanks. Just cross checked carts missing in action against carts that actually got built and you are correct. There is a conflict between old orders created from carts in our last PS installation and our new store. Thank you! Setting the operand of AUTOINCREMENT past highest number showing in orders looks like it solved the issue and makes sense as to why it seemed random.

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

  • 1 year later...
  • 2 months later...

Please check my problem which might be related to this topic. Note that shop URL might be in maintenance mode.

Quote

I tried auto-increment solution but didn't work. I'm not sure if I did it correctly or not.

Example: In ps_orders table, if last (or highest) id_cart is 30, then I have to set auto-increment of id_cart to 31 in ps_cart table. Is it right?

Link to comment
Share on other sites

12 hours ago, roo10 said:

Please check my problem which might be related to this topic. Note that shop URL might be in maintenance mode.

I tried auto-increment solution but didn't work. I'm not sure if I did it correctly or not.

Example: In ps_orders table, if last (or highest) id_cart is 30, then I have to set auto-increment of id_cart to 31 in ps_cart table. Is it right?

Just setting the operand of AUTOINCREMENT in ps_cart table 1 or 2 numbers higher than the id_cart in ps_orders table did not work for us. We actually set the AUTOINCREMENT in ps_cart table way further ahead. Our imported database was showing something like a cart value of 1015 so we just started new cart ids at 3000 autoincrementing by 1 after that. THAT fixed our problem.

If you are importing data from an older 1.6 store - I challenge your cart number only being at 30. That number sounds really small unless you don't get much traffic on your site. I think you might be looking at a wrong column in the table.

I should also mention, when you're doing testing and having issues, its a good practice to do test carts using a private or incognito tab or page. Especially with Google Chrome browser, we've seen some pretty frustrating issues caused by the browser not letting go of cached pages as well as elements from pages.

Hope this helps.

K

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

Thanks for replying.

Of course, my old store don't have 30 carts but it was just an example. The imported data from 1.6 store has nearly 55k+ carts so I set auto increment value to 60k and ran the site in private tab but still not working for us.

Stating from your earlier post in this topic, I'm also getting this: Using Dev Console - Cart shows post to cart as "True" and ajax shows "successfully added to cart"...but no picture/price/qty shows in the cart display. Clicking to checkout shows you have an empty cart.

Link to comment
Share on other sites

9 hours ago, roo10 said:

Thanks for replying.

Of course, my old store don't have 30 carts but it was just an example. The imported data from 1.6 store has nearly 55k+ carts so I set auto increment value to 60k and ran the site in private tab but still not working for us.

Stating from your earlier post in this topic, I'm also getting this: Using Dev Console - Cart shows post to cart as "True" and ajax shows "successfully added to cart"...but no picture/price/qty shows in the cart display. Clicking to checkout shows you have an empty cart.

Please see Sebastien MAS and Pechy.cz quotes above. I still maintain you have an issue from migrating. I am not an expert on the versions, but I know there are differences in the database structure between 1.6 and 1.7 and it still sounds like PS_Orders not matching with PS_Carts. If it works sometimes and not others to build a cart - I guarantee this is the problem. Your configuration looks good for 1.7. 

Quote

I'm also getting this: Using Dev Console - Cart shows post to cart as "True" and ajax shows "successfully added to cart"...but no picture/price/qty shows in the cart display. Clicking to checkout shows you have an empty cart.

This confirms you're cart IS being built - but your checkout IS NOT pulling the right cart information. It only makes sense that PS_Orders is not synced with PS_Carts. 

If you find a solution outside of this post, please update here so others can also benefit.

Link to comment
Share on other sites

Truncating those tables won't change the AUTO INCREMENT value. It just destroys your order history and can possibly break your database. The tables will be empty, but the AUTO INCREMENT operand will still be left at the last known value so truncating will only delete carts and orders and breaks links to other tables that use that information.

If you are at this point and willing to delete histories by truncating, you might be better off just doing a fresh install of 1.7.x and starting over clean. Use a migration module to import just your customer information and not the order history. (There should be a few modules available to do this in the PrestaShop add-ons shop). 

The issue you are dealing with is typically caused by importing order information from a different version into a new database. The table cells are  brought over, but the AUTO INCREMENT values of those tables are not. The operands need to be adjusted as Pechy.cz noted in the above threads.

Link to comment
Share on other sites

I'm not in a state to start with fresh installation of 1.7 because I need all the data from old store. I only performed this operation on test store to check whether the id_cart syncing actually fixes the issue or not.

I think you're getting confused with TRUNCATE and DELETE queries. Both the queries remove data from a table but there is one difference.

TRUNCATE query resets the auto increment ID to 1 whereas DELETE query doesn't and starts the auto increment ID from where last ID was left off.

So after truncating ps_orders and ps_cart tables, their auto increment ID will start from 1.

To summarize, I adjusted the id_cart value as Pechy.cz suggested and also tried with truncating the tables but still didn't fix the issue.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

I have a similar problem, 'add to the cart' button generates new cart_id after every click and shows zero in modal, but response has full cart info and product in array, even after changing autoincrement in ps_cart table to high number 150000 - problem still exists

I have migrated from version 1.6 to 1.7

 

presta.jpg

Link to comment
Share on other sites

  • 1 month later...
On 1/19/2020 at 9:58 PM, marty12321 said:

I have a similar problem, 'add to the cart' button generates new cart_id after every click and shows zero in modal, but response has full cart info and product in array, even after changing autoincrement in ps_cart table to high number 150000 - problem still exists

I have migrated from version 1.6 to 1.7

 

presta.jpg

Hi, i have the same problem after upgrating 1.6 to 1.7.

Do you find the solution ?

Thanks

Link to comment
Share on other sites

  • 1 year later...

Check my comment for explication
https://github.com/PrestaShop/PrestaShop/issues/15878#issuecomment-925429973

No fix for now, apart from removing the check of cookie existence (bot could create ghost cart if this check is removed)

Otherwise you could improve the method exists() of the Cookie class which is too basic and can differentiate real customer from bots.

Link to comment
Share on other sites

  • 4 months later...
  • 9 months later...
On 9/16/2017 at 11:13 PM, kellyriverstone said:

Genius! :) Many thanks. Just cross checked carts missing in action against carts that actually got built and you are correct. There is a conflict between old orders created from carts in our last PS installation and our new store. Thank you! Setting the operand of AUTOINCREMENT past highest number showing in orders looks like it solved the issue and makes sense as to why it seemed random.

I have exact the same issue...

cart messages are mixed up for some customers.. (showing messages from other customers as their message)

also cart sometimes seems to show products from other carts from other customers too

The site was migrated from 1.6 to 1.7

 

To my case, ps_cart has 3 times higher AUTOINCREMENT value than ps_orders

 

any idea? it's really frustrating.. 

 

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