I've been hired to add a feature to a site that uses Zen-cart. The customer gets the equivalent of a gift card balance by making a purchase from another site, that can be used on my customer's site. The tricky thing is that it needs to be used in discounts on purchases. So a buyer might get 20% off on every purchase until the balance is used up.

I don't see a setting that can do this, and was planning to write the code to do that.

I can make a table for the balance and can do the calculation easily, but would need to retrieve the price variable for a selected item, check for a balance and do the calculation, then return a modified price to Zen cart to process in the normal way. I don't want to get into the Zen Cart code any more than necessary, of course, and don't want to make major modifications to the current layout, since it's already established and I don't maintain that.

Is there a tutorial for something close to that, or can anyone give me a hint about where to start? I work with php every day, but am not familiar with Zen Cart.