HarryMemStar Posted March 12 Share Posted March 12 Hi guys, I run an eCommerce store using Prestashop, and I noticed if using the language / currency switching system while having any item in the cart, I would get the following error "If no employee is assigned in the context, cart ID must be provided to this method." - I didn't see much of this online so I thought id post about it to see if this was a common issue. The way I worked around this fault was by going into the classes/Product.php file and removing the line, this seemed to stop the error page displaying, however I obviously don't know if this will cause issues down the line? Any ideas here are much appreciated. Link to comment Share on other sites More sharing options...
ArnasDEV Posted April 5 Share Posted April 5 Same, I noticed this problem as well on PS v8.1.4 is there any developer toughs on this? Link to comment Share on other sites More sharing options...
David Pixodeo Posted April 15 Share Posted April 15 (edited) Same here with Prestashop 8.1.4 too The problem occurs when I switch the language with something in my cart. If the cart is empty, everything works fine. Edited April 15 by David Pixodeo (see edit history) Link to comment Share on other sites More sharing options...
josema_recambios Posted July 11 Share Posted July 11 Same here with Prestashop 8.1.7 - Fresh install - Default theme In debug mode throw ths error: Fatal error: Uncaught PrestaShopException: If no employee is assigned in the context, cart ID must be provided to this method. in /var/www/html/classes/Tools.php:1124 Stack trace: #0 /var/www/html/classes/Product.php(3663) Extract code from Product.php class: if (!is_object($cur_cart) || (Validate::isUnsignedInt($id_cart) && $id_cart && $cur_cart->id != $id_cart)) { /* * When a user (e.g., guest, customer, Google...) is on PrestaShop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on PrestaShop, he does not have already it BUT knows the cart ID * When called from the back office, cart ID can be inexistant */ if (!$id_cart && !isset($context->employee)) { die(Tools::displayError('If no employee is assigned in the context, cart ID must be provided to this method.')); } $cur_cart = new Cart($id_cart); // Store cart in context to avoid multiple instantiations in BO if (!Validate::isLoadedObject($context->cart)) { $context->cart = $cur_cart; } } Any news? Thanks!! :) Link to comment Share on other sites More sharing options...
TwinkleEye Posted August 2 Share Posted August 2 (edited) Hi, Is there any update on this? I have this only when ordering a Giftcard through Knowband Giftcard module. All other orders work as expected. Although When I click the refresh in the browser when getting the error page "If no employee is assigned in the context, cart ID must be provided to this method." - I will be directed to the selected payment (mobile pay / Credit card etc) Running version PS 8.1.6? Edited August 2 by TwinkleEye context (see edit history) Link to comment Share on other sites More sharing options...
TwinkleEye Posted August 2 Share Posted August 2 Hi again, I did change the above code snip in the product.php with the below - now it seems to work: if (!is_object($cur_cart) || (Validate::isUnsignedInt($id_cart) && $id_cart && $cur_cart->id != $id_cart)) { // When a user (e.g., guest, customer, Google...) is on PrestaShop, they already have their cart as a global (see /init.php). // When a non-user calls this method directly (e.g., payment module...), they do not have it but know the cart ID. // When called from the back office, cart ID may be nonexistent. if (!$id_cart && !isset($context->employee)) { throw new Exception(Tools::displayError('If no employee is assigned in the context, cart ID must be provided to this method.')); } $cur_cart = new Cart($id_cart); // Store cart in context to avoid multiple instantiations in BO if (!Validate::isLoadedObject($context->cart)) { $context->cart = $cur_cart; } } Link to comment Share on other sites More sharing options...
alexaali Posted August 4 Share Posted August 4 (edited) Hi, It sounds like the issue might be related to the session handling when switching languages or currencies. Instead of modifying the core files, which can cause issues during updates, try the following: Check if the issue persists in the latest version of PrestaShop. If the error still occurs, consider using a custom module or override to handle the cart context during the switch. This way, you can maintain core integrity and avoid potential issues later on. This should provide a cleaner and more maintainable solution. Let me know if it helps! Edited August 4 by alexaali (see edit history) Link to comment Share on other sites More sharing options...
Sashok Posted September 2 Share Posted September 2 Same bug on 8.1.7 When you change the language with a cart or log with user who default lang is not the same, frontoffice return the following error: If no employee is assigned in the context, cart ID must be provided to this method. https://yokotower.com How to fix? Thanks Link to comment Share on other sites More sharing options...
WisQQ Posted September 13 Share Posted September 13 (edited) The issue is related to method Product::getPriceStatic being called with no context of current user cart. I recently encountered this issue when ussing hook ActionCartSave calling getProducts method which is using Product::getProductProperties which calls the method above. If you have any module that uses hook ActionCartSave you can simply fix it by assigning cart to action hook context. $this->context->cart = $params['cart']; If you still have this issue please paste entire error stack so we it's easier to find what's causing the problem. Depending on the ps version you might also want to check for currency object if its loaded properly. if(!Validate::isLoadedObject($this->context->currency)){ $curreny = new Currency($params['cart']->id_currency); $this->context->currency = $curreny; } Edited September 13 by WisQQ (see edit history) 1 1 Link to comment Share on other sites More sharing options...
ps8modules Posted September 13 Share Posted September 13 Hi. This is exactly how Prestashop developers stick errors 😁 It is really necessary to give the entire error message. Natively, this error is not in Prestashop, but in some module. 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