Magento 事件的使用

在magento后端生成订单,将生成的订单id存放到creditmemo

使用事件下面是具体的方法

1.创建modules D:\www\lollicupStore2\app\etc\modules\Lollicupstore_Createorder.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <Lollicupstore_Createorder>
            <active>true</active>
            <codePool>local</codePool>
        </Lollicupstore_Createorder>
    </modules>
</config>

2. 创建 config.xml D:\www\lollicupStore2\app\code\local\Lollicupstore\Createorder\etc\config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <Lollicupstore_Createorder>
            <version>0.1.0</version>
        </Lollicupstore_Createorder>
    </modules>
    <models>
        <Lollicupstore_Createorder>Lollicupstore_Createorder_Model_Observer</Lollicupstore_Createorder>
    </models>
    <adminhtml>
        <events>
            <checkout_submit_all_after>
                <observers>
                    <Lollicupstore_Createorder>
                        <type>singleton</type>
                        <class>Lollicupstore_Createorder_Model_Observer</class>
                        <method>saveCustomData</method>
                    </Lollicupstore_Createorder>
                </observers>
            </checkout_submit_all_after>
        </events>
    </adminhtml>
</config>

3. 创建 D:\www\lollicupStore2\app\code\local\Lollicupstore\Createorder\Model\Observer.php

<?php
/**
 * Created by PhpStorm.
 * User: lollicup
 * Date: 2019/4/25
 * Time: 16:10
 */

class Lollicupstore_Createorder_Model_Observer
{
    public function saveCustomData($observer)
    {
        $order        = $observer->getEvent()->getOrder();
        $increnmentId = $order->getIncrementId();
        $id           = $order->getId();
    }

}
        

该文章参考:
http://blog.chapagain.com.np/magento-create-your-own-custom-event-observer/

Leave a comment

您的电子邮箱地址不会被公开。 必填项已用*标注