basket icon indicating copy to clipboard operation
basket copied to clipboard

Discounts

Open jasonvarga opened this issue 9 years ago • 12 comments

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"?

jasonvarga avatar Feb 27 '15 11:02 jasonvarga

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.

nWidart avatar Feb 27 '15 12:02 nWidart

Part 6 of the series leads me to think that I could calculate any order-specific discounts inside my implementation of DiscountsMetaData.

jasonvarga avatar Feb 28 '15 04:02 jasonvarga

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.

philipbrown avatar Feb 28 '15 13:02 philipbrown

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.

nWidart avatar Mar 23 '15 08:03 nWidart

I think, this is a possible quick solution: https://github.com/ennosol/basket/pull/6

arcadas avatar Apr 01 '15 13:04 arcadas

Oh, nice.

How's that used client-side. Can't see a test which describes the usage.

Thanks!

nWidart avatar Apr 01 '15 13:04 nWidart

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

arcadas avatar Apr 01 '15 13:04 arcadas

Awesome :+1: !

nWidart avatar Apr 01 '15 13:04 nWidart

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.

arcadas avatar Apr 01 '15 13:04 arcadas

Hey @philipbrown! Any progress on implementing basket discounts?

juukie avatar Aug 19 '16 10:08 juukie

@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.

philipbrown avatar Aug 19 '16 10:08 philipbrown

Thanks @philipbrown, I'll fork and see if I can make it fit the projects needs. I'll push valuable changes to the repo.

juukie avatar Aug 22 '16 14:08 juukie