How do I change how order references are generated?

You can set an order reference generator to define how order references are generated. To do this you need to use the static setReferenceGenerator method on the Aero\Cart\Models\Order model.

The method accepts a closure that accepts the order as a parameter and expects you to return a string (the reference for the order passed into the closure).

If you do not set an order reference generator the default generator will be used that does the following:

<?php

namespace Acme\MyModule;

use Aero\Cart\Models\Order;
use Aero\Common\Providers\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
{
   public function setup()
   {
       Order::setReferenceGenerator(function (Order $order) {
           $prefix = setting('order_reference_prefix');
           $random = substr(str_shuffle(str_repeat('0123456789', 10)), 1, 3);

           return "{$prefix}{$order->getKey()}-{$random}";
       });
   }
}

Articles in this section

Was this article helpful?
0 out of 0 found this helpful