How to override prestashop core files - prestashop

Can you please explain how to override following core files properly in presatashop. Prestashop 1.7.1.2 allowed only controllers, modal and tpl files in override folder. We can not override src folders in same way.
src/PrestaShopBundle/Controller/Admin/ProductController.php src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig

I don't believe this is possible in Prestashop 1.7. See their post here : it seems like they want you to use hooks, ie extending not overriding...

From PS 1.7.3, you can override src views and controllers in a module.
To override this template file:
src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
You can add it in a module:
modules/<MY-MODULE>/views/PrestaShop/Admin/Product/form.html.twig
Doc PrestaShop for views in a module
And to override this controller file:
src/PrestaShopBundle/Controller/Admin/ProductController.php
You can add it in global override folder:
override/PrestaShop/Controllers/Admin/ProductController.php
Or in a module:
modules/<MY-MODULE>/override/PrestaShop/Controllers/Admin/ProductController.php
Doc PrestaShop for controllers in a module

PrestaShop give you the ability to override core files, you can check the : officiel doc

Related

how to override a js file which exist in module in prestashop?

I am trying to override a js file which exist in module.
path - /website/modules/onepagecheckoutps/views/js/front/onepagecheckoutps.js
Is their any way we can override this file ?
If JS is properly loaded in module you can override it by copying file to this path:
/website/themes/your_theme/modules/onepagecheckoutps/views/js/front/onepagecheckoutps.js

How to override .js file in strange structure

I am working on prestashop 1.6. I have a .js file here:
\modules\my_module\views\js\custom.js
And I want to override it in theme.
I've tried for example:
\themes\my_theme\modules\my_module\views\js\custom.js
It didn't work. Nor did
\overrides\modules\my_module\views\js\custom.js
Where should this file be placed?
You should place your file under:
\themes\[theme]\js\modules\[js_path_in_module]
\themes\my_theme\js\modules\my_module\views\js\custom.js

Prestashop How override backoffice templates in my own module

if I want to do override admin templates in my own module, for example
"modules/{my_module}/override/controllers/admin/templates/products/combinations.tpl"
I don't see any changes.
I think this don't work automaticaly. What I should do more?
In prestashop 1.6 you have to manually put it in override folder so for your template it would be
override/controllers/admin/templates/products/combinations.tpl

Autoload module class in Prestashop

I've created a module that has an override for the FrontControllerCore class to add additional Smarty variables.
The issue I'm running into is trying to autoload a class that is referenced in the controller that is in my module. The class isn't being loaded and I don't know how to add it to the autoloader.
When you install the module the FrontController.php file should be located in:
override\classes\controller\
so from the FrontController.php you can "include" manually that file like:
require_once(dirname(__FILE__).'/../../../modules/servicecharges/classes/ServiceCharge.php');
There's no autoload for such includes.
Also you can use this free tiny module that override Prestashop autoload. After that all your module custom class will be autoloaded.
Exemple path: /modules/my_module/libs/classes/MyClass.php
Extended Api
I've been able to solve a similar problem, with Composer's autoload. Way to require an autoload in one file on a Prestashop module?
Instead of overriding a controller (leading to conflicts with other plugins or installations of Prestashop already using the same overrides) you could invoke the hook moduleRoutes.
This way, you could call your autlooader always before the controllers:
<?php
public function hookModuleRoutes() {
require_once __DIR__.'/vendor/autoload.php'; // And the autoload here to make our Composer classes available everywhere!
}

PrestaShop Using Default Module Instead of Theme Module

Today I starting design theme for prestashop and i'm Beginner on that.
i have a Question about Theme Module
i have Some module for my new Theme Located here:
prestashop/theme/mytheme/Module
and i want customize that for my new theme.
but the prestashop not using My Module instead using default module Located here:
Prestashop/Module/
What's Wrong and how to Fix this?
From the PrestaShop documentation:
Overriding a module's behavior
The modules are usually in the following format:
/modules/my_module/my_module.tpl
/modules/my_module/my_module.css
/modules/my_module/my_module.js
Since PrestaShop 1.5, they can and should also be in the following format:
/modules/my_module/views/templates/front/my_module.tpl
/modules/my_module/views/templates/front/my_module.css
/modules/my_module/views/templates/front/my_module.js
PrestaShop allows you to override or replace certain front-office module files
with new ones within the same theme. The override is governed by the
theme: once it contains a /modules folder (or more!), PrestaShop will
browse its content for files which have the same name and path as
those of existing modules, and replace these with the new ones.
This means, for PrestaShop 1.4-compatible modules:
/themes/my_theme/modules/my_module/my_module.tpl
/themes/my_theme/css/modules/my_module/my_module.css
/themes/my_theme/js/modules/my_module/my_module.js
Since PrestaShop 1.5, the path is slightly longer
/themes/my_theme/modules/my_module/views/templates/front/my_module.tpl
/themes/my_theme/css/modules/my_module/views/templates/front/my_module.css
/themes/my_theme/js/modules/my_module/views/templates/front/my_module.js
In general, the proper path to override a .tpl, .js or .css file
depends on the module's own path. That is the reason why if PrestaShop
1.5 has to work with a module without a view folder, it will need the same override path.
In short, you can keep overriding code in 1.5 just
as you did in 1.4.
The new files will be used when the customer loads
your shop.
Contrary to the override code that is to be placed manually
in the /override folder, module overrides are enabled as soon as the
module is installed. During installation, overriding code is merge
with those already in place (if any), otherwise they are copied to the
/override folder at the root of the PrestaShop folder.