0

Magento 2 uses table sales_sequence_meta and sales_sequence_profile for defining the entity prefix for stores.

If 2 and 3 are the store_id of two store views of the same website, the table data may look like this

mysql> SELECT * FROM sales_sequence_meta WHERE entity_type='order' AND store_id IN (2, 3);
+---------+-------------+----------+-------------------+
| meta_id | entity_type | store_id | sequence_table    |
+---------+-------------+----------+-------------------+
|      11 | order       |       2  | sequence_order_2  |
|      12 | order       |       3  | sequence_order_3  |
+---------+-------------+----------+-------------------+

And sales_sequence_profile table looks like

mysql> SELECT * FROM sales_sequence_profile WHERE meta_id IN (11, 12);
+------------+---------+--------+--------+-------------+------+------------+---------------+-----------+
| profile_id | meta_id | prefix | suffix | start_value | step | max_value  | warning_value | is_active |
+------------+---------+--------+--------+-------------+------+------------+---------------+-----------+
|         11 |      11 | 2      |        |           1 |    1 | 4294967295 |    4294966295 |         1 |
|         12 |      12 | 3      |        |           1 |    1 | 4294967295 |    4294966295 |         1 |
+------------+---------+--------+--------+-------------+------+------------+---------------+-----------+

With these, the generated order numbers may look like 2000000001 ... and 3000000001... for stores with id 2 and 3 respectively.

But I want the same sequence 200000000x (2 as the prefix) for orders from store_id = 3 as well.

From looking at table, I guess I can easily update as:

UPDATE sales_sequence_meta SET sequence_table = 'sequence_order_2' WHERE entity_type='order' AND store_id = 3;
UPDATE sales_sequence_profile SET prefix = '2' WHERE profile_id = 12;

But not sure if it's the correct way to do it.
Please share your views on this if you have any hands-on experience.

4
  • What is your end goal in making these orders sequential? That might affect the recommended solution. What problem are you trying to solve?
    – dotancohen
    Sep 6, 2022 at 7:10
  • I want English & French language stores to have a common prefix i.e. both starting from 2xxxxxxxxx (as shown above)
    – MagePsycho
    Sep 6, 2022 at 8:53
  • Let me rephrase the question. Why do you want English & French language stores to have a common prefix? What problem are you trying to solve?
    – dotancohen
    Sep 6, 2022 at 9:57
  • That's the client who wants that :) so that they know that this order belongs to XYZ stores(feel unified).
    – MagePsycho
    Sep 6, 2022 at 10:01

1 Answer 1

2

I think it is not meant to happen. If you take a look at the sales order module and particularly the db_schema.xml file, there is a constraint on the field increment_id

<constraint xsi:type="unique" referenceId="SALES_ORDER_INCREMENT_ID_STORE_ID">
            <column name="increment_id"/>
            <column name="store_id"/>
        </constraint>

Your change would imply this constraint has to be removed. Now, rest assured this might be technically doable. However, it is not advisable to break Magento database integrity as you may know.

The way round may be to add a new column that duplicates the field increment_id and add a business logic that shows the additional field.

The problem with this method is that you will need a lot of changes in various documents like invoice, order email and so on..

EDIT: Now that I understand your target better, I'd say, just change the prefix as per your query and then ensure the start_value is set so that both your store order id do not overlap.

The outcome will be what you are after and will likely work (I have not tested). The issues to watch out for are that your payment gateway will not let 2 increment_id with the same value to be created. Although in theory, it should not happen, here on this occasion you are making this scenario more likely.

2
  • I don't want the same order number but the same prefix, for example, 2 for both the stores.
    – MagePsycho
    Sep 6, 2022 at 8:54
  • 1
    np, I updated my answer. I'd say the requirement you're having is not conventional but I take you know this, good luck Sep 6, 2022 at 9:07

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.