magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

[SalesRule] Extend Applied SalesRule stored in Order with additional values

Open Hanmac opened this issue 9 months ago • 1 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description

Problem: sales/order->appliedRuleIds and sales/order_item->appliedRuleIds might store the rules ids, but not enough info for me to use. discount_description only has full names, but i need separate data.

I need for each applied rule:

  • Name (StoreLabel)
  • Amount
  • If percent based, I need the Percent and the BaseAmount
  • (Tax? If they are based on one Order Item? Should be the same?)
  • Possible Extra fields that can be extended later (I would like to add a DiscountReasonCode)

For this to work, i would need to rewrite some of Mage_SalesRule_Model_Validator, it is too deep in the process function, so i can't just extend it. salesrule_validator_process is too much before the correct values are calculated/rounded and the correct percent is used.

I need the same info for shipment too. (for shipment-tax, I will make an extra issue)

I think in a first attempt, I could try to add just a simple Event inside the each-rule-loop?

Expected Behavior

I would like to have on the OrderItem a serialized, or JSON data array And on the Order for Shipping too

I would need the Data to be persistent, even if the SalesRule gets deleted

Benefits

If the Code gets updated, more events could be added

Anything else?

I would like this Data for EN16931

Hanmac avatar Mar 10 '25 16:03 Hanmac

@Hanmac I do something similar, but did with only an observer. See this gist: https://gist.github.com/justinbeaty/7852c673be8ee87961085e5fb54e2d2d

It has been working well for my store, although I only use simple, virtual, and grouped products, so I haven't tested it under all scenarios. Of course, I'd be happy if this sort of change was integrated into the core.

justinbeaty avatar Mar 10 '25 20:03 justinbeaty