Is there possible for magento 1 to increase order id each time plus 4.

Ex.

My current order is 10001 and when we placed next time order from store next id would be 10005, after another next time it would be 10009.

Each time order increment id will be +4 from current order id.

有帮助吗?

解决方案

Yes, if you implement your own increment model

From my blog post on increment models:

Writing Custom Increment Models

You can specify any class as increment model that implements Mage_Eav_Model_Entity_Increment_Interface. Be aware: This interface pretents to only need one method, getNextId(), but at least the following setters will be called as well:

  • setPrefix
  • setPadLength
  • setPadChar
  • setLastId
  • setEntityTypeId
  • setStoreId

Yeah, Magento doesn’t give much love to interfaces. So if you want to implement your own increment model, you should at least inherit from Varien_Object, better from Mage_Eav_Model_Entity_Increment_Abstract which already provides you with the prefix and padding logic.

In the method getNextId() you will then generate the next increment id based on the last one, that is accessible with $this->getLastId()

So in your case this would be:

class Stack_Model_Entity_IncrementStep extends Mage_Eav_Model_Entity_Increment_Abstract
{
    const STEP = 4;
    public function getNextId()
    {
        $last = $this->getLastId();
        if (strpos($last, $this->getPrefix()) === 0) {
            $last = (int)substr($last, strlen($this->getPrefix()));
        } else {
            $last = (int)$last;
        }
        $next = $last + self::STEP;
        return $this->format($next);
    }
}

This is mostly copied from Mage_Eav_Model_Entity_Increment_Numeric where it is +1 instead of + self::STEP. You probably want to replace the constant in this minimum example with a configuration value.

Then update increment_model for orders in the eav_entity_type table and change it from eav/entity_increment_numeric to your model (e.g. stack/entity_incrementStep)

其他提示

The problem here is that Magento does not use the MySQL autoincrement for the increment id.

The increment ids are stored in the eav_entity_store and incremented by a class.

For numeric increment, the class is Mage_Eav_Model_Entity_Increment_Numeric and the method that takes care of the increment is getNextId :

public function getNextId()
{
    $last = $this->getLastId();

    if (strpos($last, $this->getPrefix()) === 0) {
        $last = (int)substr($last, strlen($this->getPrefix()));
    } else {
        $last = (int)$last;
    }

    $next = $last+1;

    return $this->format($next);
}

I could suggest that you rewrite that class to replace this line:

$next = $last+1;

With:

$next = $last+4;

However, that will also affect the invoices, shipments and credit memos increment ids.

Magento set a order increment id from Mage_Sales_Model_Order at function _beforeSave().

If you would chnage at here then your problem will resolved

许可以下: CC-BY-SA归因
scroll top