PrestaShop / PrestaShop

PrestaShop is the universal open-source software platform to build your e-commerce solution.
https://www.prestashop-project.org/
Other
8.14k stars 4.8k forks source link

500 error: Kernel Container is not available #15503

Closed TedEriksson closed 5 years ago

TedEriksson commented 5 years ago

Describe the bug After a payment (coming back from an external payment site), the payment module I am using calls PaymentModuleCore->validateOrder, which crashes with the exception "Kernel Container is not available". This has happened since updating from 1.7.4.4 to 1.7.6.1. It seems ContainerFinder was introduced between those versions

Stacktrace:

Fatal error: Uncaught Exception: Kernel Container is not available in /opt/bitnami/apps/prestashop/htdocs/src/Adapter/ContainerFinder.php:77 
Stack trace: 
#0 /opt/bitnami/apps/prestashop/htdocs/classes/Tools.php(796): PrestaShop\PrestaShop\Adapter\ContainerFinder->getContainer() 
#1 /opt/bitnami/apps/prestashop/htdocs/classes/Tools.php(773): ToolsCore::getContextLocale(Object(Context)) 
#2 /opt/bitnami/apps/prestashop/htdocs/classes/PaymentModule.php(421): ToolsCore::displayPrice(1.05, Object(Currency), false) 
#3 /opt/bitnami/apps/prestashop/htdocs/modules/sagepay/validation.php(85): PaymentModuleCore->validateOrder(20035, '2', 1.26, 'Sagepay', 'Result:OK<br />...', Array, NULL, false, 'REDACTED') 
#4 {main} thrown in /opt/bitnami/apps/prestashop/htdocs/src/Adapter/ContainerFinder.php on line 77

Additional information PrestaShop version: 1.7.6.1 PHP version: 7.1.22

madcorp206 commented 5 years ago

Same issue with validateOrder but also with NotificationCore :

PHP Fatal error:  Uncaught Exception: Kernel Container is not available in /var/www/store/src/Adapter/ContainerFinder.php:77
Stack trace:
#0 /var/www/store/classes/Tools.php(796): PrestaShop\PrestaShop\Adapter\ContainerFinder->getContainer()
#1 /var/www/store/classes/Tools.php(773): ToolsCore::getContextLocale(Object(Context))
#2 /var/www/store/classes/Notification.php(133): ToolsCore::displayPrice(5.3, Object(Currency), false)
#3 /var/www/store/classes/Notification.php(57): NotificationCore::getLastElementsIdsByType('order', '665')
#4 /var/www/store/admin/ajax.php(125): NotificationCore->getLastElements()
#5 {main}
  thrown in /var/www/store/src/Adapter/ContainerFinder.php on line 77

PrestaShop version: 1.7.6.1 PHP 7.1.32

khouloudbelguith commented 5 years ago

Hi @TedEriksson,

Thanks for your report. Thanks to follow this comment of our lead developer about the payment module issues with PS1.7.6. Thanks to check & feedback.

rdy4ever commented 5 years ago

Hi @TedEriksson Checking out the diff for 1.7.6 in the payment module I use (mobilpay), I see they are initializing the kernel in validation.php: image

    global $kernel;
    if(!$kernel){ 
      require_once _PS_ROOT_DIR_.'/app/AppKernel.php';
      $kernel = new \AppKernel('prod', false);
      $kernel->boot(); 
    }

Maybe you can implement this behaviour in your module.

khouloudbelguith commented 5 years ago

@TedEriksson, any news? Thanks!

TedEriksson commented 5 years ago

@khouloudbelguith Thats fixed it!

mariem-abid commented 5 years ago

Hi @TedEriksson,

I close the issue, feel free to open a new one when needed.

freefiona85 commented 4 years ago

Hello @TedEriksson , @khouloudbelguith . I tried this fix, it worked out good, but it didn't pass Prestashop Validation - is there any workaround for this? Thank you!

khouloudbelguith commented 4 years ago

Hi @freefiona85,

As it's not a module provided by Prestashop, we can't do anything with this. You should contact the module author via your addons.prestashop.com account, they are the only ones to help you with it. Thanks!

jcarloscid commented 4 years ago

Same problem found in module REDSYS (redsysoficial v3.0.4) after upgrading to PS 1.7.6.2

The fix described by @rdy4ever worked in my shop also.

marcelmiguel commented 4 years ago

@jcarloscid Please can you detail the fix done? I have a web page with PS 1.7.6.4 and redsysoficial 3.0.6 and fails not generating the order on Prestashop.

