Magento:订单电子邮件不完整

m1m5dgzv  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(228)

我通过调用方法sendNewOrderEmail();发送订单电子邮件,但是电子邮件只包含邮件的主题。没有消息在那里:(我犯了什么错?)

  1. //http:/pragneshkaria.com/2011/08/11/genearate-order-programatically-magento-along-with-sales-quotes-sales-items-and-sales-address/
  2. //http:/www.magentocommerce.com/boards/viewthread/28426/P45/
  3. //require_once 'app/Mage.php';
  4. require_once '../../../../../../../../../../app/Mage.php';
  5. //$app = Mage::app('default');
  6. $app = Mage::init(); // 1.5+
  7. include('customer.php');
  8. Mage::register('isSecureArea', true); //no output before here, will get a session header error
  9. $customer_id = $customer->getId(); //222 rmuthe
  10. $shopping_cart = array();
  11. $part = array(
  12. array("PartId" => '1', "Quantity" => '1'),
  13. array("PartId" => '2', "Quantity" => '1')
  14. );
  15. $shopping_cart = $part; //repeat as necessary
  16. //print_r($shopping_cart);
  17. $params = array("AccountNo" => $customer_id, "PartCart" => $shopping_cart);
  18. $quote_pk = PrepareOrder($params);
  19. $order_pk = ConfirmOrder($quote_pk);
  20. echo "<br />Quote Id Generated : " . $quote_pk;
  21. echo "<br />Order Id Generated : " . $order_pk;
  22. echo "<br />DONE";
  23. function PrepareOrder($params) {
  24. foreach ($params as $k => $v){
  25. $$k = $v;
  26. }
  27. $customerObj = Mage::getModel('customer/customer')->load($AccountNo);
  28. $storeId = $customerObj->getStoreId();
  29. $quoteObj = Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
  30. $storeObj = $quoteObj->getStore()->load($storeId);
  31. $quoteObj->setStore($storeObj);
  32. $productModel = Mage::getModel('catalog/product');
  33. foreach ($PartCart as $part) {
  34. foreach ($part as $k => $v) {
  35. $$k = $v;
  36. }
  37. $productObj = $productModel->load($PartId);
  38. //Modified Here annet-pk
  39. //$quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
  40. try{
  41. $quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
  42. } catch (Exception $e){
  43. echo $e;
  44. }
  45. $quoteItem->setQuote($quoteObj);
  46. $quoteItem->setQty($Quantity);
  47. $quoteObj->addItem($quoteItem);
  48. }
  49. /*
  50. $quoteObj->collectTotals();
  51. $quoteObj->save();
  52. */
  53. $shippingMethod = 'flatrate_flatrate';
  54. $quoteObj->getShippingAddress()->setShippingMethod($shippingMethod);
  55. $quoteObj->getShippingAddress()->setCollectShippingRates(true);
  56. $quoteObj->getShippingAddress()->collectShippingRates();
  57. $quoteObj->collectTotals();//calls $address->collectTotals();
  58. $quoteObj->save();
  59. $quoteId = $quoteObj->getId();
  60. return $quoteId;
  61. }
  62. function ConfirmOrder($quoteId) {
  63. /*
  64. $hpc_connector_orderid = '786-2222222-3333333';
  65. $hpc_connector_sitename = 'ebay'; //ebay / amazon
  66. * /
  67. //methods: authorizenet, paypal_express, googlecheckout, purchaseorder
  68. $hpc_payment_method = 'checkmo';
  69. //methods: flatrate_flatrate, freeshipping_freeshipping
  70. $hpc_shipping_method = 'flatrate_flatrate';
  71. $hpc_shipping_method_description = 'Here will be the links of the incoming items from the customer';
  72. $quoteObj = Mage::getModel('sales/quote')->load($quoteId);
  73. $items = $quoteObj->getAllItems();
  74. $quoteObj->collectTotals();
  75. $quoteObj->reserveOrderId();
  76. $quotePaymentObj = $quoteObj->getPayment();
  77. //methods: authorizenet, paypal_express, googlecheckout, purchaseorder
  78. $quotePaymentObj->setMethod($hpc_payment_method);
  79. $quoteObj->setPayment($quotePaymentObj);
  80. $convertQuoteObj = Mage::getSingleton('sales/convert_quote');
  81. $orderObj = $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
  82. $orderPaymentObj = $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);
  83. $orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
  84. //annet -pk to set shipping method
  85. // $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
  86. $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()))
  87. ->setShipping_method($hpc_shipping_method)
  88. ->setShippingDescription($hpc_shipping_method_description);
  89. $orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
  90. /*
  91. $orderObj->setHpcOrderId($hpc_connector_orderid);
  92. $orderObj->setHpcOrderFrom($hpc_connector_sitename);
  93. */
  94. foreach ($items as $item) {
  95. //@var $item Mage_Sales_Model_Quote_Item
  96. $orderItem = $convertQuoteObj->itemToOrderItem($item);
  97. if ($item->getParentItem()) {
  98. $orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
  99. }
  100. $orderObj->addItem($orderItem);
  101. }
  102. $orderObj->setCanShipPartiallyItem(false);
  103. $totalDue = $orderObj->getTotalDue();
  104. //$orderObj->sendNewOrderEmail();
  105. $orderObj->place(); //calls _placePayment
  106. $orderObj->save();
  107. // $orderId = $orderObj->getId();
  108. // return $orderId;
  109. $orderObj->load(Mage::getSingleton('sales/order')->getLastOrderId());
  110. $lastOrderId = $orderObj->getIncrementId();
  111. echo "Recent Order Id :".$lastOrderId;
  112. /***************EMAIL*****************/
  113. $orderObj->loadByIncrementId($lastOrderId);
  114. try{
  115. echo "Trying to send an mail";
  116. $emailed = $orderObj->sendNewOrderEmail();
  117. }catch (Exception $ex){
  118. echo "Failed to send a confirmation mail";
  119. }
  120. /***************EMAIL*****************/
  121. return $lastOrderId;
  122. }
xa9qqrwz

xa9qqrwz1#

我已经找到了我的问题。它是在Magento1.5.1.0。在这个版本中有一个问题,在发送确认邮件的订单从后端。每当我试图发送邮件它通过错误。这就是为什么我注解了两行代码通过错误。这些行是关于获得翻译的订单内容。这就是为什么它是失败的发送一个完整的订单确认邮件。后来我把magento版本降级到1.4.2.0。现在它可以用同样的代码正常工作了,只是我需要像下面这样修改一行:

  1. $app = Mage::app();

相关问题