Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

Not sure about the safety lever but I'm doing it by modifying values in DB directly:

    UPDATE `eav_entity_store` s
INNER JOIN `eav_entity_type` t ON t.`entity_type_id` = s.`entity_type_id`
       SET s.`increment_last_id` = 'your_increment_here'
     WHERE t.entity_type_code = "order";

Replace entity type code with "invoice" or "shipping" to do the same for the rest.

share|improve this answer

If you want to use custom number ranges or formats for increment IDs instead of the default Magento increments, you can also assign a custom increment model.

For example:

class My_Shop_Model_Entity_Increment_Erp
    extends Mage_Eav_Model_Entity_Increment_Abstract
{
    public function getNextId()
    {
        $last = $this->getLastId();
        $entity = $this->getEntityTypeId();
        $store = $this->getStoreId()
        $next = Mage::helper('my_shop/api')->getNextIncrementFromErp($last, $entity, $store);

        // If you want to apply pad char and length, otherwise simply return $next
        return $this->format($next);
    }
}

Then, update the increment model for the entities in a setup script:

$installer = Mage::getModel('eav/entity_setup',   'core_setup');
$installer->startSetup();
$installer->updateEntityType('order',    'increment_model', 'my_shop/entity_increment_erp');
$installer->updateEntityType('invoice',  'increment_model', 'my_shop/entity_increment_erp');
$installer->updateEntityType('shipment', 'increment_model', 'my_shop/entity_increment_erp');
$installer->endSetup();

Be sure not to return increment IDs that already where used previously!

share|improve this 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.

share|improve this answer

The best [safest for magento] way to change the order number is to change the next order numbers and not the previous ones. This can be done with a simple database query. These are the ones I used in my site and it is working without any problem for almost a year now.

Order:

    UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_last_id='XXXXXXXXXX'
WHERE eav_entity_type.entity_type_code='order';

Invoice:

UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_last_id='XXXXXXXXXX'
WHERE eav_entity_type.entity_type_code='invoice';

Shipment:

UPDATE eav_entity_store
INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET eav_entity_store.increment_last_id='XXXXXXXXXX'
WHERE eav_entity_type.entity_type_code='shipment';

These queries will change the next increment ids for your magento store. NOTE: Replace X with the next id that you want.

Accept a answer if it works.

share|improve this answer
    
Copied from here I guess warpconduit.net/2012/04/18/… –  Tim Bezhashvyly Jul 2 at 20:16
    
yes and the solution works. –  Tarun Jul 3 at 10:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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