Soniya Kaliappan
Soniya Kaliappan

Reputation: 57

How to solve modules which use overrides are not able to install / uninstall properly in prestshop

I have createsd a new module in prestashop. Here I had overrite some core functionality of product class.

My overrite file has placed in the location : prestashop/modules/mymodule/override/

When I install the module i am getting the following Error :

 Cannot redeclare class ProductOverrideOriginal in /var/www/html/htdocs/prestashop/modules/sharesoft_relatedproducts/sharesoft_relatedproducts.php(96) : eval()'d code on line 2
[PrestaShop] Fatal error in module sharesoft_relatedproducts.php(96) : eval()'d :
Cannot redeclare class ProductOverrideOriginal .

How can i fix this

Upvotes: 1

Views: 2171

Answers (1)

gskema
gskema

Reputation: 3221

It means jsut what it says. Your code tries to declare a class twice (with the same), so there is a conflict.

I also do not understand why your class is named ProductOverrideOriginal. All Prestashop overrides must override original PrestaShop classes, for example

class Product extends ProductCore { ...

From the error message I presume that you tried to include your overriden class

require('/override/sharesoft_relatedproducts.php');

But all files from module folder

prestashop/modules/mymodule/override/

are automatically copied to

prestashop/override/

during module installation. My guess is that your override class file is copied there, and is loaded, but you also try to include it again in your module, which gives you error (trying to declare twice).

Also, make sure you use statements like:

require_once('myfile.php');

or

if (!class_exists('MyFile'))
    require_once('myfile.php');

to ensure that the same class is not declared twice. Seconde option is better because its faster (does not check file system)

Upvotes: 1

Related Questions