While digging deeper, I realized that eav_entity_type.increment_per_store
may be helpful.
It is. But only for the case, when you want all store views (globally, no matter which website they're defined in) of your Magento installation to share the same order increment_id
number range.
This doesn't solve my specific issue, but maybe it's helpful to some others, so here we go:
To activate global sharing of your order numbers, set eav_entity_type.increment_per_store
of the order entity to 0
,
This leads to Mage_Eav_Model_Entity_Type::fetchNewIncrementId()
using store_id = 0
when loading the eav_entity_store
record of the order entity, no matter which store view it really belongs to.
If no such record exists, Magento creates one, using store_id
and increment_prefix
of 0
.
public function fetchNewIncrementId($storeId = null)
{
if (!$this->getIncrementModel()) {
return false;
}
if (!$this->getIncrementPerStore() || ($storeId === null)) {
/**
* store_id null we can have for entity from removed store
*/
$storeId = 0;
}
// Start transaction to run SELECT ... FOR UPDATE
$this->_getResource()->beginTransaction();
$entityStoreConfig = Mage::getModel('eav/entity_store')
->loadByEntityStore($this->getId(), $storeId);
if (!$entityStoreConfig->getId()) {
$entityStoreConfig
->setEntityTypeId($this->getId())
->setStoreId($storeId)
->setIncrementPrefix($storeId)
->save();
}
$incrementInstance = Mage::getModel($this->getIncrementModel())
->setPrefix($entityStoreConfig->getIncrementPrefix())
->setPadLength($this->getIncrementPadLength())
->setPadChar($this->getIncrementPadChar())
->setLastId($entityStoreConfig->getIncrementLastId())
->setEntityTypeId($entityStoreConfig->getEntityTypeId())
->setStoreId($entityStoreConfig->getStoreId());
/**
* do read lock on eav/entity_store to solve potential timing issues
* (most probably already done by beginTransaction of entity save)
*/
$incrementId = $incrementInstance->getNextId();
$entityStoreConfig->setIncrementLastId($incrementId);
$entityStoreConfig->save();
// Commit increment_last_id changes
$this->_getResource()->commit();
return $incrementId;
}
This should work for any entity type using the eav/entity_increment_numeric
model, like order
, invoice
, shipment
and creditmemo
.
Be aware though, that I couldn't find any official documentation of increment_per_store
yet. And that there's no option in the Magento backend letting you configure this.
This may or may not mean, that it's not thought to be used officially.
Use at your own risk. If your changes wreak havoc, don't blame me. You've been warned^^