Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure constraints system to be less confusing #30

Open
jedateach opened this issue Sep 11, 2014 · 0 comments
Open

Restructure constraints system to be less confusing #30

jedateach opened this issue Sep 11, 2014 · 0 comments

Comments

@jedateach
Copy link
Contributor

jedateach commented Sep 11, 2014

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 DiscountConstraints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant