-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Added check for coupon expiration date #3144
Conversation
This create a huge side effect! If you have multiple coupon code with same code in multiple rules, if one of the coupon is expired, this prevent another rule to work (here 8829).
|
Yikes! What should the correct behavior be? Check all coupons or just the newest one? For example here is checking the newest one:
|
@luigifab checkin the code, the same thing would happen if usage limit is surpassed: // check entire usage limit
if ($coupon->getUsageLimit() && $coupon->getTimesUsed() >= $coupon->getUsageLimit()) {
$rule->setIsValidForAddress($address, false);
return false;
}
// check coupon expiration
if ($coupon->hasExpirationDate() && ($coupon->getExpirationDate() < Mage::getModel('core/date')->date())) {
$rule->setIsValidForAddress($address, false);
return false;
}
// check per customer usage limit
$customerId = $address->getQuote()->getCustomerId();
if ($customerId && $coupon->getUsagePerCustomer()) {
$couponUsage = new Varien_Object();
Mage::getResourceModel('salesrule/coupon_usage')->loadByCustomerCoupon(
$couponUsage,
$customerId,
$coupon->getId()
);
if ($couponUsage->getCouponId() &&
$couponUsage->getTimesUsed() >= $coupon->getUsagePerCustomer()
) {
$rule->setIsValidForAddress($address, false);
return false;
}
} so I don't know... |
I'm not sure, I simply reverted this PR, and now my coupon code is working. Here (l. 177) we are loading the coupon by code, perhaps we can load it by code and rule id? $coupon = Mage::getModel('salesrule/coupon');
$coupon->load($couponCode, 'code'); |
Ahh yes, by rule id sounds correct to me..
However, I never use this feature so am no expert on it. Are there other circumstances where a rule can have multiple coupons with the same code making it necessary to filter out used up ones or loop through all of them? Just trying to throw out some suggestions, please open a PR if you see fit. |
A new PR for this new problem is required? |
@kyrena I think yes |
Oh yes, true, we are using a module to allow multi coupon code. |
Mage_SalesRule_Model_Validator::_canProcessRule() checks the validity of a coupon code that is in the process of being added to the cart, but it doesn't check for the single coupon expiration date. This PR adds this check.
Manual testing scenarios (*)
Now, what we're about to check isn't really supported by the core but I think it's still worth fixing.
salesrule_coupon
table, you'll find a record with the coupon code you just created aboveexpiration_date
column for that specific coupon and set it in the pastIt is true that the core wouldn't manage the expiration_date column but, since it exists, I know extensions (actually I was developing one today when I found this bug) that set the expiration_data for a single coupon (let's say you want a coupon to be usable only for 7 days after its generation), and it doesn't make sense to me that the core doesn't check for the expiration_date of a coupon.
After applying this PR you'll notice that the expiration_date gets correctly checked, if present.
Related PRs
This PR was already approved in #3029 but I had to recreate it due to rebasing problems.