Jump to content

Product class and ProductCore class


henryyao
 Share

Recommended Posts

Hi nerds,

 

I am confused on how prestashop classes infrastructure works. in many places like FrontControllerCore::init, it calls "new Product()" to load a product object. However, there is no class called Product and I tracked ProductCore::__constructor isn't called either. Does anyone know how a Product object is constructed?

 

Thanks,

Henry 

Share this post


Link to post
Share on other sites

What are you guys doing things on Sunday? For me, Sunday is a day to rest, just because I went out Saturday night, xD

 

Here we go,

 

You can create an object product calling "new Product()". it calles the ProductCore Class and that constructor, and creates a new Product.

 

 

Don't worry about the "Core" suffix.

Share this post


Link to post
Share on other sites

I expect it to work like that, but when I make change to ProductCore, it has no impact to new Product() code path. I am wondering if I need to somehow re-compile or do some other magic?

What exactly are you trying to do?  What code change did you make?

Share this post


Link to post
Share on other sites

Hi Raphael,

 

Thanks for your reply. I am sorry if you feel offended by "nerds", we use that a lot in my company.

I understand the way overrides works, thanks for your pointer. However, I still don't understand the following behavior:

Let's take Translate::getAdminTranslation() function as example.

 

It was called in AdminControllerCore::l() function, for translations of BO text fields. When I modify the return value in AdminControllerCore::l(), it shows in BO accordingly, everything makes sense. However, when I change the return value in TranslateCore::getAdminTranslation(), nothing happens. I even tried to delete the file /classes/Translate.php, everything still works properly. 

 

 It makes me feel I am not modifying the right file. But I can't find any other place which have getAdminTranslation() function defined.

 

Does what I described make any sense to you? 

 

Thanks,

Henry

Hello,

 

Everything is explained in this documentation : http://doc.prestashop.com/display/PS16/Overriding+default+behaviors

It's a way to allow classes overrides.

 

Regards,

 

Ps : please don't call people "nerds", it's a pejorative word ;)

Share this post


Link to post
Share on other sites

Again, show what you are doing.  Provide the code from your override class...

 

Also, after you install an override, Prestashop registers this override in a cache file.  So once installed, refresh your back office dashboard and then open the /config/class_index.php file

 

Search for the class that you have overriden (Translate) and confirm it has been registered.  This is what it looks like when there is not an override registered

  'Translate' =>
  array (
    'path' => '',
    'type' => 'class',
    'override' => false,
  ),
  'TranslateCore' =>
  array (
    'path' => 'classes/Translate.php',
    'type' => 'class',
    'override' => false,
  ),

 

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