Prestashop:Create a module that override another module? - module

I create a module and this module should also change another module (mailalerts) , I temporarily overridden this module into the folder /override/ , but I wish it was all in my module.

If you have
/modules/mymodule/override/modules/mailalerts/mailalerts.php,
then this file will be copied to
/override/modules/mailalerts/mailalerts.php,
after mymodule installation.
Be aware that making a module that overrides other modules is not good practice. You should only use module overrides for your own or your client website and place them directly in the /override/modules/ folder.

Related

autoload zf3 module without terminal command

I am using ZendFramwork3, i'm new in this so don't know how to autoload the module after creation without terminal command.
I am creating module with programme just by taking module name from the user the following things will be done :
- Module structure for new module with namespace and controller & view files will be placed under module folder
- ModuleName is initialised in modules.config.php in config folder
- Also entry in composer.json in autoload --> psr-4 initialisation done
After that i have to manually run the command "composer dump-autoload" to perfectly work my module but i don't want to do that manually rather i want solution for that to run it programmatically.
Thank you for the solution in advance.

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.

Prestashop 1.5, How to copy a core module into my theme module folder?

I'de like to copy the [prestashop new theme]cart block (cartblock2 in the main module folder) into my theme/modules in order to customize it and keep the core module intact.
How do I do that ? I searched the documentation and it's not very clear...
What I did so far :
Copy cartblock2 from the main module folder into my theme/module folder, empty prestashop cache (it's turned off but just to be sure), I made my changes but nothing change it's only changing when I modify the module in the main module folder.
Thank you for your help
module folder name must same with root modules name
/modules/blockcart2
in themes
/themes/modules/blockcart2
and you can only edit blockcart2.tpl file in themes folder
and make sure blockcart2 installed in bacoffice

Why can't Rails 3.2.9 automatically require a *.rb file in the "lib" directory?

I realize that "lib" is no longer autoloaded by default. However, I have this in my application.rb file:
config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/datatables)
I have a module in lib called utility.rb, declared as follows:
module MyApp
module Utility
I have some utility methods in there, for example a method that takes an array and turns it into values that can be queried from MySQL. I have:
include MyApp
at the top of the classes that need that method, so that I can then just call:
Utility::array_to_query_string
Unfortunately, this does not work. Whether running a rake task or the application, I am met with:
uninitialized constant MyApp
I don't know how to make Rails require other than what I have above. In the console, if I explicitly type require 'utility' and then I can successfully do the include. What do I have to do to make Rails autoload this module?
The problem could be the directory structure in your lib folder. That the rails autoloader can find your file, it needs to be placed in the right spot. Your MyApp::Utility module should live in a file called: lib/my_app/utility.rb.
If you place the file directly in lib lib/utility.rb the autoloader won't find it.
In some of my apps, I add an initializer that loads my custom code.
In config/initializers/utility.rb,
require "#{Rails.root}/lib/utility"