SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • 📖Sylius 2.0 Documentation
    • Organization
      • Release Cycle
      • Backwards Compatibility Promise
      • Sylius Team
      • Sylius Roadmap
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Contributing Translations
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
      • How to add a custom translatable model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Styles
    • Customizing Validation
    • Customizing Menus
    • Customizing Templates
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing Fixtures
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • 🧑‍🍳The Cookbook
  • How to resize images?
  • How to add one image to an entity?
  • How to add multiple images to an entity?
  • Sylius 1.X Documentation
    • 📓Sylius 1.x Documentation
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • Types of Adjustments
  • Creating an Adjustment Programmatically

Was this helpful?

Edit on GitHub
  1. The Book
  2. Carts & Orders

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:

  1. Get the Adjustment Factory

    First, you’ll need to get the adjustment factory and create a new adjustment instance.

    /** @var AdjustmentInterface $adjustment */
    $adjustment = $this->container->get('sylius.factory.adjustment')->createNew();
  2. 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).

    $adjustment->setType(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT);
    $adjustment->setAmount(200); // Amount in base currency
    $adjustment->setNeutral(false); // Affects the total
    $adjustment->setLabel('Test Promotion Adjustment');
  3. Add the Adjustment to an Order

    After setting up the adjustment, add it to the relevant order:

    $order->addAdjustment($adjustment);
  4. Save the Changes

    To apply the changes, update the order in the database:

    $this->container->get('sylius.manager.order')->flush();

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.

$adjustment->lock();

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.

PreviousTaxationNextCart Promotions

Last updated 7 months ago

Was this helpful?