Jump to content

extending product flags


Recommended Posts

Hello,

  I am VERY new to Prestashop development. I would like to begin by creating a new column for my products as a special flag to categorize products I will later use in my development. I was hoping to get some guidance on how to approach this.

1. Should I just extend the actual table? I fear this might get overwritten during an upgrade or something.

2. Should I create a new table that has the foreign key to the product table and also the specific new columns I want? That way its safe from upgrades in its own unique table.

3. Should I create a module to do this? Seems like a fairly daunting task to create a module to "install" the new table, though maybe simply because I've never created a module. I plan to add more functionality, to the front end (product page, cart) at some point so I suspect this is the correct route.

4. Should I just create hidden categories to use for these flags? And place products in various hidden categories that can be looked up in the TPL code to determine how to display? This might be a simply method than editing the db, but not sure about any limitations. Also, I dont want the customer to be able to see these flags, I will use them to display different things on the product screen based on the flag status and some logic about the customers location.

 

Please let me know. I'm sure this is an easy task, but I cannot seem to grasp the exact approach to do so.

Link to comment
Share on other sites

Hi vm. I don't know exactly what you plan to do, but I would say it's safer to add your own table with a foreign key to the product. Now, if you want to use this "flag" to alter the way the product is displayed, you'll need to test its value somewhere. Either it will be in the template or in the PHP code. In both cases, you'll need to retrieve your flag from the database....

There are several ways to change or add to Prestashop behavior but if you want to do this "clean", you'll need to create a module. Then you can use Prestashop hooks mechanism, which is basically simple: you create a module, you write a PHP method within your module class and you register it to the hook. Prestashop has tens of hooks (display or action). Of course, you need to follow some guidelines for this to work.

Other methods to add to PS are classes or controllers overriding (you extend an existing class and you modify some of the methods). You can also change the display by changing the templates (.tpl files)... You can also provide your own "search providers".

But the deeper you go, the more you'll need to understand how PS works internally! :huh:

Link to comment
Share on other sites

Thanks Pierre! I am very much looking to do this the "right" way. I believe a module is the way to go. I will begin to try and 

  1. Create a module
  2. In the install of the module, create a new table, hook to product page, cart page.
  3. Update the table via import? or maybe some custom access to the DB?
  4. edit TPL for the module to display a message on the products page if this flag is set. I think the best way is to copy the TPL from the starter theme into my custom theme so it sort of overrides (my theme is a small extension of the 1.7 default theme).

 

I would LOVE to learn more about the PS internals. I have found little on Smarty of specific prestashop development. I see some "how to make a module" and some generic coding standards, but nothing really interactive or with examples. If you know of any free resources to help me get more familiar, or even just some examples or case-studies of PS dev, I'd be very grateful.

Link to comment
Share on other sites

I started last year with Fabien Seny's book, "Développez vos propres modules PS". It's not expensive but it's in French and its based on PS1.6. I suppose you should be able to find something in English. Fabien's book is what I've found the most comprehensive and detailed, but it's still fairly basic if you need something beyond just a simple module.

What you plan to do seems ok, but don't forget to Google "prestashop hooks".

I'm currently busy with customer projects and, unfortunately, don't have much time to update my website, explaining in details what I have done. If you decide to develop your own module, which will give you plenty of satisfaction, set up a decent development environment: at least a WAMP (if you're on Windows), a development IDE such as Netbeans (but there are others) and a debugger!! (it will quickly become your best friend!).

And if you have other questions, there is still some activity on this forum!

Good luck ;).

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello Pierre, I was hoping you could help me with my development so far. I have created a test site, configured xdebug, and using phpstorm as IDE. It is working great!

I have created the table, created the new module, and been able to create hooks for my module that display the product flags within the hook. The problem now is I need to make a new hook that resides on the cart item line. That way, you can see the flags for each item on the items within the shopping cart. Do I have to create a new theme for this now and make the changes in the theme? Or is there a way to override the current theme line to add the new hook for me to implement in my module. I've seen a few sites talk about creating a /themes/modules within the module to overrides something, but never actually saw how it is used.

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...