Page 1 of 1

How to write my own ProductImpl?

Posted: Sat May 24, 2014 5:57 am
by gowthamgutha
I've written a class extending ProductImpl in a package called com.mycompany.core.catalog.domain which is placed in the core module.
For my site, I have added two additional fields to the BLC_PRODUCT table and therefore I would like to add those fields to the corresponding My ProductImpl class.

Now, my question is how do I activate My ProductImpl instead of ProductImpl provided by the broadleaf?

Thanks in advance.

Re: How to write my own ProductImpl?

Posted: Wed May 28, 2014 1:34 pm
by phillipuniverse
You've done what you need to. The only difference is that when you import your data, you also need to import primary keys into your new table that is created when you extended ProductImpl (like MY_PRODUCT).

That basically changes to 2 statements:

Code: Select all

INSERT INTO BLC_PRODUCT (ID) VALUES (1);
INSERT INTO MY_PRODUCT (ID, CUSTOM_FIELD1) VALUES (1, 'somevalue');


Hibernate will give you the correct instance (your ProductImpl subclass) if those join columns are correct. So when you actually query for a Product with id of 1, Hibernate will actually give you MYProductImpl rather than a ProductImpl.

If you are adding new products in the admin and you want to always be adding your own subclassed type (and you never want to just add a Broadleaf ProductImpl) then you can control this with the @AdminPresentationClass annotation on your custom type.

Re: How to write my own ProductImpl?

Posted: Sat May 31, 2014 5:40 am
by gowthamgutha
I don't actually have a table called the MY_PRODUCT, instead MyProductImpl directly represents the BLC_PRODUCT.
I have directly modified the BLC_PRODUCT table without creating additional table.

Now all that I need is MyProductImpl has to be activated instead of ProductImpl for BLC_PRODUCT table.

Thanks.

Re: How to write my own ProductImpl?

Posted: Sun Jun 01, 2014 11:52 pm
by phillipuniverse
That's not really how class hierarchies in Hibernate works, to my knowledge. You might just be looking for single-table inheritance (where everything is stored in a single table). We have some docs on how to do that at http://www.broadleafcommerce.com/docs/c ... s-tutorial.

Re: How to write my own ProductImpl?

Posted: Mon Jun 02, 2014 2:36 pm
by gowthamgutha
I mean i want to completely eliminate the ProductImpl (given by Broadleaf) and replace it with my own MyProductImpl which would point to the same BLC_PRODUCT table.