magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Apply Sales Rule with an old order

Open IClongI opened this issue 1 month ago • 2 comments

Preconditions and environment

  • Magento version : 2.4.7 (but probably valid for all versions)
  • Get a recent order
  • Get an old order still processing status
  • Get a Sales Rules saying you will earn some fidelity points when the order is shipped (We setup that using Amasty Promo but the core issue is also in Magento).

Steps to reproduce

1 - Make an order today 2 - Ship it from back office 3 - You can see the sales rule is properly applied

4 - To to an older order, like a few week or monrth 5 - Ship it 6 - You can see the sales rule is not properly applied

Expected result

We expect the sales rule to be properly applied if the condition is met by the product from the order. But it's not

Actual result

The reason behind all that lies on the core file

vendor/magento/module-sales-rule/Model/Rule/Condition/Product/Subselect.php

And more specifically in the validate method

    /**
     * Validate
     *
     * @param \Magento\Framework\Model\AbstractModel $model
     * @return bool
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    public function validate(\Magento\Framework\Model\AbstractModel $model)
    {
        if (!$this->getConditions()) {
            return false;
        }
        $attr = $this->getAttribute();
        $total = 0;
        foreach ($model->getQuote()->getAllVisibleItems() as $item) {

The validate method check condition by iterating the Quote. But the issue doing that is that the Quote is not a consistent object to rely on as she can be deleted after X days depending on your configuration.

Si if you ship your order after the Quote suppression, your shipping rule is not applied anymore !

Magento should inclure a fall back to that method to work from the Order object instead of the Quote.

I agree that is most cases, Quote validity stand for a month and the shipping will probably be below that period. But considering the quote validity is dynamic due to configuration and can be modified (in my specific scenario we have Quote validity for 7 days only). So this use case where the sales rules need to be checked after a full week is not that rare.

Additional information

No response

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [x] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

IClongI avatar Dec 05 '25 10:12 IClongI

Hi @IClongI. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

m2-assistant[bot] avatar Dec 05 '25 10:12 m2-assistant[bot]

Hi @engcom-Bravo. 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).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.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. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Dec 05 '25 10:12 m2-assistant[bot]