Jump to content

Activated new lang and products created before this are giving 404 page until I got a press "save" in product page in the backend


Hokuto ShinKen

Recommended Posts

Hi all,


I activated recently a 3rd language in my prestashop (latest version of the 1.7 series).
And I found out the when I switch to this new language, and try to see a product page of products which have been create before the new language activation, it is giving me a 404 sorry page.
This doesn' t happen with products created after the new language activation.
In order for me to get the "old" product, presenting their product page instead of 404, is to go to the backoffice, go to the product and press save.

I would like to know if there is some maybe sql query that would help me do this in bulk.

Thanks in advance Prestashopers!
Best regards
 

Link to comment
Share on other sites

Hello,

While this can be achieved with a SQL stored procedure, it is actually better to do it with a script, as the tables that need to be updated can change from version to version.

Now, I cannot replicate this behavior in my local environment, thus cannot guarantee the script will 100% fix your issue.

You should either run it in a staging environment first or try only with a couple of product ids (see the commented code).

You can create a script.php file in your PrestaShop root, add the below content and open <your_website_url>/script.php

<?php

require dirname(__FILE__) . '/config/config.inc.php';

$productIds = Db::getInstance()->executeS("SELECT `id_product` from `" . _DB_PREFIX_ . "product`");

// $productIds = [
//     [
//         id_product => 1,
//     ],
//     [
//         id_product => 2,
//     ],
//     [
//         id_product => 3,
//     ],
// ];

try {
    foreach ($productIds as $productId) {
        (new Product($productId['id_product']))->save();
    }

    print 'All done!';
} catch (Exception $e) {
    print $e->getMessage();
}

It looks like I cannot format it, but everything between these two paragraphs needs to be added to the script.

I have not tested it with a lot of products. If the script crashes because you have too many products, let me know. This can be improved in order to have a couple of products batches run in parallel.

Link to comment
Share on other sites

  • 3 weeks later...
  On 5/26/2024 at 8:08 AM, Andrei H said:

Hello,

While this can be achieved with a SQL stored procedure, it is actually better to do it with a script, as the tables that need to be updated can change from version to version.

Now, I cannot replicate this behavior in my local environment, thus cannot guarantee the script will 100% fix your issue.

You should either run it in a staging environment first or try only with a couple of product ids (see the commented code).

You can create a script.php file in your PrestaShop root, add the below content and open <your_website_url>/script.php

<?php

require dirname(__FILE__) . '/config/config.inc.php';

$productIds = Db::getInstance()->executeS("SELECT `id_product` from `" . _DB_PREFIX_ . "product`");

// $productIds = [
//     [
//         id_product => 1,
//     ],
//     [
//         id_product => 2,
//     ],
//     [
//         id_product => 3,
//     ],
// ];

try {
    foreach ($productIds as $productId) {
        (new Product($productId['id_product']))->save();
    }

    print 'All done!';
} catch (Exception $e) {
    print $e->getMessage();
}

It looks like I cannot format it, but everything between these two paragraphs needs to be added to the script.

I have not tested it with a lot of products. If the script crashes because you have too many products, let me know. This can be improved in order to have a couple of products batches run in parallel.

Expand  

Hi @Andrei H and everyone,

I am very sorry for the late reply. I will try and let you know.

Regards

Link to comment
Share on other sites

  On 6/11/2024 at 9:24 AM, Hokuto ShinKen said:

Hi @Andrei H and everyone,

I am very sorry for the late reply. I will try and let you know.

Regards

Expand  

Hi @Andrei H and everyone,

I ran the script and it looks like it fails with the following:

 

 PHP Warning:  Cannot modify header information - headers already sent by (output started at /public_html/resave.php:1) in /public_html/modules/ps_accounts/classes/Service/AnalyticsService.php on line 291
