How do I get my homegrown module to override a theme function from another module?

E.g. My homegrown module (let's call it qdiscount) wants to change the way product price is displayed. This is normally handled by the function theme_product_price in ecommerce/product/product.module.

Now, I know that if I have a theme called e.g. mymarine, then I can define a function called mymarine_product_price in mymarine/template.php, and that will override theme_product_price.

BUT I want to be able to use qdiscount without having to define a theme that understands it. qdiscount should be independent of mymarine, if you get my drift.

So, what do I need to do (in template.php or wherever) to make the override?

Any help gratefully received. I've read the Drupal book and searched around but can't find any examples of what I'm trying to do.

Comments

mooffie’s picture

Why do you want to override this function? To change its logic? ecommerce already provides you tools to alter a product price.

Whatever,
Instead of 'mymarine_product_price', define 'phptemplate_product_price'. Virtaually everybody uses the 'phptemplate' engine, so it should work. Yeah, it's not very nice.

lucyconnuk’s picture

Thanks Mooffie, that's exactly the conclusion I came to in the end.

The reason I wanted to override was because I am adding a quantity price - i.e. I define an additional price to be used if the customer is buying more than say, 25.

So when a product node is displayed, I want to display a little table instead of a single price, like this:

Quantity | Price
----------------
1-24 | £25
25+ | £20

You can see it here:
http://wwf.finsta.co.uk/d/node/22

Lucy C

mooffie’s picture

Quantity | Price
----------------
1-24 | £25
25+ | £20

There are two ways to understand this table.

If I buy 26 items,

do I pay £25 for each of the first 24 items plus £20 for each of the 2 extra items?

or do I pay £20 for each of the 26 items?

The wording on your site ("Price Each") suggests this is the latter possibility. But then it wouldn't be ecomonical to buy from 20 to 24 items...

lucyconnuk’s picture

It's a good point, but for the moment I'm going with the low-tech solution - the firm always contacts its customers between order and confirmation anyway, and they will either point out that buying 24 items doesn't really make sense, or give the customer a discount anyway.

Presumably other e-commerce sites (not just Drupal ones) also have this problem and get round it somehow, and my next task will be to find out how.

Lucy C