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.
The idea for this module was born in OXID forums, my mate @vanilla-thunder helped me to get it running 🙂
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:
This doesn’t work for me. I activate module and don’t anything change regarding the price.
This article was written more than a year ago using an older version of OXID eShop. Most likely something changed in the mean time so the module will not work any more without some adaptions. Also this article was written for educational purposes in order to give an idea about module writing in OXID eShop; sorry – can’t maintain these modules.
Obviously the best solution for you would be to request help in the forums (http://forum.oxid-esales.com/forumdisplay.php?f=7). Please give as much information as you can: your shop version, did you download the module from GitHub or did you write it yourself using this tutorial, the settings you use etc.