PHP Stack trace:
PHP   1. {main}() /public_html/resave.php:0
PHP   2. Product->save() /public_html/resave.php:21
PHP   3. Product->update() /public_html/classes/ObjectModel.php:535
PHP   4. Product->update() /public_html/classes/Product.php:816
PHP   5. HookCore::exec() /public_html/classes/ObjectModel.php:835
PHP   6. HookCore::callHookOn() /public_html/classes/Hook.php:944
PHP   7. Hook::coreCallHook() /public_html/classes/Hook.php:431
PHP   8. PageCache::execHook() /public_html/override/classes/Hook.php:82
PHP   9. Ps_eventbus->hookActionObjectProductUpdateAfter() /public_html/modules/pagecache/pagecache.php:3540
PHP  10. Ps_eventbus->insertIncrementalSyncObject() /public_html/modules/ps_eventbus/ps_eventbus.php:543
PHP  11. Ps_eventbus->getService() /public_html/modules/ps_eventbus/ps_eventbus.php:1390
PHP  12. PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer->getService() /public_html/modules/ps_eventbus/ps_eventbus.php:228
PHP  13. Symfony\Component\DependencyInjection\ContainerBuilder->get() /public_html/modules/ps_eventbus/vendor/prestashop/module-lib-service-container/src/DependencyInjection/ServiceContainer.php:64
PHP  14. Symfony\Component\DependencyInjection\ContainerBuilder->doGet() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:588
PHP  15. Symfony\Component\DependencyInjection\ContainerBuilder->createService() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:634
PHP  16. Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1149
PHP  17. Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1238
PHP  18. Symfony\Component\DependencyInjection\ContainerBuilder->doGet() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1281
PHP  19. Symfony\Component\DependencyInjection\ContainerBuilder->createService() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:634
PHP  20. ReflectionClass->newInstanceArgs() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1176
PHP  21. PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler->__construct() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1176
PHP  22. PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts->getPsAccountsService() /public_html/modules/ps_eventbus/src/Handler/ErrorHandler/ErrorHandler.php:44
PHP  23. PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts->getService() /public_html/modules/ps_eventbus/vendor/prestashop/prestashop-accounts-installer/src/Installer/Facade/PsAccounts.php:62
PHP  24. Ps_accounts->getService() /public_html/modules/ps_eventbus/vendor/prestashop/prestashop-accounts-installer/src/Installer/Facade/PsAccounts.php:47
PHP  25. PrestaShop\Module\PsAccounts\DependencyInjection\ServiceContainer->getService() /public_html/modules/ps_accounts/ps_accounts.php:228
PHP  26. Ps_accounts562FrontContainer->get() /public_html/modules/ps_accounts/classes/DependencyInjection/ServiceContainer.php:73
PHP  27. Ps_accounts562FrontContainer->getPsAccountsServiceService() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:306
PHP  28. Ps_accounts562FrontContainer->getShopTokenRepositoryService() /public_html/var/cache/prod/Ps_accounts562FrontContainer.php:268
PHP  29. Ps_accounts562FrontContainer->getAnalyticsServiceService() /public_html/var/cache/prod/Ps_accounts562FrontContainer.php:238
PHP  30. PrestaShop\Module\PsAccounts\Service\AnalyticsService->__construct() /public_html/var/cache/prod/Ps_accounts562FrontContainer.php:258
PHP  31. PrestaShop\Module\PsAccounts\Service\AnalyticsService->initAnonymousId() /public_html/modules/ps_accounts/classes/Service/AnalyticsService.php:33
PHP  32. setcookie() /public_html/modules/ps_accounts/classes/Service/AnalyticsService.php:291
PHP Notice:  Trying to get property 'precision' of non-object in /public_html/classes/Context.php on line 498
PHP Stack trace:
PHP   1. {main}() /public_html/resave.php:0
PHP   2. Product->save() /public_html/resave.php:21
PHP   3. Product->update() /public_html/classes/ObjectModel.php:535
PHP   4. HookCore::exec() /public_html/classes/Product.php:831
PHP   5. HookCore::callHookOn() /public_html/classes/Hook.php:944
PHP   6. Hook::coreCallHook() /public_html/classes/Hook.php:431
PHP   7. PageCache::execHook() /public_html/override/classes/Hook.php:82
PHP   8. Holded->hookActionProductUpdate() /public_html/modules/pagecache/pagecache.php:3540
PHP   9. Holded\Prestashop\Services\ProductService->updateHoldedProduct() /public_html/modules/holded/src/Hooks/Hooks.php:54
PHP  10. Holded\Prestashop\Adapters\ProductAdapter::fromPrestashopToDTO() /public_html/modules/holded/src/Services/ProductService.php:40
PHP  11. array_map() /public_html/modules/holded/src/Adapters/ProductAdapter.php:124
PHP  12. Holded\Prestashop\Adapters\ProductAdapter::Holded\Prestashop\Adapters\{closure:/public_html/modules/holded/src/Adapters/ProductAdapter.php:88-124}() /public_html/modules/holded/src/Adapters/ProductAdapter.php:124
PHP  13. Product->getAttributeCombinationsById() /public_html/modules/holded/src/Adapters/ProductAdapter.php:109
PHP  14. Context->getComputingPrecision() /public_html/classes/Product.php:2841
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision::getPrecision() must be of the type int, null given, called in /public_html/classes/Context.php on line 498 and defined in /public_html/src/Core/Localization/CLDR/ComputingPrecision.php:41
Stack trace:
#0 /public_html/classes/Context.php(498): PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision->getPrecision()
#1 /public_html/classes/Product.php(2841): ContextCore->getComputingPrecision()
#2 /public_html/modules/holded/src/Adapters/ProductAdapter.php(109): ProductCore->getAttributeCombinationsById()
#3 [internal function]: Holded\Prestashop\Adapters\ProductAdapter::Holded\Prestashop\Adapters\{closure}()
#4 /public_html/modules/holded/src/Adapters/ProductAdapter.php(124): array_map()
#5 /public_html/modules/holded/src/Services/ProductService.php(40): Holded\Prestashop\Adapters\ProductA in /public_html/src/Core/Localization/CLDR/ComputingPrecision.php on line 41

