Discount coupons
Closed this issue · 2 comments
A highly requested feature which I've wanted to implement since the beginning of Shopr is Discount coupons. This issue will serve as a gathering place for checklists and discussions for this feature.
Database structure
I figure we'll add another table and model to the package. I thought about letting each user build their own database design, but eventually landed in the fact that this package is meant to make it as easy as possible to get started with a web shop, while still allowing for flexibility. Most projects won't need to modify the discount functionality or design if we just think it through, and so they shouldn't have to think about how to structure their discount table.
Validation
Some projects may need the ability to add custom validation to make sure the applied discount code is valid according to rules beyond a timestamp, code validation and other default rules. We need to make this easily configurable and modifiable.
Todo
- Database table and model
- REST endpoint for applying a code
- Validation, is the code valid?
- Flexibility so that everyone can add their own validation logics
- Inclusion in the order and confirmation emails
- A good abstraction for applying discounts to each new payment provider
- Access applied discount coupons on the cart summary
- Translatable validation errors
- Tests
One idea on the validation is to provide each rule separately in the configuration file, with the most common rules built in. That way anyone could add or remove rules as they'd like. Something like this:
'discount_coupons' => [
'validation_rules' => [
Happypixels\Shopr\Rules\Cart\CartNotEmpty::class,
Happypixels\Shopr\Rules\Discounts\OnlyOneCouponPerOrder::class,
Happypixels\Shopr\Rules\Discounts\CouponHasNotBeenApplied::class,
Happypixels\Shopr\Rules\Discounts\CouponExists::class,
Happypixels\Shopr\Rules\Discounts\DateIsWithinCouponTimespan::class,
]
]
Resolved in release 1.1.