Magento2: Can't Cancel Order

Created on 15 Nov 2018  路  25Comments  路  Source: magento/magento2

Preconditions (*)

  1. 2.2.6
  2. Allow guest checkout
  3. Have a coupon you can use

Steps to reproduce (*)

  1. Checkout as a guest using a valid coupon
  2. After placing the order, register an account using the create account button on the order confirmation page.
  3. Login to the admin
  4. Make sure to get the order to a processing state.
  5. Try to cancel the order

Expected result (*)

  1. The order is canceled

Actual result (*)

  1. You receive the generic errror "You have not canceled the item"
  2. The underlying error is:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mage`.`salesrule_customer`, CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE), query was: INSERT INTO `salesrule_customer` () VALUES () {"exception":"[object] (Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mage`.`salesrule_customer`, CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE), query was: INSERT INTO `salesrule_customer` () VALUES () at /www/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mage`.`salesrule_customer`, CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE) at /www/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"} []

Related Issues

https://github.com/magento/magento2/issues/16779

Sales SalesRule Fixed in 2.2.x Fixed in 2.3.x Clear Description Format is valid Reproduced on 2.2.x

Most helpful comment

i am still having this issue in magento 2.3.3 CE:

All 25 comments

Hi @friendscottn. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@friendscottn do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @maheshWebkul721. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

@magento-engcom-team give me 2.2-develop instance

Hi @maheshWebkul721. Thank you for your request. I'm working on Magento 2.2-develop instance for you

Hi @maheshWebkul721, here is your Magento instance.
Admin access: http://34.228.235.121/i-19230-2-2-develop//admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@maheshWebkul721 Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-96384 were created

Hi there, I'm able to reproduce it, I'm facing the same issue on magento 2.2.6

Same for me

Reproducible on 2.2.7-dev

Hi @KravetsAndriy. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

Does anyone know if this is an issue in 2.2.3?

@SamB-GB Hello. It doesn't throw exception, however expected behaviour is not valid, because after making an account, it doesn't increase coupon usage for newly created customer.
So, I think, that make reverse bugs, however, if you you're interested only in canceling order, you won't have a bug, described here.

Hi @engcom-backlog-tomash. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@magento-engcom-team give me 2.3.0 instance

Hi @engcom-backlog-tomash. Thank you for your request. I'm working on Magento 2.3.0 instance for you

Hi @engcom-backlog-tomash, here is your Magento instance.
Admin access: https://i-19230-2-3-0.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@friendscottn, thank you for reporting this isuue. The latest released version of Magento (2.3.0) is not affected by this issue. After the order is invoiced you cannot cancel the order. By if the merchant ships the order without invoicing than order gets status processing and also he is able to cancel it until invoice is not created. In such conditions order has no problems with cancelation

@engcom-backlog-tomash I think, when user makes guest order with coupon code and then registers an account, coupon code usage should be increased and coupon usage per customer should be increased , the same way as customer made account BEFORE checkout with given coupon.
In fact, coupon has been used, but amount of usages will be the same as before. This behaviour exists in 2.3.
If its not relevant to current scope ( Canceling an order), I can make separated issue.

@Winfle, yes please create new one if it's not already created.

Hi @friendscottn. Thank you for your report.
The issue has been fixed in magento/magento2#19423 by @Winfle in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

@sidolov the same issue in Magento 2.2.9

Hi @friendscottn. Thank you for your report.
The issue has been fixed in magento/magento2#20577 by @p-bystritsky in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.4 release.

The issue still happens with Guest Users. The issue originates from \Magento\SalesRule\Model\Coupon\UpdateCouponUsages::updateCustomerRuleUsages and this line $ruleCustomer->save(); was causing the issue. I am on enterprise version.

@magento-engcom-team Can you please release a patch for this on 2.2.x for EE customers. Orders can't be cancelled have big effect on stock values within the system

i am still having this issue in magento 2.3.3 CE:

Was this page helpful?
0 / 5 - 0 ratings