Custom order IDs
This is an article for advanced users of Frontastic.
Order IDs often have very specific constraints in different customer setups — while most backend systems 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, add the below lines to a services.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="…" / -->
</service>
Your custom order generator must implement the interface Frontastic\\Common\\CartApiBundle\\Domain\\OrderIdGeneratorV2
which defines one single method for you to implement:
namespace Acme\MyDecoratorsBundle\Domain;
use Frontastic\Common\CartApiBundle\Domain\OrderIdGeneratorV2;
use Frontastic\Common\CartApiBundle\Domain\Cart;
class OrderNumberGenerator implements OrderIdGenerator
{
public function getOrderId(CartApi $cartApi, Cart $cart): string
{
return 'some-radom-order-id';
}
}
The method retrieves the cart to generate the order. 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.
If you previously used OrderIdGenerator
, you can use the OrderIdGeneratorV2Adapter
.
Updated almost 2 years ago