Question

I have a client that requires custom order, invoice and shipment number to be present in emails and while printing them out... The best possible modification would be to change the code that assigns those numbers.

How would I go about changing this so Magento generates these numbers the way i want them to?

Thank you!!!

Edit: I'm sory that I wasn't specific enough first time... i don't need a way to change the order increment or starting number but rather change the whole logic of assigning/generating those numbers.

Eg: I would like to have a order number that would be todays date (220114) with a postfix which would be something like the number of todays order (if its the third order today then that postfix wold be 3), invoice number would have additional postfix that would correspond to payment method used and shippment number would a postifx that would describe the shipping method used.

So what i really need is location of the magento code that is responsible for generating current/default numbers and switch that code with my own as needed.

Was it helpful?

Solution

It is possible to create a completely new EAV increment model. This is where the magic happens when getting the next ids :)

Firstly you can see what the current model is by looking at the table eav_entity_type under the column increment_model. For example to order has the following set.

eav/entity_increment_numeric

You can create your new model and set it for orders via an install script.

class My_CustomEav_Model_Entity_Increment_New extends Mage_Eav_Model_Entity_Increment_Abstract
{
    public function getNextId()
    {
        // Some magic here to get the unique  vaue you want and return it
    }
}

The table eav_entity_store holds a few more pieces of important information. Here you can store increment_prefix varchar(20) which is the prefix that is normally added to the increment, I think the default it 1, and increment_last_id varchar(50) this stores the last id used for the entity type on a given store, note that without changing the table definition you will be limited to varchar(50), though that should be enough....maybe.

NOTE I have not tested this myself as I have never needed to but it should all work nicely if the ids are unique.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top