valentin-anamorphik commented 4 years ago

Same problem

Fatal error: Uncaught Exception: Kernel Container is not available in \prestashop\src\Adapter\ContainerFinder.php on line 77
--

1 | 0.0006 | 422000 | {main}( ) | ...\cron.php:0
2 | 0.0695 | 2136768 | MyClass->method( ) | ...\cron.php:20
3 | 0.1136 | 2841496 | Order->setCurrentState( ) | ...\Management.php:146
4 | 0.1978 | 3728784 | OrderHistory->addWithemail( ) | ...\Order.php:1681
5 | 0.2044 | 3740904 | OrderHistory->sendEmail( ) | ...\OrderHistory.php:468
6 | 0.2082 | 3785768 | ToolsCore::displayPrice( ) | ...\OrderHistory.php:513
7 | 0.2083 | 3785768 | ToolsCore::getContextLocale( ) | ...\Tools.php:773
8 | 0.2086 | 3852016 | PrestaShop\PrestaShop\Adapter\ContainerFinder->getContainer( ) | ...\Tools.php:796
# change order state
$order->setCurrentState(6);
OtiZ2 commented 4 years ago

Same problem. If i want change order state

Fatal error: Uncaught Exception: Kernel Container is not available in /var/www/clients/client13/web68/web/src/Adapter/ContainerFinder.php:77 Stack trace: #0 /var/www/clients/client13/web68/web/classes/Tools.php(796): PrestaShop\PrestaShop\Adapter\ContainerFinder->getContainer() #1 /var/www/clients/client13/web68/web/classes/Tools.php(773): ToolsCore::getContextLocale(Object(Context)) #2 /var/www/clients/client13/web68/web/classes/order/OrderHistory.php(513): ToolsCore::displayPrice(27.27, Object(Currency), false) #3 /var/www/clients/client13/web68/web/classes/order/OrderHistory.php(468): OrderHistoryCore->sendEmail(Object(Order), false) #4 /var/www/clients/client13/web68/web/import_export/classes/export/ChangeStateClass.php(55): OrderHistoryCore->addWithemail() #5 /var/www/clients/client13/web68/web/import_export/classes/AdapterImport.php(277): ChangeStateClass->changeOrderState('5', '4', 'X3P2sYMV', false) #6 /var/www/clients/client13/web68/web/import_export/classes/AdapterImport.php(70): AdapterImport->runOrderStateChan in /var/www/clients/client13/web68/web/src/Adapter/ContainerFinder.php on line 77

romain-le-mercier commented 4 years ago

I don't like how you (prestashop devs) dismiss this bug saying it's related to a third party module. YOU provide a method Tools::displayPrice(). Yes it's deprecated but as long as it's in the code IT HAS TO WORK. This is a static method (so by definition can be used in any contexte) and in some case it triggers an error, so the bug is prestashop related, not module related.

PierreRambaud commented 4 years ago

I don't like how you (prestashop devs) dismiss this bug saying it's related to a third party module. YOU provide a method Tools::displayPrice(). Yes it's deprecated but as long as it's in the code IT HAS TO WORK. This is a static method (so by definition can be used in any contexte) and in some case it triggers an error, so the bug is prestashop related, not module related.

Unfortunately, this is the problem when there are a lot of static methods in the code. A second problem is this kind of method is really sensitive, it touches about prices, date, etc. And in order to keep the same result everywhere, they decided to implement the formatPrice in the displayPrice method. As you say, even if the method is tagged as deprecated, it must work as before, you're right we can't deny it.

If you can provide us a little module to help us to reproduce the problem, we will be able to find a solution as fast as possible.

Febivayne commented 3 years ago

Hi @TedEriksson Checking out the diff for 1.7.6 in the payment module I use (mobilpay), I see they are initializing the kernel in validation.php: image

    global $kernel;
    if(!$kernel){ 
      require_once _PS_ROOT_DIR_.'/app/AppKernel.php';
      $kernel = new \AppKernel('prod', false);
      $kernel->boot(); 
    }

Maybe you can implement this behaviour in your module.

Any fix for this? We are implemeting an update on our prestashop module and we keep getting "Uncaught Exception: Kernel Container is not available" - what can we do about this? We can't use global $kernel; since globals are not authorized by prestashop.

Amit-Kumar-Tiwari-Webkul commented 2 years ago

@Febivayne You can include file init.php like this require_once('../../init.php');