2

I try to short order number from 11 to 6.

In database I select table eav_entity_type

SELECT * FROM `eav_entity_type`

go to table "order" and looking for increment_pad_length

enter image description here

I found that I have to change the record increment_pad_lenght

But here I have value 8 (in magento order ID have 11 digitals).

I change this value to 4 and update magento

php bin/magento setup:upgrade

unfortunately I did not receive any result. Any one know how to do?

EDIT: after database query

select * from sales_sequence_meta;

I see table sequence_order_1, sequence_order_2, sequence_order_3 etc. enter image description here

After edit for example sequence_order_1 I cannot see AUTO_INCREMENT record.

EDIT: After:

mysql: select * from sales_sequence_meta;


ALTER TABLE sequence_order_0 AUTO_INCREMENT=7895;
ALTER TABLE sequence_order_1 AUTO_INCREMENT=7895;
ALTER TABLE sequence_order_2 AUTO_INCREMENT=7895;
ALTER TABLE sequence_order_3 AUTO_INCREMENT=7895;
ALTER TABLE sequence_order_4 AUTO_INCREMENT=7895;
ALTER TABLE sequence_order_5 AUTO_INCREMENT=7895;
ALTER TABLE sequence_order_6 AUTO_INCREMENT=7895;

my order ID is still the same.

@Rakesh Varma, In file /vendor/magento/module-sales-sequence/Model/Sequence.php, on line 19 I have:

const DEFAULT_PATTERN  = "%s%'.09d%s";

When I edit file: app/etc/di.xml and adding below line:

<?xml version="1.0"?>
<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>

Get error:

Fatal error: Uncaught Magento\Framework\Exception\LocalizedException: Invalid XML in file /home/brandswearxv/ftp/app/etc/di.xml: XML declaration allowed only at the start of the document Line: 1233 Extra content at the end of the document Line: 1234 in /home/brandswearxv/ftp/vendor/magento/framework/Config/Reader/Filesystem.php:151 Stack trace: #0 /home/brandswearxv/ftp/vendor/magento/framework/Config/Reader/Filesystem.php(127): Magento\Framework\Config\Reader\Filesystem->_readFiles(Object(Magento\Framework\Config\FileIterator)) #1 /home/brandswearxv/ftp/vendor/magento/framework/App/ObjectManagerFactory.php(282): Magento\Framework\Config\Reader\Filesystem->read('primary') #2 /home/brandswearxv/ftp/vendor/magento/framework/App/ObjectManagerFactory.php(142): Magento\Framework\App\ObjectManagerFactory->_loadPrimaryConfig(Object(Magento\Framework\App\Filesystem\DirectoryList), Object(Magento\Framework\Filesystem\DriverPool), Object(Magento\Framework\ObjectManager\Config\Mapper\Dom), 'developer') #3 /home/brandswearxv/ftp/ve in /home/brandswearxv/ftp/vendor/magento/framework/App/ObjectManagerFactory.php on line 284
7
  • Do you want to change order increment_id length? for example 00000001 to 001?
    – Keyur Shah
    Commented Feb 4, 2018 at 11:13
  • Yes, I have to change the length of the order numbers because I have an integrated magento with the sales system and this system does not accept such a long order number. Do you know how to do ?
    – Sylvester
    Commented Feb 4, 2018 at 12:07
  • Check this magento.stackexchange.com/questions/101341/…
    – Keyur Shah
    Commented Feb 4, 2018 at 12:17
  • @KeyurShah Thanks, but I cannot see one thing (I have updated my post).
    – Sylvester
    Commented Feb 4, 2018 at 12:40
  • Did you place any new order? to see the effect you need to place a new order and one more thing don't set the same number(as I can see that you set the 7895 for all store ) for all store otherwise it will break
    – Keyur Shah
    Commented Feb 4, 2018 at 12:52

2 Answers 2

6

To change the padding for the order number you have to override default constant 

DEFAULT_PATTERN

 which is set in: /vendor/magento/module-sales-sequence/Model/Sequence.php, on line 19. We can change this in a custom module by creating 

etc/di.xml

 with the following content:

<type name="Magento\Framework\DB\Sequence\SequenceInterface">
    <arguments>
        <argument name="pattern" xsi:type="string">%s%'.06d%s</argument>
    </arguments>
</type>

You can read more details from here... https://www.classyllama.com/blog/m2-incrementid

5
  • Thanks Rakesh, I update my topic, can you check? Thanks.
    – Sylvester
    Commented Feb 4, 2018 at 15:53
  • You have to add di.xml file in under your module... Commented Feb 4, 2018 at 15:55
  • ahh and that would solve this problem! Only to which folder should I upload the new creating file di.xml ? What do you mean "under your module". Thanks
    – Sylvester
    Commented Feb 4, 2018 at 15:58
  • 1
    You have to create your own module and create di.xml file you can use this website to create module... mage2gen.com Commented Feb 4, 2018 at 16:01
  • You welcome.. let me know if you face other issue. Commented Feb 4, 2018 at 16:03
0

You can also try this in magento 2.3+ this will work.

Create di.xml in your module

[namespace] / [modulename] /etc/di.xml

And paste This code

<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\SalesSequence\Model\Sequence">
    <arguments>
        <argument name="pattern" xsi:type="string"><![CDATA[%s%'.06d%s]]></argument>
    </arguments>
</type></config>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.