-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
Description
Currently DiscountConstraint extends DataExtension. This was merely to encapsulate the additional db / relation fields that need be extended on a Discount. Also encapsulated is the checking functions that look at those fields and decide if an order/item is within the constraint.
The problem is that it is quite messy. These classes are being instantiated on their own, with functions that are used quite statically. If one of the check or filter functions is called on a $discount object, then it will call only one of the constraints function's.
A restructuring could look like this:
BlahConstraint extends DiscountConstraint{
//has this constraint been added to the given discount
//we automatically skip constraints that haven't been configured during checking
function applies(){
return $this->discount->FooList()->exists();
}
//does the order comply with this constraint
function check(){
//check if (something to do with the order) exists within FooList
}
//function filter(DataList $discounts) should be optional
}
BlahConstraint_DiscountExtension extends DiscountConstraintExtension{
private static $has_many = array(
'FooList' => 'Foo'
);
}
// elsewhere the DiscountConstraintExtensions are applied, based on a configured list of DiscountConstraintsReactions are currently unavailable