THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 Custom Product class

(22-03-2014 16:59:06)


Greetings,

Recently I've become part of a project aimed at making a custom e-commerce solution.
Thelia2 has been an excellent choice for everything we have done so far.

I'm assigned with making a solution for extendable products,
But I have had no luck so far. I can't find any documentation on making product extensions,
and after a day of work with little to no progress I'm starting to wonder if it's possible without making
it an extremely hacky solution.

I have read the documentation extensively, but just can't figure out the proper way to solve it.

What I would like to do:

  • Create a custom 'product' class that's easily expandable.

  • Manage the custom product class from the thelia back-end.

  • Seperate the solution from the thelia, so it doesn't need a complete rewrite on updating the framework.

  • Create a custom bundle to manage the custom product and its dependencies (preferably)

  • Store the custom products in a seperate table (preferably).

I hope you can help steer me in the right direction, or even give me some example code.
Thanks in advance!

Yours sincerely,
Tim.

Offline

#2 Re: Custom Product class

(22-03-2014 18:54:25)


Hi Tim,

You can do all that in a module. Basically, this module (let's call it MyModule) will manage a database table which contains the additional product data. You'll then provide a custom loop (say, MyModule\Loops\MyProduct class), that will extend the core Thelia Product loop (Thelia\Core\Template\Loop\Product), and return the additional data, by overriding the parseResults() method.

You'll the registrer this loop as the default Thelia Product loop in the <loops> section of the module's config.xml file :

    <loops>
        <loop class="MyModule\Loops\MyProduct" name="product"/>
    </loops>

You're done ! Your product data are now available everywhere in the front-office template.

To manage you product data from the back-office, you can use the "product-edit" include hook, which will include the MyModule/AdminIncludes /product-edit.html file as a Smarty template in the product's "Modules" tab.

You can also create a specific page that will be displayed through the module's "Configure" button in the Modules section of the back-office. To do so, you can :

1)  use the "module_configuration" hook: the AdminIncludes/module_configuration.html file will be included as a Smarty template
2) create your own template and controllers, and provide a route named "/admin/module/MyModule"

The "Colissimo" module is a good example of a T2 module, and demonstrates point 1)

The TheliaDebugBar module demonstrates point 2).

You can do A LOT more customization of Thelia data and behaviour in a module, specially manipulating events and events data. Be sure that a documentation about the fine art of writing T2 modules will pop up soon.

Hope it helps.


OpenStudio Toulouse