Jump to content

[SOLVED] Problem while adding cart rules manually and trying to show them in the Cart Summary


Nopa Kga

Recommended Posts

I have a very strange problem and I am not sure is it related to a wrong configuration or I most probably I am doing the things in wrong way.

 

We use Prestashop 1.5.6

 

We need to add some custom cart rules, when a product is added to the cart ,so the rules are shown in the cart summary details and calculated in the total price

 

Due to multiple factors I decided to do it in maybe the "worst" possible way: to add records in cart_cart_rule tables

 

In my local dev environment it worked like a charm, but in the dev server the manually added rules constantly disapeared from the database after refresh of the "Shopping Cart-Summary" page

 

After I swtiched on the profiler I've noticed the following sql request: 

 

0.072 ms DELETE FROM `cart_cart_rule` WHERE `id_cart_rule` = 44 AND `id_cart` = 99 LIMIT 1
in /var/www/clients/client224/web844/web/shopx3/classes/Cart.php:1138

 

And it is _updateCustomizationQuantity method. Debugging the callstack to figure out what is the problem in the dev server seems like a very cumbersome task. 

 

I tried to modify Cart.php just to figure out what is calling that method with no success. Whatever I do the records in the cart_cart_rule I try to manually add are always deleted.

 

So I ask you. Do anyone of you have an idea what would be the reason _updateCustomizationQuantity to be called and why after update , the manually added records in the cart_cart_rule table are deleted

 

Thanks in advance

 

Best regards... 

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

Ok I got the problem

 

When refreshing the Cart Summary, CartRule::autoRemoveFromCart method was called ,which at some point checks the validity of all the cart rules. The cart rules I create failed to pass validation, so they were deleted with an error message: 'You cannot use this voucher'

 

Because of some reason, maybe the installed theme, the error message was not shown, so I didn't know whats going on. To make the things even worst, the Cart.php file was different from the one in my local dev machine, so when the profiler shows the DELETE database request executed at some line number, it pointet to a totally different code in my local Cart.php.  I was totally misleaded.

 

Anyway

 

A I guess a relevant conclusion for anyone having similar problems with disappearing cart rules would be:  

 

Every cart rule is checked for validity and if it does not pass the validation, it is automatically removed from the cart_cart_rule table. 

 

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