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

The coupon is not valid and discount is not applied #4409

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

fabianaromagnoli
Copy link

@fabianaromagnoli fabianaromagnoli commented Dec 9, 2024

It solves the issue reported here #4401.

Preconditions
OpenMage version 20.6.0
PHP 8.0

Steps to reproduce
Setup a cart promo rule with a specific coupon. Set both start date and end date with current date.
Go to fronted, add a product to cart and go to the cart page
Try to apply the coupon

Expected result
The coupon is valid and discount is applied

Actual result
The coupon is not valid and discount is not applied

In this piece of code the coupon expiration date is compared to the current datetime, but coupon expiration date always has 00:00:00 time, so that if the expiration day is today, that check cannot pass. Dates should be compared without considering time, like it's done in the Collection where the promo validity dates are compared to $now, and $now is a date without time.

@github-actions github-actions bot added the Component: SalesRule Relates to Mage_SalesRule label Dec 9, 2024
@addison74 addison74 linked an issue Dec 9, 2024 that may be closed by this pull request
@addison74 addison74 changed the title Fix issue #4401 The coupon is not valid and discount is not applied Dec 9, 2024
@sreichel
Copy link
Contributor

Id change the code to not call getExpirationDate before hasExpirationDate.

@sreichel sreichel added this to the 20.13.0 milestone Jan 1, 2025
@fabianaromagnoli
Copy link
Author

@sreichel Thanks for pointing out! What do you think about the refactoring in commit 3cff24f? The very bad thing before this commit was that $couponExpirationDay had a not-null value even when the coupon had no expiration date. Now it is explicitly null if coupon has no expiration date.

@sreichel
Copy link
Contributor

sreichel commented Jan 6, 2025

Mhh, i think that the original code works as expected.

To make a coupon valid only for this this set "to date" to the next day. (thats 00:00:00) - but that unintentional.

I have tested your code, but it does enot work for me. I have an one-day offset in comparison. Wait for PR ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: SalesRule Relates to Mage_SalesRule enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coupon not valid when cart promo rule end date is today.
2 participants