Magento更改发票编号格式

时间:2014-11-28 10:51:24

标签: magento

目前,发票没有。是XXXXXXX。我需要改变格式YYYY-MM-XXXX

YYYY - 当年 MM - 当月 XXXX - 自动生成没有。从每个月初的1900开始。

我看到很多帖子谈到改变增量值或在发票号码中加入INV等字符。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

注意:在继续之前备份数据库。

这是基本的理解: eav_entity_store 表有两个感兴趣的选项: 1)increment_prefix 2)increment_last_id increment_prefix 指定将哪个前缀添加到数字,默认情况下等于«1»。 increment_last_id 定义最后一个实体编号。

在这里,我们可以更改订单,发票和货件的起始编号。 eav_entity_type 表具有允许我们更改数字格式的设置。这些是 increment_pad_length ,用于设置不包括其前缀的数字的长度, increment_pad_char 用于指定用于将数字填充到所需长度的字符。默认情况下为零。另一个重要字段是 increment_model ,它指定用于生成数字的类。

使用以下内容覆盖文件夹 app / code / local / Mage / Eav / Model / Entity / Increment 中的 Mage_Eav_Model_Entity_Increment_Order

class Mage_Eav_Model_Entity_Increment_Order extends Mage_Eav_Model_Entity_Increment_Abstract
{
    public function getNextId()
    {
        $last = $this->getLastId();

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

        $next = $last+1;

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

    public function format($id)
    {
        $result  = $this->getPrefix() . date('y'); //year is appended to the increment id
        $result .= str_pad((string)$id, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT);
        return $result;
    }

}

根据您的需要修改代码。

来源:atwix

相关问题