Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an option to automatically add BuyXGetY discount rewards #1733

Open
wants to merge 7 commits into
base: 1.x
Choose a base branch
from

Conversation

ryanmitchell
Copy link
Contributor

This PR provides an option to automatically add BuyXGetY discount rewards.

It adds a toggle to the discount create/edit screen to automatically add.

When selected we work out if any rewards are available that haven't yet been added to the cart and if we so we add them. Along the way we keep track of how many we added, so we can decrement/increment if cart values are changed, and if necessary remove the item from the cart when it no longer is eligible.

Devs can check for whether an item was added by discount by checking the meta->added_by_discount array values ... if the sum is the same as the cart line quantity then it was added by a discount and can be displayed differently (if required).

Replaces #1385
Closes #876

Copy link

vercel bot commented May 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2024 3:54pm

@glennjacobs
Copy link
Contributor

@ryanmitchell the logic doesn't seem quite right for me. Please see below a Loom video demonstrating what I'm seeing.

https://www.loom.com/share/a03f218e2482432abb5e4f5b91346294?sid=2f6843a6-0b63-4f77-9201-3515cf06253c

@ryanmitchell
Copy link
Contributor Author

Ok so to clarify - you would expect it to remove any that have been added? thats a little more opinionated than I had been aiming for (which is fine) - I was leaving them in the cart, but just not marking them as having been added by the discount any more.

@glennjacobs
Copy link
Contributor

Ok so to clarify - you would expect it to remove any that have been added? thats a little more opinionated than I had been aiming for (which is fine) - I was leaving them in the cart, but just not marking them as having been added by the discount any more.

I'm not really concerned about it removing (that's just what I had taken from your description).

and if necessary remove the item from the cart when it no longer is eligible

However, it shouldn't apply the additional product when the qty is 23.

@glennjacobs
Copy link
Contributor

@ryanmitchell from looking at your code, doesn't it try to automatically remove the item?

@glennjacobs
Copy link
Contributor

@ryanmitchell I think the issue with the 23 is that it's probably loading the cart first, which sees it's got 24, so applies the discount and then we update the qty to 23, making it seem like 23 caused the item to be added.

If it auto-removed the item, then I guess this wouldn't happen.

@ryanmitchell
Copy link
Contributor Author

@ryanmitchell from looking at your code, doesn't it try to automatically remove the item?

Yeah it does... it's been too long since I looked at this properly.

@ryanmitchell I think the issue with the 23 is that it's probably loading the cart first, which sees it's got 24, so applies the discount and then we update the qty to 23, making it seem like 23 caused the item to be added.

Yep thats whats happening. I'll try and get another look over the next day or two.

@glennjacobs
Copy link
Contributor

@ryanmitchell I'll try take a look now to see if I can get my head around it

@glennjacobs
Copy link
Contributor

@ryanmitchell having looked at the code further, it's obvious the "removing" part of the code won't be hit as the discount bails on line 69 if it doesn't qualify.

So I propose we don't worry about removing the item, only automatically adding it.

Do you agree? If so, I can look to finish up the PR.

@ryanmitchell
Copy link
Contributor Author

Yep that works for me - keeps it simpler

@glennjacobs
Copy link
Contributor

The outstanding issue on this is the fact that the discounts apply before a qty change is considered, meaning the automatically applied product can come back if the previous qty was above the qualifying amount.

The CartSession Manager calculates the cart on load which causes this. Changing this could have been quite achievable if it wasn't for the estimate shipping logic. @alecritson I'll probably need to discuss this one with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discount BuyXGetY automatically add
3 participants