Ventes / commande courriel n'envoyées lorsque le statut est « traitement »
-
16-10-2019 - |
Question
Mage 1.5.1.0 avec le ASchroder.com SMTP Pro Email l'extension, j'ai des choses correctement configurées, pour autant que je peux dire, parce que quand une commande est placé et le statut est en attente * Je reçois l'e-mail de commande. Cependant, lorsque l'état est immédiatement traitement *, je ne pas obtenir le courrier électronique de commande.
* état immédiatement défini, aucune autre mesure prise, que ce soit via Magento ou la passerelle du processeur de paiement correspondant.
Est-ce comportement par défaut? Si oui, comment puis-je configurer Mage d'envoyer un courriel lorsqu'une commande avec aucun statut est soumis?
La solution
Just updating the status/state of the order does not trigger any emails to be sent. The most relevant code is in
app/code/core/Mage/Sales/Model/Order.php
protected function _setState($state, $status = false, $comment = '', $isCustomerNotified = null, $shouldProtectState = false)
{
// attempt to set the specified state
if ($shouldProtectState) {
if ($this->isStateProtected($state)) {
Mage::throwException(Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state));
}
}
$this->setData('state', $state);
// add status history
if ($status) {
if ($status === true) {
$status = $this->getConfig()->getStateDefaultStatus($state);
}
$this->setStatus($status);
$history = $this->addStatusHistoryComment($comment, false); // no sense to set $status again
$history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility
}
return $this;
}
which does not include any calls to the email sending code. This is usually handled by each individual payment method and can differ substantially. Some will send the order confirmation email, some will send the invoice confirmation email only. If your payment method does not send any emails at all this seems like an oversight during development. For example in
/app/code/core/Mage/Paypal/Model/Express/Checkout.php
you will find $order->sendNewOrderEmail()
to trigger the email sending part.
If all payment methods are not sending any emails check your email sending settings under System > Configuration > Sales Email
if this is not disabled it is time to further check your email configuration and server/Magento error logs for further clues as to why no emails are being sent once you have confirmed what your code is meant to send.
Autres conseils
You can use Magento event/observer.
1. Add observer for sales_order_save_after
event:
<global>
<events>
<sales_order_save_after>
<observers>
<some_module>
<class>Some_Module_Model_Observer</class>
<method>salesOrderSaveAfter</method>
</some_module>
</observers>
</sales_order_save_after>
</events>
</global>
2.Send email in the observer if new order email was not sent already:
class Some_Module_Model_Observer
{
public function salesOrderSaveAfter($observer)
{
/**
* @var $order Mage_Sales_Model_Order
*/
$order = $observer->getDataObject();
if(!$order->getEmailSent()){
try{
$order->sendNewOrderEmail();
$historyItem = Mage::getResourceModel('sales/order_status_history_collection')
->getUnnotifiedForInstance($order, Mage_Sales_Model_Order::HISTORY_ENTITY_NAME);
//track history
if ($historyItem) {
$historyItem->setIsCustomerNotified(1);
$historyItem->save();
}
}catch (Exception $e){
//some exception handling
}
}
}
}
By the way sales_order_save_after
event fires when order status changed via admin panel or payment module and your observer sends email if order confirmation email not sent.