Jump to content

Class override not working


DD_DD2

Recommended Posts

Hello,

 

I implemented an override of the function filterOutField from SpecificPrice Class.

The new file is located in \override\classes\

and its content looks like that:

class SpecificPrice extends SpecificPriceCore
{
    protected static function filterOutField($field_name, $field_value, $threshold = 1000000)
    {
     ...
    }
}

I deleted /app/cache/dev/class_index.php and /app/cache/prod/class_index.php.

 

Nothing happens this override doesn't work.

 

Does anyone know if this override is allowed in PS 1.7, and if yes why it doesn't work ?

 

Thanks in advance for your help.

 

 

 

 

Link to comment
Share on other sites

  • 1 month later...

Hello,

 

I implemented an override of the function filterOutField from SpecificPrice Class.

The new file is located in \override\classes\

and its content looks like that:

class SpecificPrice extends SpecificPriceCore
{
    protected static function filterOutField($field_name, $field_value, $threshold = 1000000)
    {
     ...
    }
}

I deleted /app/cache/dev/class_index.php and /app/cache/prod/class_index.php.

 

Nothing happens this override doesn't work.

 

Does anyone know if this override is allowed in PS 1.7, and if yes why it doesn't work ?

 

Thanks in advance for your help.

Same problem with Order.php override  on PS 1.7.1

Link to comment
Share on other sites

From what I know, overrides are no longer supported in Prestashop 1.7. Or rather, let me re-phrase that, overrides are still usable to some degree:

 

"[..] overrides work as usual on all classes that have no namespace (so you can still override Product, Address, etc.)."

 

Quote from:

 

http://build.prestashop.com/news/prestashop-1-7-faq/#can-developers-still-use-overrides-in-17

 

Also, a quote from NemoPS's blog:

 

"[..]PrestaShop 1.7 will not use overrides anymore. The article states legacy architecture will still be usable; however the back office’s Product and Modules page will not allow their usage. Into human language, it means all modules currently (wisely) using overrides will have to drop the system in future 1.7 versions."

 

However, I'm not very knowledgeable in using overrides so I'm unsure if what you're trying to do applies to this.

Link to comment
Share on other sites

  • 2 months later...

@1989

As the override doesn't work despite no namespace, I simply opened the /classes/SpecificPrice.php and changed the lines I wanted to change.

The pity doing that is that it will not remain changed through a one click update  :(

Link to comment
Share on other sites

SpecificPriceCore extends the ObjectModel, and ObjectModel uses the following namespace

use PrestaShop\PrestaShop\Adapter\ServiceLocator;

Perhaps the namespace from the parent class is preventing the override,

 

or perhaps the fact that ObjectModelCore implements something from the NEW architecture interfers...

abstract class ObjectModelCore implements \PrestaShop\PrestaShop\Core\Foundation\Database\EntityInterface

If you can't do something with the override, then try doing it with a module.  If a module cannot do it, then the only thing you can do is what you have done.  Try submitting an enhancement request to Prestashop using their forge, and perhaps they can add another module hook to solve what you are trying to accomplish.

Edited by bellini13 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 8 months later...

Hi everyone,

i'm looking for help for a question, but nobody help to me, i try ask here because i have see conversation about Specific price.

I have PS 1.7.2.4, i would like make specific price product for discount, by Total cart amount, and not by Quantity product.

It's possible make any change for make this? Please someone can help me to make any changes to any files, for this?

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hi everyone,

 

I got the same problem. I need to add attributes to an class (seller) of a module (JA MARKETPLACE). It seems logical to me that the proper way is to override the class.

How i supposed to do if we can't ? What is the best solution to have a coherent and reusable structure and a durable solution ?

 

Thank you for your answers.

 

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

This one was helpfull.

I added it once to make it work, then I could comment it and it's still working ! Something was broken down there

 

On 8/18/2017 at 1:15 PM, bellini13 said:

SpecificPriceCore extends the ObjectModel, and ObjectModel uses the following namespace


use PrestaShop\PrestaShop\Adapter\ServiceLocator;

Perhaps the namespace from the parent class is preventing the override,

 

Link to comment
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
×
×
  • Create New...