I am trying to check where this comes from.

Regards

Link to comment
Share on other sites

  On 6/11/2024 at 10:09 AM, Hokuto ShinKen said:

Hi @Andrei H and everyone,

I ran the script and it looks like it fails with the following:

 

 PHP Warning:  Cannot modify header information - headers already sent by (output started at /public_html/resave.php:1) in /public_html/modules/ps_accounts/classes/Service/AnalyticsService.php on line 291
PHP Stack trace:
PHP   1. {main}() /public_html/resave.php:0
PHP   2. Product->save() /public_html/resave.php:21
PHP   3. Product->update() /public_html/classes/ObjectModel.php:535
PHP   4. Product->update() /public_html/classes/Product.php:816
PHP   5. HookCore::exec() /public_html/classes/ObjectModel.php:835
PHP   6. HookCore::callHookOn() /public_html/classes/Hook.php:944
PHP   7. Hook::coreCallHook() /public_html/classes/Hook.php:431
PHP   8. PageCache::execHook() /public_html/override/classes/Hook.php:82
PHP   9. Ps_eventbus->hookActionObjectProductUpdateAfter() /public_html/modules/pagecache/pagecache.php:3540
PHP  10. Ps_eventbus->insertIncrementalSyncObject() /public_html/modules/ps_eventbus/ps_eventbus.php:543
PHP  11. Ps_eventbus->getService() /public_html/modules/ps_eventbus/ps_eventbus.php:1390
PHP  12. PrestaShop\ModuleLibServiceContainer\DependencyInjection\ServiceContainer->getService() /public_html/modules/ps_eventbus/ps_eventbus.php:228
PHP  13. Symfony\Component\DependencyInjection\ContainerBuilder->get() /public_html/modules/ps_eventbus/vendor/prestashop/module-lib-service-container/src/DependencyInjection/ServiceContainer.php:64
PHP  14. Symfony\Component\DependencyInjection\ContainerBuilder->doGet() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:588
PHP  15. Symfony\Component\DependencyInjection\ContainerBuilder->createService() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:634
PHP  16. Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1149
PHP  17. Symfony\Component\DependencyInjection\ContainerBuilder->doResolveServices() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1238
PHP  18. Symfony\Component\DependencyInjection\ContainerBuilder->doGet() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1281
PHP  19. Symfony\Component\DependencyInjection\ContainerBuilder->createService() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:634
PHP  20. ReflectionClass->newInstanceArgs() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1176
PHP  21. PrestaShop\Module\PsEventbus\Handler\ErrorHandler\ErrorHandler->__construct() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1176
PHP  22. PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts->getPsAccountsService() /public_html/modules/ps_eventbus/src/Handler/ErrorHandler/ErrorHandler.php:44
PHP  23. PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts->getService() /public_html/modules/ps_eventbus/vendor/prestashop/prestashop-accounts-installer/src/Installer/Facade/PsAccounts.php:62
PHP  24. Ps_accounts->getService() /public_html/modules/ps_eventbus/vendor/prestashop/prestashop-accounts-installer/src/Installer/Facade/PsAccounts.php:47
PHP  25. PrestaShop\Module\PsAccounts\DependencyInjection\ServiceContainer->getService() /public_html/modules/ps_accounts/ps_accounts.php:228
PHP  26. Ps_accounts562FrontContainer->get() /public_html/modules/ps_accounts/classes/DependencyInjection/ServiceContainer.php:73
PHP  27. Ps_accounts562FrontContainer->getPsAccountsServiceService() /public_html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:306
PHP  28. Ps_accounts562FrontContainer->getShopTokenRepositoryService() /public_html/var/cache/prod/Ps_accounts562FrontContainer.php:268
PHP  29. Ps_accounts562FrontContainer->getAnalyticsServiceService() /public_html/var/cache/prod/Ps_accounts562FrontContainer.php:238
PHP  30. PrestaShop\Module\PsAccounts\Service\AnalyticsService->__construct() /public_html/var/cache/prod/Ps_accounts562FrontContainer.php:258
PHP  31. PrestaShop\Module\PsAccounts\Service\AnalyticsService->initAnonymousId() /public_html/modules/ps_accounts/classes/Service/AnalyticsService.php:33
PHP  32. setcookie() /public_html/modules/ps_accounts/classes/Service/AnalyticsService.php:291
PHP Notice:  Trying to get property 'precision' of non-object in /public_html/classes/Context.php on line 498
PHP Stack trace:
PHP   1. {main}() /public_html/resave.php:0
PHP   2. Product->save() /public_html/resave.php:21
PHP   3. Product->update() /public_html/classes/ObjectModel.php:535
PHP   4. HookCore::exec() /public_html/classes/Product.php:831
PHP   5. HookCore::callHookOn() /public_html/classes/Hook.php:944
PHP   6. Hook::coreCallHook() /public_html/classes/Hook.php:431
PHP   7. PageCache::execHook() /public_html/override/classes/Hook.php:82
PHP   8. Holded->hookActionProductUpdate() /public_html/modules/pagecache/pagecache.php:3540
PHP   9. Holded\Prestashop\Services\ProductService->updateHoldedProduct() /public_html/modules/holded/src/Hooks/Hooks.php:54
PHP  10. Holded\Prestashop\Adapters\ProductAdapter::fromPrestashopToDTO() /public_html/modules/holded/src/Services/ProductService.php:40
PHP  11. array_map() /public_html/modules/holded/src/Adapters/ProductAdapter.php:124
PHP  12. Holded\Prestashop\Adapters\ProductAdapter::Holded\Prestashop\Adapters\{closure:/public_html/modules/holded/src/Adapters/ProductAdapter.php:88-124}() /public_html/modules/holded/src/Adapters/ProductAdapter.php:124
PHP  13. Product->getAttributeCombinationsById() /public_html/modules/holded/src/Adapters/ProductAdapter.php:109
PHP  14. Context->getComputingPrecision() /public_html/classes/Product.php:2841
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision::getPrecision() must be of the type int, null given, called in /public_html/classes/Context.php on line 498 and defined in /public_html/src/Core/Localization/CLDR/ComputingPrecision.php:41
Stack trace:
#0 /public_html/classes/Context.php(498): PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision->getPrecision()
#1 /public_html/classes/Product.php(2841): ContextCore->getComputingPrecision()
#2 /public_html/modules/holded/src/Adapters/ProductAdapter.php(109): ProductCore->getAttributeCombinationsById()
#3 [internal function]: Holded\Prestashop\Adapters\ProductAdapter::Holded\Prestashop\Adapters\{closure}()
#4 /public_html/modules/holded/src/Adapters/ProductAdapter.php(124): array_map()
#5 /public_html/modules/holded/src/Services/ProductService.php(40): Holded\Prestashop\Adapters\ProductA in /public_html/src/Core/Localization/CLDR/ComputingPrecision.php on line 41

I am trying to check where this comes from.

Regards

Expand  

Hi @Andrei H and everyone,

I finally was able run the script without issue by disabling the module "Holded" temporarily from my install.
The script did the job by simulating the "press" save button on the edit product page on the backend as expected.

Thanks a lot @Andrei H again for your support.

Best regards

 

  • Like 1
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...