在Magento 1.9中,为什么订单电子邮件通过队列发送,而发票电子邮件直接发送?


8

在Magento 1.9中,为什么订单电子邮件通过队列发送,而发票电子邮件直接发送?我检查了订单和发票的代码,并order-sendNewOrderEmail使用了队列,同时invoice->sendEmail()完全跳过了队列。如果订单被自动批准,它将使订单电子邮件在发票电子邮件之后而不是之前发送!

Answers:


11

使用队列发送订单电子邮件的原因有多种:

  • 发送电子邮件时避免前端变慢
  • 重新发送失败
  • 避免在结帐/结帐后出现错误

解决方案1(立即发送订单的电子邮件):

如果您想立即发送订单电子邮件,可以考虑Mage_Sales_Model_Order::queueNewOrderEmail()通过链接以下几行来覆盖该方法:

/** @var $emailQueue Mage_Core_Model_Email_Queue */
$emailQueue = Mage::getModel('core/email_queue');
$emailQueue->setEntityId($this->getId())
    ->setEntityType(self::ENTITY)
    ->setEventType(self::EMAIL_EVENT_NAME_NEW_ORDER)
    ->setIsForceCheck(!$forceMode);

$mailer->setQueue($emailQueue)->send();

至:

    /** @var $emailQueue Mage_Core_Model_Email_Queue */
    $mailer->send();

解决方案2(使用队列发送发票):

相反的解决方案是让发票使用队列:

您必须覆盖Mage_Sales_Model_Order_Invoice::sendEmail更改:

// Set all required params and send emails
        $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
        $mailer->setStoreId($storeId);
        $mailer->setTemplateId($templateId);
        $mailer->setTemplateParams(array(
                'order'        => $order,
                'invoice'      => $this,
                'comment'      => $comment,
                'billing'      => $order->getBillingAddress(),
                'payment_html' => $paymentBlockHtml
            )
        );
        $mailer->send();

至:

// Set all required params and send emails
        $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
        $mailer->setStoreId($storeId);
        $mailer->setTemplateId($templateId);
        $mailer->setTemplateParams(array(
                'order'        => $order,
                'invoice'      => $this,
                'comment'      => $comment,
                'billing'      => $order->getBillingAddress(),
                'payment_html' => $paymentBlockHtml
            )
        );

        $emailQueue = Mage::getModel('core/email_queue');
        $emailQueue->setEntityId($this->getId())
          ->setEntityType('order_invoice')
          ->setEventType('new_invoice');

        $mailer->setQueue($emailQueue)->send();

非常感谢您的建议!我实际上做了同样的事情,但是反过来。我将发票添加到队列中。它奏效了,但我想知道这样做是否还正确?
帕特

1
是的,当然。我会将其添加到其他用户的帖子中。
Phoenix128_RiccardoT

1
似乎是好的解决方案。会尝试

1
我使用了解决方案1,它对我有效。谢谢
2016年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.