I have been using below code to get the next order id in Magento
$getNewOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
This works fine but the problem for this code is it changes the increment_last_id field in table eav_entity_store to this new order id.
So, if your order was not processed, the order id has already incremented and hence the order id would get lost, as next time before creating orders Magento will increment this value in the table and process the order.
How can we get the next order id without incrementing the value in the table, it obviously will change the value in this table when the order is created in the latter part of the code.
I am using this piece of code to create orders programmatically
Try this:
$entityStoreConfig = Mage::getModel('eav/entity_store')->loadByEntityStore($this->getId(), $storeId);
$incrementInstance = Mage::getModel($this->getIncrementModel())
->setPrefix($entityStoreConfig->getIncrementPrefix())
->setPadLength($this->getIncrementPadLength())
->setPadChar($this->getIncrementPadChar())
->setLastId($entityStoreConfig->getIncrementLastId())
->setEntityTypeId($entityStoreConfig->getEntityTypeId())
->setStoreId($entityStoreConfig->getStoreId());
$nextId = $incrementInstance->getNextId();
The code is taken from the fetchNewIncrementId
method. I just omitted the save part.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments