Override Prestashop 1.6.1.4 - php

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.

Related

PrestaShop 1.7 override src file in own module

I create own module and I want to override some file so in views folder I create folder PrestaShop and in it I add complete path to file like Admin/Catalog/Product/List/somefile.php and this override works, but when I want override file from src folder there is nothing happend. For example I want to override file public_html/src/Adapter/Product/PriceCalculator.php so in my module I have public_html/modules/mycustommodule/views/PrestaShop/src/Adapter/Product/PriceCalculator.php and this is not work. There is any possibility to override those files?
I think that is not possible to override this folder, you can't overrides of other things than classes/controllers/modules with /override/ directory is not available anymore.
You can reed informations about that in their post : planned to ovverride

Prestashop - How to override another module in own module

I create own module. This module should override the BlockCart class.
I created a file /mymodule/override/blockcart/blockcart.php but this file is not executed.
I can not place this file in / override because the module must work on several shops and the instalation must works.
How I can do this?
You have to put your file in the right path of your module:
mymodule/override/modules/blockcart/blockcart.php
Then your blockcart.php should be like this:
class BlockCartOverride extends BlockCart
{
/* your stuff */
}
During the installation PrestaShop install your override.
Useful link:
- How to override modules

Override core files using module prestashop

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

Magento2 : How can override vendor/module-catalog to magento default theme?

I am trying to override vendor/magento/module-catalog/* ( * for whole module ).
I copied,
vendor/magento/module-catalog/view/templates/*
files under
app/design/frontend/Magento/Magento_Catalog/*
But I can't get any change of copied files. I don't have any custom theme.
How can I do this? I want to keep original files unchanged with my custom changes.
You can override all files from vendor to our theme using below method.
Goto vendor\magento\module-catalog\view\frontend
Copy all folders and files to
app\design\frontend\{Your_vendor}\{Theme_name}\Magento_Catalog
Clear your cache using below command.
php bin/magento cache:clean
Refresh your page you can see files from your theme.
You can use this as a theme.
app/design/frontend/Magento/Magento_Catalog/
First, you have to create your own theme containing folder like:
app/design/frontend/Mytheme/Theme/Magento_Catalog
And select the theme from admin.
Then this folder will override core module_catalog

Symfony 1.4 - Doctrine - Custom Plugin - How do I get plugin model files to reside in plugin directory?

I am creating a custom plugin, and am trying to keep all related model files contained within the plugin directory structure. However, when I build the model, some files get dropped into lib/model/doctrine/... and others in plugins/userPlugin/lib/model/... . According to Doctrine docs I can add a "package" option to the schema.yml file, and generated model files will be created in the location as defined by my dot-notation entry, for example:
# plugins/userPlugin/config/doctrine/schema.yml
connection: store-rw-user
options:
# Fully expect resulting model files to be dropped in this directory (vs the main model dir)
package: userPlugin.lib.model.doctrine
....
As mentioned, this config setup still results in model files being dropped into the main lib/model/doctrine directory. I even tried this, to no avail:
# plugins/userPlugin/config/doctrine/schema.yml
connection: store-rw-user
options:
package: userPlugin
package_custom_path: /tmp/userPlugin
....
Just wanted to see if the files were dropped in the /tmp directory, but they were not.
Before I start tearing apart the source code, I figured I would ask first, to see if there is something I am missing.
It's perfectly normal to get model files in your project directory after building. The purpose of this is to let you customize the plugin model on per-project basis, because the classes inside these files inherit from the classes defined in the plugin's files. I use plugins too, and most of the time, all the code I write resides in the plugin's model files.

Categories