有没有办法以编程方式将发送的电子邮件标记为已发送?在通过谷歌寻求帮助之后,我空手而归。
我已经设置了一个观察员,只要将一个跟踪号码添加到货件中就会发送一封电子邮件,但我需要能够在管理员中显示电子邮件已发送的一些信息,而不是显示“发送邮件不会发送。“
更新
这是我的代码。我可以收到发送的电子邮件,但我无法设置email_sent标志
class WR_TrackingEmail_Model_Observer
{
public function sendTrackEmail($observer)
{
$track = $observer->getEvent()->getTrack();
$shipment = $track->getShipment(true);
$shipment->sendEmail();
$shipment->setEmailSent(true);
}
}
<小时/> 更新2
尝试以下代码后,我遇到了一个新问题。该商品已标记为已发货但由于某种原因,我会收到一百万份发货邮件。我假设某个循环正在发生。谁能告诉我这里我做错了什么?
public function sendTrackEmail($observer)
{
$track = $observer->getEvent()->getTrack();
$shipment = $track->getShipment(true);
$shipment->sendEmail();
$shipment->setEmailSent(true);
$saveTransaction = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}
答案 0 :(得分:1)
通常,这是设置所有货件状态以及所有通知电子邮件的方式: -
$_eachOrderTrackingNum = 'ANY_SPECIFIC_TRACKING_NUMBER';
$arrTracking = array(
'carrier_code' => 'ups',
'title' => 'United Parcel Service',
'number' => $_eachOrderTrackingNum,
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$emailSentStatus = $shipment->getData('email_sent');
$customerEmail = $order->getData('customer_email');
if (!is_null($customerEmail) && !$emailSentStatus) {
$shipment->sendEmail($customerEmail, '');
$shipment->setEmailSent(true);
}
$saveTransaction = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
此处“$shipment
”是订单转换为此货件对象后的“Mage_Sales_Model_Order_Shipment
”对象。 “$order
”也是特定的Order对象。
希望它有所帮助。
<强>更新强>
看到您的更新后,您似乎需要为方法“sendTrackEmail()
”使用以下代码: -
public function sendTrackEmail($observer)
{
$track = $observer->getEvent()->getTrack();
$shipment = $track->getShipment(true);
$shipment->sendEmail();
$shipment->setEmailSent(true);
$saveTransaction = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}