php - Magento 使用什么事件发送订单确认邮件

标签 php magento zend-framework

我写的模块有问题。我已经创建了上传 XML 并为管理员发送通知的观察者。

我有 2 个事件的测试:<sales_order_place_after><sales_order_save_after> .

问题是我提供两种付款方式(银行转帐和信用卡)。一立即改变状态为[New] (银行转帐) 和其他是用信用卡付款的状态[Processing]在捕获付款之前和捕获付款之后[New] .

这给我带来了问题,因为我只想为每个订单上传一次 XML,并且 <sales_order_save_after>每个订单更新和<sales_order_place_after>的触发事件只触发一次,而不是在付款被捕获时触发。

我认为解决方案是使用与 Magento 相同的事件来发送订单确认邮件。那是哪个事件?

这是我的观察器,它不能正常工作。

public function salesOrderSaveAfter($observer) { .... if ($orderStatus == 'pending' || $orderStatus == 'bank_transfer' ) {

有什么解决这个问题的建议吗?

最佳答案

订单确认电子邮件不是由事件触发的。它们由 Mage_Checkout_Model_Type_Onepage 类中的 saveOrder() 方法触发。

您应该会看到一些类似的代码;

/**
 * a flag to set that there will be redirect to third party after confirmation
 * eg: paypal standard ipn
 */
$redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
/**
 * we only want to send to customer about new order when there is no redirect to third party
 */
if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
    try {
        $order->sendNewOrderEmail();
    } catch (Exception $e) {
        Mage::logException($e);
    }
}

这基本上会在下订单后立即发送确认电子邮件,除非支付方式具有重定向 URL(即第三方支付页面,如 PayPal 标准)。

如果您不希望针对特定支付方式发送电子邮件,您可以覆盖上面的函数并让它检查支付类型;

if (!$redirectUrl && $order->getPayment()->getMethod() != 'your_payment_method' && $order->getCanSendNewEmailFlag()) {
    try {
        $order->sendNewOrderEmail();
    } catch (Exception $e) {
        Mage::logException($e);
    }
}

要触发观察者发送确认电子邮件,只需加载订单对象并调用 $order->sendNewOrderEmail();

关于php - Magento 使用什么事件发送订单确认邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22632254/

相关文章:

php - 从 .htaccess mod_rewrite 规则中排除子域?

php - 如何从 Magento 2.3 中的最后一个订单中检索信息

php - Magento : How to check if admin is logged in within a module controller?

zend-framework - Zend MVC 项目与 Node.js 一起提高 JavaScript 性能

php - 如何根据 Android 上的用户输入从数据库返回数据?

php - 如果成功插入数据库,则创建成功消息

magento - magento 管理面板中的颜色选择器

ios - 从 iOS 中的 magento 2.0 获取完整图像 URL

php - 以特殊字符开头的路由 URL

php - 在静态函数中访问公共(public)/私有(private)函数?