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

Coupon not valid when cart promo rule end date is today. #4401

Open
fabianaromagnoli opened this issue Dec 5, 2024 · 2 comments · May be fixed by #4409
Open

Coupon not valid when cart promo rule end date is today. #4401

fabianaromagnoli opened this issue Dec 5, 2024 · 2 comments · May be fixed by #4409
Labels

Comments

@fabianaromagnoli
Copy link

Preconditions

  1. OpenMage version 20.6.0
  2. PHP 8.0

Steps to reproduce

  1. Setup a cart promo rule with a specific coupon. Set both start date and end date with current date.
  2. Go to fronted, add a product to cart and go to the cart page
  3. 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.

@fabianaromagnoli
Copy link
Author

This patch seems to work fine:

--- a/app/code/core/Mage/SalesRule/Model/Validator.php
+++ b/app/code/core/Mage/SalesRule/Model/Validator.php
@@ -179,7 +179,9 @@ protected function _canProcessRule($rule, $address)
                         return false;
                     }
                     // check coupon expiration
-                    if ($coupon->hasExpirationDate() && ($coupon->getExpirationDate() < Mage::getModel('core/date')->date())) {
+                    $couponExpirationDay = Mage::getModel('core/date')->date(Varien_Date::DATE_PHP_FORMAT, $coupon->getExpirationDate());
+                    $today = Mage::getModel('core/date')->date(Varien_Date::DATE_PHP_FORMAT);
+                    if ($coupon->hasExpirationDate() && ($couponExpirationDay < $today)) {
                         $rule->setIsValidForAddress($address, false);
                         return false;
                     }

@addison74
Copy link
Contributor

Please create a PR to help us checking this issue.

fabianaromagnoli added a commit to fabianaromagnoli/magento-lts that referenced this issue Dec 9, 2024
@addison74 addison74 linked a pull request Dec 9, 2024 that will close this issue
@addison74 addison74 linked a pull request Dec 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants