2013-04-29 84 views
0

我使用貝寶作爲網關,我想我會編輯IPN監聽器並根據貝寶結果更新客戶組。Magento - 成功訂單更改客戶組

有沒有更像'Magento'這樣做的方式,就像重寫方法一樣,如果是的話,我會在那裏做什麼?

回答

2

事件觀察者在這裏會有意義。不知道paypal_payment_transaction_save_after事件會在這裏工作;在保存成功的IPN付款後檢查訂單將起作用。

0

爲別人找這個功能,這是我做的:

要覆蓋的Magento 1.7.0.2貝寶例程我複製

/應用/代碼/核心/法師/貝寶/

/應用程序/代碼/本地/法師/貝寶/

我然後加入下面的方法來/app/code/local/Mage/Paypal/Model/Ipn.php

protected function _changeUserGroup($group){ 

    $invoice_id = $this->_request['invoice']; 

    // get the resource model 
    $resource = Mage::getSingleton('core/resource'); 

    // retrieve the read connection 
    $read = $resource->getConnection('core_read'); 

    // get the customer_id for the invoice from the database 
    $customer_id = (int) $read->fetchOne($read->select()->from('sales_flat_order','customer_id')->where("increment_id='$invoice_id'")->limit(1)); 

    // retrieve the write connection 
    $write = $resource->getConnection('core_write'); 

    // raw query 
    $query = "UPDATE customer_entity SET group_id = $group WHERE entity_id = $customer_id"; 

    // execute the query 
    $write->query($query); 

} 

然後,您可以在IPN過程中的任何位置調用此方法以適合您的目的。我發現http://fishpig.co.uk/blog/direct-sql-queries-magento.html對數據庫調用很有用。