Adjustments
Adjustments are closely tied to orders in Sylius. They influence the total amount of an order and can be applied at different levels:
Order Level
OrderItem Level
OrderItemUnit Level
Types of Adjustments
Adjustments can be divided into three main groups:
Promotion Adjustments
Applied when promotions or discounts are used
Example:
Order Promotion Adjustments
,OrderItem Promotion Adjustments
Shipping Adjustments
Applied to the cost of shipping
Example:
Shipping Adjustments
,Shipping Promotion Adjustments
Tax Adjustments
Applied to calculate taxes on orders
Example:
Tax Adjustments
Positive vs Negative Adjustments
Positive Adjustments | Negative Adjustments |
---|---|
These are charges that increase the total amount (e.g., shipping fees, taxes) | These are discounts that reduce the total amount (e.g., promotional discounts) |
Creating an Adjustment Programmatically
Adjustments need to be linked to an order to make sense. Here’s how you can create one:
Get the Adjustment Factory
First, you’ll need to get the adjustment factory and create a new adjustment instance.
Set the Adjustment Type and Amount
Set the type of the adjustment (available types are found in
AdjustmentInterface
).Provide the amount (in the base currency).
Optionally, set whether the adjustment is neutral (neutral adjustments don’t affect the total like taxes already included in the price).
Add the Adjustment to an Order
After setting up the adjustment, add it to the relevant order:
Save the Changes
To apply the changes, update the order in the database:
Adding Adjustments to Order Items or Item Units
If you want to add adjustments at the OrderItem level, make sure the adjustment is attached to the OrderItem. If it’s for an OrderItemUnit, apply it at the OrderItemUnit level.
Adjustments on different levels affect only that specific part of the order.
Locking an Adjustment
You can lock an adjustment to prevent it from being removed during recalculations. This is useful for scenarios like expired promotions that still need to be applied to the order.
For example, if a promotion is no longer applicable but you still want it to be applied (e.g., an expired coupon), locking the adjustment ensures it remains active.
Last updated