I am writing shop system in CakePHP Framework. I am stuck on writing flexible discount system.
I have Product model that can have many different attributes (ProductVariant Model and ProductAttribute model).
ProductVariant is the part where there is price specified, because I can have physical product with different price and e-product for download with different price (though content is the same). So from this model for consideration is type and price.
ProductAttributes are some properties of product - like category, language etc. (attributes are defined in a key-value way and assigned to product)
Now I want operators to be able to add temporary discounts, discount codes etc. That would apply discounts on product basis depending on it's Variant and/or Attributes.
For instance - discount 20% for physical products in english language or -$5 for download products in german or english language.
I figured out that maybe I should create Models - DiscountType (for percentage discount and just plain discount) - DiscountScope (for discounting specific product ids and/or attributes and/or variants
But I am stuck here, wondering how to define those rule sets so the operator could add them easily (attributes and variants can be added by operator too, so there is infinite number of possibilities here, but accessible from DB of course).
And second part where I am stuck is applying discounts for order processing. Should I use decorator pattern? If so I am clueless now how to apply it in Cake (or just in MVC).
If I can improve my question somehow or provide some parts of code that can help solve the problem please let me know.