--- layout: title: visible: true description: visible: false tableOfContents: visible: true outline: visible: true pagination: visible: true --- # Customizing Business Logic Sylius offers extensive customization options, allowing you to tailor your eCommerce store to your specific needs. Let’s walk through an example of how you can customize Sylius by implementing a **custom shipping calculator**. ## Custom Shipping Calculator A **shipping calculator** in Sylius calculates the shipping cost for an order. This calculation is usually based on the products and some configuration defined by the admin. Sylius provides two default calculators: * **FlatRateCalculator**: Charges a fixed rate per order. * **PerUnitRateCalculator**: Charges a rate based on the number of items in the order. Let’s say you need to charge based on the number of parcels used to pack the order. You can create a custom calculator to achieve this. ### Step 1: Create the Custom Shipping Calculator Your custom calculator must implement the `CalculatorInterface`. Below is an example of a **ParcelCalculator**, which charges based on the number of parcels. ```php getUnits()->count() / $parcelSize); return (int) ($numberOfPackages * $parcelPrice); } public function getType(): string { return 'parcel'; } } ``` In this code, we calculate the number of parcels needed by dividing the total product units by the parcel size. The total shipping cost is then the number of parcels multiplied by the price per parcel. ### Step 2: Register the Custom Calculator To make this calculator available in the admin panel, register it as a service in your `services.yaml`: ```yaml # config/services.yaml services: app.shipping_calculator.parcel: class: App\ShippingCalculator\ParcelCalculator tags: - { name: sylius.shipping_calculator } ``` This will allow your custom shipping calculator to be selected when configuring shipping methods in the admin panel. ### Step 3: Configure the Shipping Method in the Admin Panel Now that your calculator is registered, you can create a new **Shipping Method** in the admin panel using your **ParcelCalculator**. When setting up the shipping method, you will need to provide two configuration options: * **Size**: How many units fit into one parcel. * **Price**: The cost per parcel.

Configuration in the Admin Panel

Shipping cost for 1 pacel

Shipping cost for 4 parcels