DiscountModule


as of: October 30, 2013

DiscountModules calculate transaction-level discounts. The default behavior is to multiply items with discountable=1 by the percentage in custdata's Discount column. Subclasses may provide an entirely different calculation if necessary. The percentage function lets you apply a different value than custdata.Discount to the transaction. The calculate function allows for more involved changes such as apply different percentages to different items. In general, percentage is a safer choice in that it's less likely to result in odd edge cases.

double calculate()

The return value should be the current discount based on the transaction's state. This value is normally positive.

double percentage(double $custdata_discount)

The return value is the discount the customer should receive. The $custdata_discount argument is the value from custdata.Discount. Both the parameter and return value are expressed as percentages: i.e., 5.0 means a 5% discount.

Example: give members an extra 5% discount on Wednesdays

class WednesdayDiscount extends DiscountModule {
	function percentage($custdata_discount=0){
		// Not a Wednesday or not a member
		if (date('w') != 3 || $CORE_LOCAL->get('isMember') != 1)
			return $custdata_discount;
		else
			return $custdata_discount + 5;
	}
}