事件不会在magento api sales_order_invoice.create中触发

时间:2017-08-03 12:02:25

标签: api magento

我正在使用SOAP V1 api

$parameters = array('orderIncrementId' => $postdata['order_id'], $items);

$createInvoice = $proxy->call($sessionId,'sales_order_invoice.create', $parameters);

有人可以帮助我,如何在api发票时触发发票事件(sales_order_invoice_pay)。

1 个答案:

答案 0 :(得分:0)

从API创建发票后创建自定义事件。

$baseUrl = 'http://example.com/index.php/';

$proxy = new SoapClient($baseUrl.'api/soap/?wsdl');

$createInvoice = $proxy->call($sessionId,'sales_order_invoice.create', $parameters);

$orderinvoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($createInvoice);

Mage::dispatchEvent('sales_order_invoice_pay_api', array('invoice'=>$orderinvoice));

在模块config.xml文件中添加事件触发器

<config>
    <global>
     ..........
     ..........
      <events>
           <sales_order_invoice_pay_api>
                <observers>
                    <namespace_modulename_model_observer>
                        <type>singleton</type>
                        <class>Namespace_Modulename_Model_Observer</class>
                        <method>setinvoicestatetaxapi</method>
                    </namespace_modulename_model_observer>
                </observers>
            </sales_order_invoice_pay_api>
      </events>
     ..........
     ..........
   <global>
<config>

创建/修改Observer.php

<?php

class Namespace_Modulename_Model_Observer extends Varien_Object
{
...............
...............

public function setinvoicestatetaxapi(Varien_Event_Observer $observer)
{
  $invoice = $observer->getEvent()->getInvoice();
}

...............
...............
}