开发者

Magento - add attributes to Invoice Items

I would like to add the attribute 'epagine_download' to invoice items. I've created an Observer that listens to the sales_order_invoice_pay event. The Idea is that the observer will fill that attribute 'epagine_download' with an url specific for the customer (and will in fact be obtained by calling an external webservice).

I've managed to create the attribute via following code :

    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('invoice_item', 'epagine_download', array(
    'label'                       => 'Download',
    'type'                        => 'varchar',
    'input'                       => 'text'  ,
    'visible'                     => false,
    'required'                    => false  
))

This is my config of the observer :

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <eboeksales>
                <class>Eboek_Sales_Model</class>
            </eboeksales>
        </models>
        <events>
            <sales_order_invoice_pay>
                <observers>
                    <eboek_sales_pay_observer>
                        <type>singleton</type>
                        <class>Eboek_Sales_Model_Pay_Observer</class>
                        <method>handle_sales_invoice_paid</method>
                    </eboek_sales_pay_observer>

                </observers>
            </sales_order_invoice_pay>    
        </events>
    </global>

</config>

Now I'm stuck implementing the observer. It seems the getData doesn't retun my new attribute "epagine_download". What am I missing ? I test this by creating an invoice in the adminmodule. For some reason I can't use var_dump here, so I use Mage::log. I also call a unexisting function GetBlahBlah so I get an exception and thus preventing the invoice from being created, so I won't need create a new order each time I want to test.

class Eboek_Sales_Model_Pay_Observer {
    public function __construct()
    {

    }
    /**
     *
     * @param Varien_Event_Observer $observer
     * @return Eboek_Sales_Model_Pay_Observer
     */
    public function handle_sales_invoice_paid($observer)
    {

        $event = $observer->getEvent();
        Mage::log("Hello8812");
        $inv=$event->getInvoice();

        #Mage::log($inv);
        $a= $inv->getAllItems();

        Mage::log("=========================================================================");
        Mage::log($a[0]->getOrderItem()->getData());
        Mage::log("=========================================================================");
        Mage::log($a[0]->getData());
        Mage::log("===================================开发者_开发技巧======================================");
        $event->GetBlahBlah();

        return $this;
    }
}

(Magento version is 1.4) Thanks for feedback...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