Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CartRule->checkValidity FatalThrowableError #36115

Closed
2 tasks done
Eva-F opened this issue May 8, 2024 · 3 comments
Closed
2 tasks done

CartRule->checkValidity FatalThrowableError #36115

Eva-F opened this issue May 8, 2024 · 3 comments
Labels
Bug Type: Bug

Comments

@Eva-F
Copy link

Eva-F commented May 8, 2024

Prerequisites

Describe the bug and add attachments

when using a plugin that is connected to "hookActionCartSave", we get a FatalThrowableError in the CartRule->checkValidity function for older cookies.
These legacy cookies contain id_cart, which refer to a no longer existing record in table DB_PREFIX.'cart' (table DB_PREFIX.'cart' is periodically deleted by the abandoned cart plugin)
checkValidity1

Expected behavior

the problem imho is caused that $context->cart is not set

this simple patch of /classes/controller/FrontController.php solves our problem

   public function init()
// ...
        if ((int) $this->context->cookie->id_cart) {

            if (!isset($cart)) {
                $cart = new Cart($this->context->cookie->id_cart);
            }
            if (Validate::isLoadedObject($cart) && $cart->orderExists()) {
// ...

change to:

   public function init()
// ...
        if ((int) $this->context->cookie->id_cart) {

            if (!isset($cart)) {
                $cart = new Cart($this->context->cookie->id_cart);
            }
// adding lines 
	}
        if (isset($cart) && $cart->id && isset($context->cart) ) {
// adding lines 

            if (Validate::isLoadedObject($cart) && $cart->orderExists()) {
// ...

Steps to reproduce

PrestaShop version(s) where the bug happened

1.7.8.11

PHP version(s) where the bug happened

7.3.33

If your bug is related to a module, specify its name and its version

No response

Your company or customer's name goes here (if applicable).

No response

@Eva-F Eva-F added Bug Type: Bug New New issue not yet processed by QA labels May 8, 2024
@Hlavtox
Copy link
Contributor

Hlavtox commented May 8, 2024

@Eva-F Hi, can you please provide a clearly reproducible scenario so we can test this? I fixed a very related issue to this - #33954, so I am interested if this isn't maybe also fixed?

Something like:

  • Install module XY that hooks into actionCartSave.
  • Create cart
  • Create cart rule with settings A, B, C
  • Delete this cart in database
  • Go to FO bla bla bla

Thanks!

@Eva-F
Copy link
Author

Eva-F commented May 9, 2024

my sorry - I didn't realized all consequences of placing the condition

isset($context->cart)

should by just before

$cart->update();

this way

 if ($to_update&& isset($context->cart)  ) {
      $cart->update();
 }

To @Hlavtox

I am not able to describe the exact steps because I am only an external consultant who should try to solve the urgent problems with the eshop.

The tricky was that the cookie contained id_cart, which was created say 2 months ago and the related order was not created. Moreover (maybe) here played its role a voucher (here i am not sure) - the error occured thanks the affiliate plugin, that hooks "hookActionCartSave")
In db was this cart removed as abandoned and this obsolete cookie was a source of problem when FrontController initialized

And yes

also ComputingPrecision->getPrecision() error occured before and was patched the similiar way as you did

but $cart->update() is called twice in init and our problem cas was related on /* Select an address if not set */

@florine2623
Copy link
Contributor

Closing the issue as it cannot be reproduce on a native shop

@florine2623 florine2623 removed the New New issue not yet processed by QA label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants