Jump to content

How to override module logic


MvdP
 Share

Recommended Posts

Hello,

I have been searching my ass off for a solution but cannot find anything relating to this... so I hope someone can help me with my problem.

I would like to change the logic of the standard 1.4 module "productscategory" without touching the standard files.

To be precize "productscategory.php" line 119:
$categoryProducts = $category->getProducts((int)($cookie->id_lang), 1, 100); /* 100 products max. */

I would like this instead to only load 4 random products from the same category.

I know how to modify the getProducts call... but as I said I would not like to modify the original file.

So is there a possibility to override the original file with a custom one for me to modify to my wishes?

Thanks in advance,
Mark

Share this post


Link to post
Share on other sites

I don't think there is a way to override a module class (PHP) file.
If you are using 1.4 of PrestaShop, you can override core class (they are in /classes folder).

For module, you can only override the theme file by create theme under
YourSiteRoot/themes/YourSiteTheme/Modules/YourModule/YourModule.tpl

(maybe you can find a way to implement your requirement in theme file?)

Share this post


Link to post
Share on other sites

Thanks shokinro!

I was already afraid for that... and have been thinking of doing it in the .tpl file... but its not really an option.

Would it be an idea to copy the module... change the naming and then modify the module class?

Share this post


Link to post
Share on other sites

  • 1 month later...

In Prestashop 1.4 you can override a modules class (PHP) file by placing a modified copy in /override/modules/[modulename]/[filename]
This file will completely replace the original class file in /modules/[modulename]/, so you will have to copy the whole class PHP file and edit that copy. And you will have to update the file manualy when the original file is updated.
You cannot use "class ModuleName extends ModuleNameCore", like you can for the core classes.


With the core classes you can extend the core class with only a couple of lines.
For example, if you want to give all products a standard price of € 100, you can create a file /override/classes/Product.php with only the following code:

<?php

class Product extends ProductCore
{
   public         $price = 100;
}

This will only override the default value for $price, and take the rest of the variables and functions from the core class ProductCore in /classes/Product.php

Share this post


Link to post
Share on other sites

  • 2 weeks later...
In Prestashop 1.4 you can override a modules class (PHP) file by placing…

Nope, creating a “modules” subdirectory beneath /override
and placing “custom” files in this /override/modules path
will have no effect.



ok, so , which is the correct solution..? :)

Share this post


Link to post
Share on other sites

— disable the native module, copy it to a new path / filename / classname and modifiy it to suit, then enable the modified copy

I agree with Angora's suggestion.

But please note, you must follow his suggestion to disable the old module or just removed it physically.
otherwise, it will affect each other because they sharing same settings.

if you want to make it completely new module, then following my link on my post "Posted: 12 April 2011 07:17 PM"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More