Gouravdev Posted January 23, 2022 Share Posted January 23, 2022 Hi Team, Can you please help me, as I've found that the $this->context->cart is null when product is added into the cart. recording : https://beta.claap.io/sendinblue/cart-is-null-c-3YfMIiN6mG-vI1bGz-C55V3? Thanks Link to comment Share on other sites More sharing options...
ps8modules Posted January 23, 2022 Share Posted January 23, 2022 Contact the author of the module. Turn on debug mode. Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 @4you.software I've enabled the debug mode. But do you've any idea why the context->cart is coming null Also, this issue is only coming for version 1.7.8.0 and above. Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 For reference: https://beta.claap.io/sendinblue/inbox-3YfMIiN6mG/AL7OcMGtoJMg Link to comment Share on other sites More sharing options...
ps8modules Posted January 23, 2022 Share Posted January 23, 2022 4 minutes ago, Gouravdev said: For reference: https://beta.claap.io/sendinblue/inbox-3YfMIiN6mG/AL7OcMGtoJMg Page not found. Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 5 minutes ago, Gouravdev said: @4you.software I've enabled the debug mode. But do you've any idea why the context->cart is coming null Also, this issue is only coming for version 1.7.8.0 and above. can you please help me with this, complete followhttps://beta.claap.io/sendinblue/inbox-3YfMIiN6mG/AL7OcMGtoJMg Link to comment Share on other sites More sharing options...
ps8modules Posted January 23, 2022 Share Posted January 23, 2022 3 minutes ago, Gouravdev said: can you please help me with this, complete followhttps://beta.claap.io/sendinblue/inbox-3YfMIiN6mG/AL7OcMGtoJMg Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 Sorry @4you.software here it's https://beta.claap.io/sendinblue/fatal-error-c-3YfMIiN6mG-AL7OcMGtoJMg Also, $this->context->cart is coming null? do you have any idea about it? thanks for the help 🙏🏻 Link to comment Share on other sites More sharing options...
knacky Posted January 23, 2022 Share Posted January 23, 2022 You are requesting support for a module that is not the original Prestashop. Not everyone has this module to give you advice. When you turn off the module, uninstall it, is it still the same error? Has Prestashop been upgraded? If so, what tool did you use to update your Prestashop? Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 Yes, I understand the case, but right now I'm trying to fix it at module end, I need help in fixing the issue, why the $this->context->cart is coming null? When a product is added into the cart. I'm fixing it my end not taking module support, Hope you guys help me out here Link to comment Share on other sites More sharing options...
ComGrafPL Posted January 23, 2022 Share Posted January 23, 2022 (edited) You did reset your cart module is that correct? PHP version? Edited January 23, 2022 by ComGrafPL (see edit history) Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 Just now, ComGrafPL said: You did reset your cart module is that correct? which one? Link to comment Share on other sites More sharing options...
ComGrafPL Posted January 23, 2022 Share Posted January 23, 2022 (edited) 3 minutes ago, Gouravdev said: which one? Cart one. Also check hooks. Maybe you have other module, that could interfere add to cart. Can you link your store here? Edited January 23, 2022 by ComGrafPL (see edit history) Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 8 minutes ago, ComGrafPL said: Cart one. Also check hooks. Maybe you have other module, that could interfere add to cart. Can you link your store here? its on the local system, I'm doing the debugging. -> Sendinblue module install -> login as new customer -> Add product into cart Fatal error occur. The hook is `hookActionCartSave` I want to know why the $this->context->cart is coming null? Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 Help me guys, I need to fix it urgently php version is above 5.6 Link to comment Share on other sites More sharing options...
ps8modules Posted January 23, 2022 Share Posted January 23, 2022 https://devdocs.prestashop.com/1.7/basics/installation/system-requirements/ PHP min. 7.1, recomended 7.4 It is not possible to identify and correct the error from your samples. Link to comment Share on other sites More sharing options...
Gouravdev Posted January 23, 2022 Author Share Posted January 23, 2022 Just now, 4you.software said: https://devdocs.prestashop.com/1.7/basics/installation/system-requirements/ PHP min. 7.1, recomended 7.4 It is not possible to identify and correct the error from your samples. @4you.software done I've updated the php to 7.2 Link to comment Share on other sites More sharing options...
Whatapk01 Posted January 23, 2022 Share Posted January 23, 2022 For reference: https://beta.claap.io/sendinblue/inbox-3YfMIiN6mG/AL7OcMGtoJMg Link to comment Share on other sites More sharing options...
Gouravdev Posted January 24, 2022 Author Share Posted January 24, 2022 13 hours ago, Whatapk01 said: For reference: https://beta.claap.io/sendinblue/inbox-3YfMIiN6mG/AL7OcMGtoJMg Yes what is in this Reference? Link to comment Share on other sites More sharing options...
knacky Posted January 24, 2022 Share Posted January 24, 2022 https://help.sendinblue.com/hc/en-us/articles/115001123645-PrestaShop-plugin-1-7-Installation-and-setup https://www.sendinblue.com/contact/ Link to comment Share on other sites More sharing options...
Gouravdev Posted January 24, 2022 Author Share Posted January 24, 2022 1 minute ago, knacky said: https://help.sendinblue.com/hc/en-us/articles/115001123645-PrestaShop-plugin-1-7-Installation-and-setup https://www.sendinblue.com/contact/ I know that, but I want to know why it's coming as null when product is added. Link to comment Share on other sites More sharing options...
knacky Posted January 24, 2022 Share Posted January 24, 2022 You should visit the Indian Forum, they will understand you there. You have a few important questions that can solve your problem. You didn't answer either. Probably no one will advise you here anymore. You can start a Job and someone may solve your problem.You've dealt with it in more discussions. I apologize for my brief statement and for not being able to help. Link to comment Share on other sites More sharing options...
Gouravdev Posted January 24, 2022 Author Share Posted January 24, 2022 1 minute ago, knacky said: You should visit the Indian Forum, they will understand you there. You have a few important questions that can solve your problem. You didn't answer either. Probably no one will advise you here anymore. You can start a Job and someone may solve your problem.You've dealt with it in more discussions. I apologize for my brief statement and for not being able to help. I understand @knacky Previously, other Prestashop support and community helped me here. I debug the issue and I got it, why it's coming, where I got stuck is that why the `$this->context->cart` is null when the product is added into the cart. Is there anything wrong with current PS version or change modifications in ACtionCartSave hook? Thats, all I want to know. Link to comment Share on other sites More sharing options...
ps8modules Posted January 24, 2022 Share Posted January 24, 2022 Hello. Why are you asking? Do you present yourself as a developer and can't compare hooks in different versions of Prestashop? Open Cart.php and CartController.php and you will find the difference. Prestashop 1.7.8 works mainly via ajax and not all parameters can be null. If you know the id cart is OK, the error is in the database or some other module has an override on the cart. Do you want a few hours of free explanations from the community and you will be paid for the repairs yourself? There is documentation where all changes are written in Prestashop. If you want to solve something, you have to read and study. This is not how help works. 1 Link to comment Share on other sites More sharing options...
Gouravdev Posted January 24, 2022 Author Share Posted January 24, 2022 57 minutes ago, 4you.software said: Hello. Why are you asking? Do you present yourself as a developer and can't compare hooks in different versions of Prestashop? Open Cart.php and CartController.php and you will find the difference. Prestashop 1.7.8 works mainly via ajax and not all parameters can be null. If you know the id cart is OK, the error is in the database or some other module has an override on the cart. Do you want a few hours of free explanations from the community and you will be paid for the repairs yourself? There is documentation where all changes are written in Prestashop. If you want to solve something, you have to read and study. This is not how help works. @4you.software I've done all the above debug of comparing hooks, checking Cart.php and CartController.php, checking parameters, disabling other modules, I didn't get paid for anything, it's just as community I need some help to understand what I'm missing in my debugging. Thanks for you response 🙏🏻 Link to comment Share on other sites More sharing options...
Couponsva Posted March 8, 2022 Share Posted March 8, 2022 On 1/24/2022 at 4:10 PM, knacky said: You should visit the Indian Forum, they will understand you there. You have a few important questions that can solve your problem. You didn't answer either. Probably no one will advise you here anymore. You can start a Job and someone may solve your problem.You've dealt with it in more discussions. I apologize for my brief statement and for not being able to help. I know that, but I want to know why it's coming as null when product is added. Thanks Link to comment Share on other sites More sharing options...
Gouravdev Posted March 8, 2022 Author Share Posted March 8, 2022 2 hours ago, Couponsva said: I know that, but I want to know why it's coming as null when product is added. Thanks I've fixed it as add product to cart call run twice, which leads cart empty in first call. Link to comment Share on other sites More sharing options...
casualPScoder Posted April 13, 2023 Share Posted April 13, 2023 (edited) On 3/8/2022 at 6:01 PM, Couponsva said: I know that, but I want to know why it's coming as null when product is added. Thanks TLDR: check your current customer address, you must have one address (or default address) to get context->cart value Just experienced the same problem, turns out its a prestashop bug (I'm on PS 1.7.8.8) My problem case is, on hook ActionCartSave, when I var_dump(Context::getContext()->cart) is always null, and I cant get Context::getContext()->cart->getProducts(), will throw me error everytime. This happens only to logged in customer without any default address (no address at all) Check on <ps root folder>/classes/controller/FrontController.php on init function, search for this line "if (!isset($cart) || !$cart->id) {" in my case its line 442. Just before that line, there is $cart->update, thats the one triggering actionCartSave (its trigger when ps check that the customer has no default address, and it will always be triggered until the customer has default address), and its triggered before initialization of the $this->context->cart (its inside the if on line 442). Adding address on the customer solve the problem. but I wondering, if I have a heavy code on actionCartSave hook, turns out it will always executed everytime customer without address load a page (anywhere), it will slowdown the server. I'll open this issue on github too, thanks EDIT: I solve the problem by overriding the FrontController, copying all init function with replacing this line if ($to_update) { $cart->update(); } with if ($to_update && Customer::getAddressesTotalById($cart->id_customer) > 0) { $cart->update(); } EDIT AGAIN: it turns out very bad idea to override init function. So I just update the prestashop core. Very bad practice, but needed Edited April 13, 2023 by casualPScoder update my fixes (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now