Magento – Custom Order, Invoice, and Shipping Starting Numbers

custominvoiceordersshipping

What's the safest approach to change the next starting numbers for order, invoice, and shipment on a live site?

Best Answer

If I want to continue using Magento's default increment type and just want to change the next increment number, this is what I use.

Be sure to only use increment numbers that are larger then ones already used!

SET @next_increment='310000000';

SELECT @entity_types:=GROUP_CONCAT(`entity_type_id`) FROM `eav_entity_type`
    WHERE `entity_type_code` IN ('order', 'invoice', 'shipment');

SELECT @new_last_increment:=GREATEST((@next_increment -1), 
    (SELECT MAX(`increment_last_id`) FROM `eav_entity_store`
     WHERE FIND_IN_SET(`entity_type_id`, @entity_types)));

UPDATE `eav_entity_store` SET `increment_last_id`=@new_last_increment
    WHERE FIND_IN_SET(`entity_type_id`, @entity_types);

This SQL should take care of not accidentially setting an increment ID that was used already.
If a larger increment then next_increment already was used, it simply sets the last increment number for all three entity types to be the same.

Related Topic