Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Sharing Invoice Numbers Between Stores.(Consecutives)
 
Ignacio Bona
Jr. Member
 
Total Posts:  10
Joined:  2008-11-07
Spain
 

Hi, if anybody is interested in sharing the invoice numbers between stores you have to override Mage_Eav_Model_Entity_Store Class.

1- In the /Company/Module/etc/config.xml you have to write the following thing:

<config>
    <
modules>
        <
Company_Module>
            <
version>0.1.0</version>
        </
Company_Module>
    </
modules>
    <global>
        <
models>
            <
eav>
                <
rewrite>
                    <
entity_store>Company_Module_Model_Entity_Store</entity_store>
                </
rewrite>
            </
eav>
        </
models>
    </global>
</
config>

2- You have to copy /Mage/Eav/Model/Entity/Store.php into your folder /Company/Module/Model/Entity/Store.php.
3- Edit your Store.php file:

from this:

class Mage_Eav_Model_Entity_Store extends Mage_Core_Model_Abstract 
{
    
protected function _construct()
    
{
        $this
->_init('eav/entity_store');
    
}
    
    
public function loadByEntityStore($entityTypeId$storeId)
    
{
        $this
->_getResource()->loadByEntityStore($this$entityTypeId$storeId);
        return 
$this;
    
}
}

to this:

class Company_Module_Model_Entity_Store extends Mage_Eav_Model_Entity_Store
{
    
protected function _construct()
    
{
        $this
->_init('eav/entity_store');
    
}
    
    
public function loadByEntityStore($entityTypeId$storeId)
    
{
        $this
->_getResource()->loadByEntityStore($this$entityTypeId1);//1 is your default store_id
        
return $this;
    
}
    
protected function _beforeSave()
    
{
        $this
->setStoreId(1);//I had some issues, My credit memos were not saved properly(save store id was 0 but when reading store id was 1) . So I force store id to be 1.(same as load)
    
}
}

Don’t forget to chage the etc/modules/Company_All.xml file.

BE CAREFUL!! You will share all your increments_ids!(orders,invoices,etc..) maybe you can add this to apply only to invoices:

if($entityTypeId==16){//16==invoices
 
$this->_getResource()->loadByEntityStore($this$entityTypeId1);//1 is your default store_id
}else{
 $this
->_getResource()->loadByEntityStore($this$entityTypeId$storeId);
}

Good Luck!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Elektronicanet
Jr. Member
 
Total Posts:  10
Joined:  2009-01-02
 

This can also be done in a better way (I think).

Find in app/code/mage/sales/model/entity/setup.php the following piece of code:

'invoice' => array(
                
'entity_model'      => 'sales/order_invoice',
                
'table'             =>'sales/order_entity',
                
'increment_model'   =>'eav/entity_increment_numeric',
                
'increment_per_store'=>false,
and chance
'increment_per_store'=>false

to
'increment_per_store'=>true

After creating a new invoice, table imch_eav_entity_store (MySQL, accessable via PhpMyAdmin) should show a new entry with store_id=0. You may delete the previous entry, with entity=16 (at least in version 1.3.2.2 this is the invoice entry).

Also, I changed in table imch_eav_entity_type the increment_per_store from the invoice entity to 0. This is the most important step actually!

 
Magento Community Magento Community
Magento Community
Magento Community
 
nigital
Jr. Member
 
Total Posts:  26
Joined:  2009-11-13
Germany
 

Dear Elektronicanet,
thanks for your solution - it works great!!!!
nils

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidgrun
Sr. Member
 
Total Posts:  245
Joined:  2008-07-10
 

@Elektronicanet

Why didn’t I find you 10 hours ago?!?!?!
Your solution worked like a charm on version 1.6.2.0!!
Btw, this method is not at all popular on the internet, but its the easiest one!

I also implemented it for orders, invoices, credit memos, and shipments in lines 260, 554, 652, 731.

THANK YOU!!!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top