【发布时间】:2013-04-29 17:01:37
【问题描述】:
我使用 paypal 作为网关,我想我会编辑 IPN 侦听器并根据 paypal 结果从那里更新客户组。
有没有更“Magento”的方式来做这件事,比如覆盖方法,如果有,我会在哪里做?
【问题讨论】:
标签: magento magento-1.7
我使用 paypal 作为网关,我想我会编辑 IPN 侦听器并根据 paypal 结果从那里更新客户组。
有没有更“Magento”的方式来做这件事,比如覆盖方法,如果有,我会在哪里做?
【问题讨论】:
标签: magento magento-1.7
事件观察者在这里是有意义的。不确定paypal_payment_transaction_save_after 事件是否会在这里起作用;保存成功的 IPN 付款后检查订单。
【讨论】:
对于其他正在寻找此功能的人,这就是我所做的:
要覆盖我复制的 Magento 1.7.0.2 贝宝例程
/app/code/core/Mage/Paypal/
到
/app/code/local/Mage/Paypal/
然后我将以下方法添加到 /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 对数据库调用很有用。
【讨论】: