# Order Modifiers

# Overview

If you want to add additional functionality to the Order creation process, you can do so using Order Modifiers.

# Registering an Order modifier

Much like Carts, we just need to register these in our service provider.

public function boot(OrderModifiers $orderModifiers)
{
    $orderModifiers->add(
        \App\Modifiers\CustomOrderModifier::class
    )
}
namespace App\Modifiers;

use GetCandy\Base\OrderModifier;
use GetCandy\Models\Cart;
use GetCandy\Models\Order;

class CustomOrderModifier extends OrderModifier
{
    public function creating(Cart $cart)
    {
        //
    }

    public function created(Order $order)
    {
        //
    }
}

When using your own OrderModifier things can go wrong or for whatever reason you may need to abort the process and take the customer back to the checkout. For this you can throw a CartException (or your own exception that extends this) at any point in the flow and it'll stop.

The process is wrapped in a transaction so no need to worry about incomplete data making it's way in to the database.

namespace App\Exceptions;

class MyCustomException extends \GetCandy\Exceptions\CartException
{

}
public function creating(Cart $cart)
{
    if ($somethingWentTerriblyWrong) {
        throw new MyCustomException;
    }
}