You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are currently building a Commerce site with some complex pricing rules. One thing we have to account for is adding additional flat charges based on a specific product option.
For example:
If a user selects Gold Irridite as an optional finish, we want to add a flat $150 charge to the line item, regardless of quantity:
The way I was doing this was by hooking onto the LineItems::EVENT_POPULATE_LINE_ITEM event, checking the option and then adding the additional amount to the line item price. Since this is the value of a single line item, I need to take the $150 and divide it by the quantity so it calculates correctly per item. This is working great when 150 / {qty} gives a round number. But if I submit a quantity like 499, then the additional amount that I'm adding per line item is 0.3006012, there's a rounding issue, and the price is incorrectly calculated
That should be $184.93.
This seems like the perfect use case for an adjuster, but what I need to add the additional charge for doesn't fall under an adjuster category
An adjustment model should have a type of shipping, discount, or tax.
Is there another way to add a flat rate charge that I'm missing?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We are currently building a Commerce site with some complex pricing rules. One thing we have to account for is adding additional flat charges based on a specific product option.
For example:
If a user selects Gold Irridite as an optional finish, we want to add a flat $150 charge to the line item, regardless of quantity:
The way I was doing this was by hooking onto the
LineItems::EVENT_POPULATE_LINE_ITEM
event, checking the option and then adding the additional amount to the line item price. Since this is the value of a single line item, I need to take the $150 and divide it by the quantity so it calculates correctly per item. This is working great when150 / {qty}
gives a round number. But if I submit a quantity like 499, then the additional amount that I'm adding per line item is0.3006012
, there's a rounding issue, and the price is incorrectly calculatedThat should be
$184.93
.This seems like the perfect use case for an adjuster, but what I need to add the additional charge for doesn't fall under an adjuster category
Is there another way to add a flat rate charge that I'm missing?
Beta Was this translation helpful? Give feedback.
All reactions