Some merchants want to customize order’s Increment id PAD-LENGTH numbers to be different than what Magento 2 produces by default.
PAD-LENGTH is the number of zeros in increment id of an order
Increment id is the ID through which a store owner communicate with the customer.
An order increment id is consist of following parts:
- Prefix
- Suffix
- Start-value
- Pad-length
The Prefix, Suffix, Start-value, and Step are stored in the database, while the Pad-length is set in the code.
Here we only talk about PAD-LENGTH. The PAD-LENGTH of the increment-ID is determined in the code base, and it’s not affected by any database properties.
In \Magento\SalesSequence\Model\Secequence, the getCurrentValue() method used for to set the pattern of the increment id number:
the “$this->pattern” got value from the constant DEFAULT_PATTERN
which is initially %s%’.09d%s.
%’.09d. The ‘.0 sets “0” as the padding character and sets the number of digits to display as the value that follows, which in this case is 9. The d presents the number as a [signed] decimal. This means that by default, the increment-ID number will be a signed decimal with 9 digits, padded with 0s.
How to change PAD-LENGTH
We can change this in a custom module by creating etc/di.xml
<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%'.06d%s</argument> </arguments> </type> </config>
Here I have set the padding 6 from default padding 9 zero.
2 comments
yes, if you set ‘0’ as following then no padding will add to new orders.
Thanks