Custom Order IDs

Order IDs often have very specific constraints in different customer setups – while most backend system can generate these order IDs, these configurations might not be enough. This is why we allow you to customize the Order ID generation and even retrieve them from backend systems.

Register and Write Service

To overwrite the default behavior you can use the default Symfony mechanism in the Dependency Injection Container. To do this, just add the below lines to a service.xml in one of your Project bundles (if there isn't a bundle yet, you can create one using bin/console frontastic:create:bundle MyDecorators, for example):

<service
    id="frontastic.order-id-generator"
    class="Acme\MyDecoratorsBundle\Domain\OrderNumberGenerator">
    <!-- argument type="service" id="&hellip;" / -->
</service>

Your custom order generator must implement the interface Frontastic\\Common\\CartApiBundle\\Domain\\OrderIdGenerator which defines one single method for you to implement:

<?php

namespace Acme\MyDecoratorsBundle\Domain;

use Frontastic\Common\CartApiBundle\Domain\OrderIdGenerator;
use Frontastic\Common\CartApiBundle\Domain\Cart;

class OrderNumberGenerator implements OrderIdGenerator
{
    public function getOrderId(Cart $cart): string
    {
        return 'some-radom-order-id';
    }
}

The method retrieves the cart to generate the order for. You can now generate a random order or talk with another backend system, even your ERP, to retrieve something (like the next sensible order ID). The returned order ID must always be a string, but could be a numeric string.


‹ Back to Article List

Next Article ›

Context Decorators and Locale Resolvers

Still need help? Contact Us Contact Us