FFggs Posted February 26, 2015 Share Posted February 26, 2015 Cheers all, I'm a PHP developer working on an existing PrestaShop site trying to deal with the override mechanism, I'm a PS newbie but I read the documentation. A big thank you to those who will read and reply to my following questions.The site (v1.6.x) uses a template where I'm asked to change small details such "move this 10px to the left" or "add a input field below this image". Most of these questions come from failed attempts to simple edit which didn't reflect in the public site (even after rebuilding PS cache). Q1: Most of the things I have to change come from the theme itself or some core page (one is in the main root, not even in the classes/controllers folders). I read several threads on this forum suggesting to clone the theme and "hard-code" changes on the cloned theme, but does the theme update itself as happens for modules and so I lose the changes every now and then? Q2: When overriding a class/controller/module, I assumed if I need to change things only in (example) the PHP file I do not need to prepare/upload eventual tpl/css/whatever that the original module/controller/etc had, right? I create only what I need to change right? Q3: overriding a php file basically asks me to extend the class that the original .php file constitutes, eg. a file called "randomclass.php" is considered the "randomClassCore" class and in my override file I'll set up my "randomClass" to extend said "randomClassCore" class, did I get this right? Q4: php files are overridden as classes extension, but what about .tpl and .css files? Should I just clone what is in the original file and edit/add/remove what I need? I did this for a .tpl within the template but it didn't work. One file I worked on was located in root\themes\theme_name\shopping-cart.tpl and I put the override in root\themes\theme_name\override\shopping-cart.tpl, rebuilt cache, and no change happened so I assume it's the wrong folder? Q5: about translations, when in the .tpl file I find things such "{l s='ok'}", there is a way for me to conveniently detect in the admin page which field is the one that provides that translation? (there are A LOT of lines!) A huge thank you to those that will invest their time explaining me or giving me hints about my problems/doubts, have a great day! Link to comment Share on other sites More sharing options...
bellini13 Posted February 26, 2015 Share Posted February 26, 2015 (edited) Q1: Most of the things I have to change come from the theme itself or some core page (one is in the main root, not even in the classes/controllers folders). I read several threads on this forum suggesting to clone the theme and "hard-code" changes on the cloned theme, but does the theme update itself as happens for modules and so I lose the changes every now and then? It is possible that if you upgrade a module, and that module has been designed to replace your theme files, then yes you could lose your changes. But that is the exception, not the rule. Cloning your theme is not required if you are using a third party theme. However if you are using the default-bootstrap theme, then yes cloning it is a good idea. If you upgrade PS in the future, then you will most certainly lose your customizations. Q2: When overriding a class/controller/module, I assumed if I need to change things only in (example) the PHP file I do not need to prepare/upload eventual tpl/css/whatever that the original module/controller/etc had, right? I create only what I need to change right? This is too broad of a question, so I need to be broad in my answer. Be more specific in your question. For core class and controller overrides, you would only override what you need to change (like a specific function) For theme file overrides (like css, js), you are replacing the entire file with your new file. You cannot override a themes .tpl file For module overrides (PHP files), it is similar to core overrides, you only need to override what you want to change For module overrides (css, js etc), you would place these in the appropriate folder in the theme Q3: overriding a php file basically asks me to extend the class that the original .php file constitutes, eg. a file called "randomclass.php" is considered the "randomClassCore" class and in my override file I'll set up my "randomClass" to extend said "randomClassCore" class, did I get this right? yes, you got it right Q4: php files are overridden as classes extension, but what about .tpl and .css files? Should I just clone what is in the original file and edit/add/remove what I need? I did this for a .tpl within the template but it didn't work. One file I worked on was located in root\themes\theme_name\shopping-cart.tpl and I put the override in root\themes\theme_name\override\shopping-cart.tpl, rebuilt cache, and no change happened so I assume it's the wrong folder? You are talking specifically about altering a core theme template file, so my answer is specific to that scenario. You cannot override a themes .tpl file. Your only option is to edit the file. or clone the theme and customize the file to your liking Q5: about translations, when in the .tpl file I find things such "{l s='ok'}", there is a way for me to conveniently detect in the admin page which field is the one that provides that translation? (there are A LOT of lines!) If the .tpl file is from a module, then you can narrow it down by going to the module configuration page and selecting translate. If the .tpl file is from the front office theme, then you can narrow down the field based on the file name. For example, if the file is 404.tpl, then all of those translations will be in the section labelled '404' (which has 8 expressions). If the .tpl file is from the back office theme, then it is similar to the front office. The translations are group based on the admin page. So if you want to translate a .tpl from the AdminAddressController page, then look in the section named 'adminaddresses' (which has 27 expressions) Edited February 26, 2015 by bellini13 (see edit history) 2 Link to comment Share on other sites More sharing options...
FFggs Posted February 27, 2015 Author Share Posted February 27, 2015 Wow thank you very much for this deep explanation, bellini13! I didn't expect to learn this much about Prestashop from a single reply, I'll treasure everything.Thank you again, have a nice day and a great week-end. 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