basket
basket copied to clipboard
Discounts
Loved your accompanying articles to this project. Very helpful.
I had a question about how you're handling discounts (and coupons).
At the moment, they are part of the Product
object. How would you deal with a discount that should be applied to the basket and not directly related to a product. Something like "$10 off your entire order"?
I was wondering this too. Since there is a discounts
property on the last example of the readme, I guessed there was a way to do this.
Part 6 of the series leads me to think that I could calculate any order-specific discounts inside my implementation of DiscountsMetaData
.
Thank you Jason, I'm glad you found them helpful :smile:
Yeah that is something that I was thinking about when I was initially writing this package. I only had the requirement for product specific discounts. I decided to not have order wide discounts to keep things simple and then see if there was actually a need for them. I guess there is actually a demand for them haha :smile:
I'll have a think about how to add order specific discounts.
I'm trying to implement something so discounts can be added on the basket.
Sadly, the 2 discount class (+interface) are currently tightly coupled to a Product
. Ideally, those would not be coupled.
I don't think it's the Discount
responsibility to calculate the discount on a product.
I probably will have to create 2 new discount classes.
I think, this is a possible quick solution: https://github.com/ennosol/basket/pull/6
Oh, nice.
How's that used client-side. Can't see a test which describes the usage.
Thanks!
public function should_add_a_discount()
{
$this->basket->discount(new PercentageDiscount(20));
$this->assertEquals(20, $this->basket->discount->rate()->int());
}
https://github.com/ennosol/basket/blob/2b3e552857975ab018018a29624e7578fad20c1f/tests/BasketTest.php#L88-L93
https://github.com/ennosol/basket/blob/2b3e552857975ab018018a29624e7578fad20c1f/README.md#basket-1
Awesome :+1: !
Thanks. Be careful:
Basket:
The basket discount will be overwrite the product discounts.
Product:
There is a limitation at discounts, only one discount allowed for a product, if there was another discount in the Collection, that it will be overwritten. So the $product->discount always will be return with only one discount.
Hey @philipbrown! Any progress on implementing basket discounts?
@juukie No, to be honest I haven't used this since I made it open source. If you want to work on it I'll make you a contributor (or you can just fork it if you want) as I have no plans to work on it.
Thanks @philipbrown, I'll fork and see if I can make it fit the projects needs. I'll push valuable changes to the repo.