Short Increment Number

Short Increment number

Sometimes there is a requirement to short increment number for the order,invoice,creditmemo and shipment. For that there is no any default setting or database field to set the default length of the increment number. This lenght is define in  /vendor/magento/module-sales-sequence/Model/Sequence.php file. But chaning in core file is not good Idea.

So, In today’s Blog I will show you how you can shorten this number using your module so your changes will not remove when you upgrade your Magento version.

For that you have to create di.xml file in your module under etc folder and write below code.

File Path:Vendor/Module/etc/di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <type name="Magento\Framework\DB\Sequence\SequenceInterface">
         <argument name="pattern" xsi:type="string">%s%'.05d%s</argument>

After that perform the following command if your caches are enabled
php bin/magento cache:clean

From now every new order has 5 digit number with prefix and postfix if you have added that.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top