knacky Posted February 21, 2022 Share Posted February 21, 2022 (edited) How to create an override for Core in a module: ./src/Core/Localization/Locale.php => ./modules/my_module/override/PrestaShop/PrestaShop/Core/Localization/Locale.php not work Thank you Edited February 21, 2022 by knacky (see edit history) Link to comment Share on other sites More sharing options...
ZiedDams Posted February 22, 2022 Share Posted February 22, 2022 As far as i know anything in src/Core/* cannot be overridden , look for a hook instead 1 Link to comment Share on other sites More sharing options...
Paul C Posted February 22, 2022 Share Posted February 22, 2022 I try and avoid using ANY overrides in 1.7. What are you trying to do? 1 Link to comment Share on other sites More sharing options...
ZiedDams Posted February 22, 2022 Share Posted February 22, 2022 Just now, Paul C said: I try and avoid using ANY overrides in 1.7. What are you trying to do? i did not say you need to avoid overrides but the problem is prestashop dos not support any override under src/Core so you need to find another way for example a hook , can you explain in more details why you want to override /Core/Localization/Locale.php may be i can help 1 Link to comment Share on other sites More sharing options...
Paul C Posted February 22, 2022 Share Posted February 22, 2022 1 minute ago, ZiedDams said: i did not say you need to avoid overrides but the problem is prestashop dos not support any override under src/Core so you need to find another way for example a hook , can you explain in more details why you want to override /Core/Localization/Locale.php may be i can help I agree with you. In 1.6 overrides were encouraged but for 1.7 they aren't really and I personally try to avoid using them - plus with so many new hooks you can avoid having to use them most times. I'm interested though in what anyone would possibly want to override in that file...... 1 Link to comment Share on other sites More sharing options...
ZiedDams Posted February 22, 2022 Share Posted February 22, 2022 8 minutes ago, Paul C said: I agree with you. In 1.6 overrides were encouraged but for 1.7 they aren't really and I personally try to avoid using them - plus with so many new hooks you can avoid having to use them most times. I'm interested though in what anyone would possibly want to override in that file...... that's true, i agree also . 1 Link to comment Share on other sites More sharing options...
knacky Posted February 23, 2022 Author Share Posted February 23, 2022 (edited) 13 hours ago, Paul C said: I try and avoid using ANY overrides in 1.7. What are you trying to do? Thank you. I'm trying to change my own price display by currency, language, shop, user group etc. In older Prestashop versions, it was enough to overwrite displayPrice in Tools. I need an override Locale::formatPrice() Edited February 23, 2022 by knacky (see edit history) Link to comment Share on other sites More sharing options...
Paul C Posted February 23, 2022 Share Posted February 23, 2022 1 hour ago, knacky said: Thank you. I'm trying to change my own price display by currency, language, shop, user group etc. In older Prestashop versions, it was enough to overwrite displayPrice in Tools. I need an override Locale::formatPrice() Isn't that just a specific price? Or maybe I'm not understanding... The price is the price (and just a number) but how you display it depends on the currency format (and there's just one per currency, although there's nothing stopping you defining a "French Euro" distinct from a "German Euro" etc. I guess). You can also manipulate how things display in the theme too.... I have used specific prices to store additional pricing information for products in the past such as RRP etc. Maybe you could give a few example scenarios? Link to comment Share on other sites More sharing options...
knacky Posted February 23, 2022 Author Share Posted February 23, 2022 16 minutes ago, Paul C said: Isn't that just a specific price? Or maybe I'm not understanding... The price is the price (and just a number) but how you display it depends on the currency format (and there's just one per currency, although there's nothing stopping you defining a "French Euro" distinct from a "German Euro" etc. I guess). You can also manipulate how things display in the theme too.... I have used specific prices to store additional pricing information for products in the past such as RRP etc. Maybe you could give a few example scenarios? OK. I need to change the price display according to the parameters and I also need to change the price format. language 1 | currency EUR | shop 1 | user group 2 => price round 2 decimal (€30.15) language 1 | currency EUR | shop 1 | user group 3 => price round 1 decimal (€30.20) language 1 | currency USD | shop 1 | user group 2 => price round 2 decimal ($30.15) language 1 | currency USD | shop 1 | user group 3 => price round 0 decimal + show decimal = true / false ($30.00 / $30) language 2 | currency USD | shop 2 | user group 2 => price round 2 decimal ($30.15) language 2 | currency USD | shop 2 | user group 3 => price round 1 decimal ($30.2) If you can't do Core override, then there's no point in dealing with it. Override classes or controllers would have to be created, which is nonsense. The functions and override functions of Tools :: displayPrice were easy to edit, it was beautiful to rewrite, add functions, etc. Now the open system has become a closed, non-editable, uneditable system. When Prestashop completely removes the Tools: .displayPrice function, 90% of the price display modules will stop working properly. Link to comment Share on other sites More sharing options...
Paul C Posted February 23, 2022 Share Posted February 23, 2022 To be fair I don't think this is a common requirement as normally you would want to display the price that is going to be charged, exactly as it's going to be charged? I'm probably not properly understanding the requirements though as I'm just a dumb hacker I would probably write a module that provided a (custom) hook I could add into themes at arbitrary locations e.g. {hook h="displayMyCustomPrice" product=$product iso=$currency.iso_code} Obviously you could add parameters for group, rounding, decimal display etc. so your module could format the output correctly. It may not be as transparent as an override but on the other hand it makes it much clearer in the theme where the data is coming from. It also isolates your code and as long as you test your module with a standard install of a new release, then I believe it's also much easier to maintain. Custom hooks are described in the documentation with an example. Are you trying to create a generic module to do this, or is this just for one specific shop? 1 Link to comment Share on other sites More sharing options...
knacky Posted February 23, 2022 Author Share Posted February 23, 2022 17 minutes ago, Paul C said: To be fair I don't think this is a common requirement as normally you would want to display the price that is going to be charged, exactly as it's going to be charged? I'm probably not properly understanding the requirements though as I'm just a dumb hacker I would probably write a module that provided a (custom) hook I could add into themes at arbitrary locations e.g. {hook h="displayMyCustomPrice" product=$product iso=$currency.iso_code} Obviously you could add parameters for group, rounding, decimal display etc. so your module could format the output correctly. It may not be as transparent as an override but on the other hand it makes it much clearer in the theme where the data is coming from. It also isolates your code and as long as you test your module with a standard install of a new release, then I believe it's also much easier to maintain. Custom hooks are described in the documentation with an example. Are you trying to create a generic module to do this, or is this just for one specific shop? Please do not need such advice, I am a programmer of Prestashop modules. This is standard rounding, I just need to extend it. I need advice from someone experienced. Thank you for your effort. These are not the peculiarities you see in that. Rounding is perfectly normal. Unfortunately, the new features in Core are useless. 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