duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/simple-commerce
Other
143 stars 34 forks source link

[7.x] Include order when dispatching `CouponRedeemed` event #1091

Closed sbrow closed 4 weeks ago

sbrow commented 1 month ago

On my shop, we have an affiliate program. We primarily use coupon codes to track which orders are assigned to which affiliate users. I created a listener for this (on the CouponRedeemed event), only to find that it didn't include the order on which the coupon was redeemed.

This PR fixes that. I added a test to ensure that it works, and AFAIK it should be backwards compatible with base simple-commerce, however any custom packages that emit CouponRedeemed will break. This could however be made more compatible by making $order default to null, and then waiting until the v8 release to make it non-optional- I leave that to you to decide.

sbrow commented 1 month ago

Upon further thought, I decided that $order should be nullable. Even though I highly doubt anyone is manually creating CouponRedeemed events, adding an additional, non-optional argument does constitute a breaking change, which would break semantic versioning.

I've added another test to ensure it is nullable.

sbrow commented 1 month ago

Ran Laravel pint on the files so they'd pass the check.

sbrow commented 1 month ago

Do you require anything else from me to get this merged? :)

duncanmcclean commented 1 month ago

Nope, I just need to find some time to get this reviewed.

github-actions[bot] commented 4 weeks ago

Released as part of v7.3.0.