How to Write a Module for OXID eShop: Round the Price on Product Details Page to a Fiver
For my next tutorial about writing modules for OXID eShop I chose a very simple example. The aim is to round up the display of the price on the product details page to the next five cent (or any other currency of your choice). This is because there are countries where it doesn’t make sense to display prices like 7.99 EUR because the value doesn’t even impact on your money bag and the tax authorities deal with it in a gentler way.
Let’s have a look at the code now. First we have to find the getter for the value of the price. A good starting point for searching for it is the OXID eShop source code documentation. Move into the OXID eShop version you are using and search for getPrice here to find the getPrice() method in the oxArticle function. Hint: getPrice() will return all prices, no matter whether you use prices including or without tax, so it’s brilliant for our purpose.
Move to /core/oxarticle.php now and find the method definition that we want to overwrite on line 178:
Next: copy the entire method and paste it into a new file which we call mst_oxprice_ch_highfive.php in our example. Place this file into /modules/mst/ch_highfive/core/.
Make the necessary changes to this file, i.e.: add
<?php at the beginning, followed by the mandatory statement
class mst_ch_highfive extends mst_ch_highfive_parent to make the module work. Then replace the value to your own calculations and you’re almost done. The content of the file should look like this now:
The only thing left is to add the metadata for your module and for your vendor information, maybe an additional icon for it. I described this in more detail in my former blog post “How to Write a Module for OXID eShop: Display “You will save x %” on the Product Details Page“.
I put this ready-to-use extension under the open source license GPLv3 on GitHub again. Please feel free to contribute any additions or changes if needed: