vm0824 Posted February 4, 2018 Share Posted February 4, 2018 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 More sharing options...
Pierre_d Posted February 4, 2018 Share Posted February 4, 2018 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! Link to comment Share on other sites More sharing options...
vm0824 Posted February 6, 2018 Author Share Posted February 6, 2018 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 Create a module In the install of the module, create a new table, hook to product page, cart page. Update the table via import? or maybe some custom access to the DB? 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 More sharing options...
Pierre_d Posted February 7, 2018 Share Posted February 7, 2018 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 More sharing options...
vm0824 Posted February 16, 2018 Author Share Posted February 16, 2018 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 More sharing options...
Pierre_d Posted February 17, 2018 Share Posted February 17, 2018 Hi vm, I just saw your post. I'm busy with some other tasks for the moment, but I'll try to answer your questions on Monday. Pierre Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now