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="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\DB\Sequence\SequenceInterface"> <arguments> <argument name="pattern" xsi:type="string">%s%'.05d%s</argument> </arguments> </type> </config>
After that perform the following command if your caches are enabledphp bin/magento cache:clean
From now every new order has 5 digit number with prefix and postfix if you have added that.