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

Canceling order with a coupon code for logged in users FAILS #1472

Closed
gkopec opened this issue Feb 22, 2021 · 2 comments
Closed

Canceling order with a coupon code for logged in users FAILS #1472

gkopec opened this issue Feb 22, 2021 · 2 comments
Labels

Comments

@gkopec
Copy link

gkopec commented Feb 22, 2021

Preconditions (*)

  1. OpenMage 19.4.10
  2. It's probably Magento bug but hard to say and it actually doesn't matter

Steps to reproduce (*)

  1. Create or use a Coupon Code (Shopping Cart Price Rules) and leave Uses per Customer field empty or put 0.
  2. Use this code for order placed by Logged in User
  3. Make sure to choose a payment method which won't create an invoice or change the order state. The order should be in pending state.
  4. Go to admin panel and try to cancel the order

Expected result (*)

  1. The order should be canceled

Actual result (*)

  1. Order can not be canceled message.
  2. Mysql Exception:
Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`open_mage`.`salesrule_customer`, CONSTRAINT `FK_SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE ON UPDATE CASCADE) in /Volumes/Workspace/om/shop/magento/lib/Zend/Db/Statement/Pdo.php:228

Reason:

In Mage_SalesRule_Model_Observer:162 system is trying to decrease the code usage amount in salesrule_customer but there's no entity to change. Used promo rule had no limitation per user, so Magento didn't create an entry after order placement.

My solution:

It could check if the entity exists ($object->getId()) before trying to manipulate it.
Mage_SalesRule_Model_Observer:162
instead:

if ($customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId())) {

use

$customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId());
if ($customerCoupon->getId()) {
@gkopec gkopec added the bug label Feb 22, 2021
@luigifab
Copy link
Contributor

Same problem, I found the same solution but not why. #1220

@gkopec
Copy link
Author

gkopec commented Apr 30, 2021

Fixed by #1473

@gkopec gkopec closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants