Skip to content

Restructure constraints system to be less confusing #30

@jedateach

Description

@jedateach

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions