Actually I'm a newbie to prestashop,
and I have changes in the following file in these locations
classes/Product.php
src/PrestaShopBundle/Controller/Admin/ProductController.php
src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
I have created a module named as My Kit while this module is configured all these changes should work..If the module is set to be disabled these changes should not affect in front end(I mean in admin panel)
For this I've created an override folder in my_kit module and place all those above mentioned files into this my_kit\override path..
like
my_kit\override\classes/Product.php
my_kit\override\src/PrestaShopBundle/Controller/Admin/ProductController.php
my_kit\override\src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
But it won't work for me :(
how should I do this one..
Someone help me out of this..
You can use php default copy function in your main file install function like below.
public function install()
{
copy(_PS_ROOT_DIR_."/modules/your module name/classes/Product.php",_PS_ROOT_DIR_."/override/classes/Product.php");
unlink(_PS_ROOT_DIR_."/cache/class_index.php");//because you need to delete this file after override
//Do same like this all other file.
}
Thanks,
I'm not really sure how you will work around the part with the custom module (maybe when the module is not configured, you will leave the override classes only defined, and when its configured, you will put the changes there)... still changes in the core files should be done like this - for the Product class:
Make a new file in (basefolder)/override/classes/Product.php
Define the class ass:
class Product extends ProductCore
Do your changes. (override functions, or adding new ones)
You can't override classes from src folder
PrestaShop 1.7 introduces the use of namespaces with its new
architecture, and in short, anything that has namespaces cannot be
overridden. The legacy architecture can still be overridden, though.
But in general, we advise against overriding code. It is better to
extend it. Also, overrides are currently forbidden in the
Symfony-based pages (namely, the Product page and the Modules page).
http://build.prestashop.com/news/prestashop-1-7-faq/#is-there-any-change-planned-to-the-override-system
If you want to override PrestaShop's classes and controllers, you can do it as in previous versions
http://doc.prestashop.com/display/PS16/Overriding+default+behaviors
Related
I am doing a module in Prestashop and I need override the method update in the class CartCore. I have created a class inside the folder override (I have tried in modules/name_of_module/override also) Cart extends CartCore (the file is Cart.php), and I have the next code.
public function update($null_values = false, $hook = true)
{
if (isset(self::$_nbProducts[$this->id])) {
unset(self::$_nbProducts[$this->id]);
}
if (isset(self::$_totalWeight[$this->id])) {
unset(self::$_totalWeight[$this->id]);
}
$this->_products = null;
$return = parent::update($null_values);
if($hook) Hook::exec('actionCartSave');
return $return;
}
I have deleted the file cache/class_index.php and I have activated the overrides in the back-office Performance but it does not work. Only works if I change the original Cart class, but I don´t want do this.
Thanks!
When you create a new Override in a module Prestashop isn't aware of this new file. Deleting the /cache/class_index.php will only force Prestashop to look for new files in the root /overrides/ folder but not in your module /modules/your_module/overrides/ folder.
Your file needs to be placed under the root /overrides/ folder. This process is done automatically when you install your module. Every override files in your module is placed under the root /overrides/ folder. If you create a new override while your module is already installed, Prestashop will not move it for you.
You then have two possibilities. Uninstall and install your module. Or copying this file into the root /overrides/ folder and deleting the /cache/class_index.php file.
Also take into account Niclas Larsson advise to put this file under /overrides/classes/Cart.php.
Overriding default behaviors
Overriding a class
In order to override the Product class, your file needs to be called Product.php and must feature a Product class that then extends ProductCore class.
The file can be placed in either of these locations:
/override/classes/Product.php
/modules/my_module/override/classes/Product.php
Override files a separated in folders based on their types (classes, controllers, modules, ..)
So i think you are doing things right, but you need to add the folder 'classes' in override, and move your file into it.
I'm working with the Webform module of Drupal 7 and I'm trying to modify the hook_webform_submission_presave in the webform.api.php , but it seems that the module is not using this file because I've made modifications but doesn't change anything.
Do I have to say to Drupal in any place to use this file? Or what do I have to do?
First, I hope that you know that you shouldn't change module files directly, but to add hook function to your module and change that "hook" at beginning of function name with your module machine name.
Second, you have to clear all the caches so Drupal will re-scan your module and figure out that there is new hook function and start using it.
So, you have to create your own module first:
https://www.drupal.org/developing/modules/7
Don't be scared - It's just a folder with an info file describing your module and module file it self (in minimal case).
Then, if your module is called "anna" you should create a function inside your module file and name it:
anna_webform_submissions_presave()
And clear the cache - after that Drupal should start calling your hook function.
Modules don't use their .api.php files. These file are there for documentation purpose. That's the standard way for documenting hook definitions.
I have been using the CodeIgniter i18n library by Jérôme Jaglale (http://maestric.com/en/doc/php/codeigniter_i18n), which works great for my project.
But since I need to write separate modules, I recently added CodeIgniter Modular Extensions ( https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc ) and the navigation breaks.
How can I solve this issue please, I would love to use both the i18n library & Modular Extensions.
I think my application navigation fails to work because i18n library introduces adds a language segment in the site url, in my case my url is localhost/index.php/en/home and after adding Modular Extensions, my navigation/links stop working.
Thank you in advance.
Recently, I try to use HMVC with i18n and have similar problem. Below is my solution.
1.first you need to go to here HMVC select "Branches" to download HMVC extension, don't download the one on github it might not work.
2.Unzip HMVC extension inside the folder copy two files "MY_Loader.php" and "MY_Router.php" from core folder to Codeigniter's "application/core" after that copy "MX" folder from "third_party" to Codeigniter's "application/third_party". By this point your HMVC is installed, however it will not work because i18n cause the problem so if you run your website it might not display.
3.You need to get new version of i18n which support both HMVC and none HMVC, the old version of i18n seems not support HMVC. Go to here i18n download it and take time to read the description on github.
4.Before this step I suggest you to backup "application/core/MY_Config.php" and "application/core/MY_Lang.php" in case something goes wrong you can reverst back. Unzip i18n inside folder copy file "language.php" from config folder to Codeigniter's "application/config", copy two files "MY_Config.php" and "MY_Lang.php" from core folder to Codeigniter's "application/core", finally copy "MY_language_helper.php" from helpers folder to Codeigniter's "application/helpers". So far you have new i18n installed, but you need to configure it to make it work, otherwise you might get error message.
5.Open "application/core/MY_Config.php" and replace the line require_once APPPATH . "libraries/MX/Config.php"; to require_once APPPATH . "third_party/MX/Config.php"; then open "application/core/MY_Lang.php" replace the line require APPPATH . "libraries/MX/Lang.php"; to require APPPATH . "third_party/MX/Lang.php";. Why? because it point to the wrong directory, the MX folder is located in "third_party" not "libraries" in case you don't know, if you don't change it you might get error message.
6.To add new language(Not create language file) you need to open "application/config/language.php". You see at top the code block with comment says "Supported Languages" there already have English and Russian language configure for you just need to copy the template and change to the language you want, it's very easy. Be aware folder's name must exactly the same as folder in "application/language".
7.According to i18n github description you need to add these line
$route['^(en|de|fr|nl)/(.+)$'] = "$2";
$route['^(en|de|fr|nl)$'] = $route['default_controller'];
to the "application/config/routes.php". Be aware this line $route['^(en|de|fr|nl)/(.+)$'] = "$2"; in old i18n probably is $route['^(en|de|fr|nl)/(.+)$'] = "$1"; the difference is "$1" have to change to "$2", otherwise you will got problem.
8.To create language file is same as the method you did in old i18n. Now test your website with multi-language to make sure everything work fine.
9.Create your module. How? Create a folder name "modules" inside Codeigniter's application folder, inside modules folder you can start to create your module. That's say you want to create a module call foo, you just need to create a folder name it "foo" and then inside foo folder you can create three folders controllers, models and views. Create a php file with name foo with the code below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Foo extends MX_Controller
{
public function index()
{
echo "<h1>class foo this is module test</h1>";
}
}
Enter url to run your module, if you see "class foo this is module test" then it work.
Remember module class must extends from MX_Controller.
If you still encounter any problem just ask.
I want to use a function in all models class (in project folder and in plugins folder).
Where should I declare it?
Depending on what your function does, you can create a file in the lib folder and then call it from every where in your app. This is useful in a Symfony project to define common functions (like a toolbox).
For example, in the Jobeet tutorial, they define a method called slugify in /lib/Jobeet.class.php (be sure to name the file with .class.php at the end so Symfony will automatically load it). Then, you can call Jobeet::slugify() every where in your app/model/plugin/view.
This solution works with Symfony 1.4:
You create a new file in which you declare the function you want to be available everywhere.
You load that file with the auto prepend file settingin the php.ini file.
If done correctly, that function is available in all your scripts, regardless of model, plugin or something else from your project.
I am new to the kohana php framework. In the modules folder in kohana 3.1, there are many empty files extending the existing classes. Should I write my code in those empty files?
If yes, do I have to make any changes in bootstrap?
If not, where should I place these files? Should they be in a subfolder inside the Application directory or inside the modules directory?
Which all files will I have to copy from the modules to application?
Those empty files you see are aliases created for the class. An example would be the Cookie class, declared as so:
class Cookie extends Kohana_Cookie {}
It's just another way for you to refer to the real class, in this case Kohana_Cookie, without having to type all that out.
So when you use something like Cookie::salt($name, $value) you're really just using Kohana_Cookie::salt($name, $value).
If you want to extend a class, you can drop the files into your application/classes folder and go from there.
check out the docs at http://kohanaframework.org/3.1/guide
especially: http://kohanaframework.org/3.1/guide/kohana/files
you can extend classes in the folder: application/classes/.. or modules//classes/..