Score:0

How to create an Order fee which only applies to certain line items (like an OrderItem fee)?

us flag

I need to create a fee which is only applied to certain items (OrderItem fee) but also has a minimum and maximum that must/can be applied of this fee type to each order (Order fee).

Commerce has base classes for both of these fee types. The benefit of the OrderItemFeeBase is that it provides UI to select which product types this fee is applied to. But using this, I am not able to control min/max fee amount added for entire order.

For maximum amount, it would be possible to carry a static running order total to evaluate on each order item and then asses or not based on if total has been exceeded. But for minimum, this is not possible without knowing which item is last (hmm, do I know this?).

I can use an Order fee and analyze each item to see if it is the type the fee should be applied to; but then I lose the nice UI to select types.

Possibly there is an event or alter that can post-process the fee amount after the fees have been totaled? This would allow me to use the OrderItem type but then post-process the total fee for min/max.

Update:

Not sure how to add the OrderItemFee UI into the OrderFee UI but OrderFee seems to be the best approach as It can see all line items at once to be able to handle min/max.

The approach at the moment is to hard code the list of product types i don't want included in the fee and (with a cloned version of the Order) remove the order items which aren't of the allowed types.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.