我通过调用sendNewOrderEmail();
方法发送订单电子邮件
但是电子邮件只与邮件的主题有关。没有消息:(
我做错了什么?
//http:/pragneshkaria.com/2011/08/11/genearate-order-programatically-magento-along-with-sales-quotes-sales-items-and-sales-address/
//http:/www.magentocommerce.com/boards/viewthread/28426/P45/
//require_once 'app/Mage.php';
require_once '../../../../../../../../../../app/Mage.php';
//$app = Mage::app('default');
$app = Mage::init(); // 1.5+
include('customer.php');
Mage::register('isSecureArea', true); //no output before here, will get a session header error
$customer_id = $customer->getId(); //222 rmuthe
$shopping_cart = array();
$part = array(
array("PartId" => '1', "Quantity" => '1'),
array("PartId" => '2', "Quantity" => '1')
);
$shopping_cart = $part; //repeat as necessary
//print_r($shopping_cart);
$params = array("AccountNo" => $customer_id, "PartCart" => $shopping_cart);
$quote_pk = PrepareOrder($params);
$order_pk = ConfirmOrder($quote_pk);
echo "<br />Quote Id Generated : " . $quote_pk;
echo "<br />Order Id Generated : " . $order_pk;
echo "<br />DONE";
function PrepareOrder($params) {
foreach ($params as $k => $v){
$$k = $v;
}
$customerObj = Mage::getModel('customer/customer')->load($AccountNo);
$storeId = $customerObj->getStoreId();
$quoteObj = Mage::getModel('sales/quote')->assignCustomer($customerObj); //sets ship/bill address
$storeObj = $quoteObj->getStore()->load($storeId);
$quoteObj->setStore($storeObj);
$productModel = Mage::getModel('catalog/product');
foreach ($PartCart as $part) {
foreach ($part as $k => $v) {
$$k = $v;
}
$productObj = $productModel->load($PartId);
//Modified Here annet-pk
//$quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
try{
$quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
} catch (Exception $e){
echo $e;
}
$quoteItem->setQuote($quoteObj);
$quoteItem->setQty($Quantity);
$quoteObj->addItem($quoteItem);
}
/*
$quoteObj->collectTotals();
$quoteObj->save();
*/
$shippingMethod = 'flatrate_flatrate';
$quoteObj->getShippingAddress()->setShippingMethod($shippingMethod);
$quoteObj->getShippingAddress()->setCollectShippingRates(true);
$quoteObj->getShippingAddress()->collectShippingRates();
$quoteObj->collectTotals();//calls $address->collectTotals();
$quoteObj->save();
$quoteId = $quoteObj->getId();
return $quoteId;
}
function ConfirmOrder($quoteId) {
/*
$hpc_connector_orderid = '786-2222222-3333333';
$hpc_connector_sitename = 'ebay'; //ebay / amazon
*/
//methods: authorizenet, paypal_express, googlecheckout, purchaseorder
$hpc_payment_method = 'checkmo';
//methods: flatrate_flatrate, freeshipping_freeshipping
$hpc_shipping_method = 'flatrate_flatrate';
$hpc_shipping_method_description = 'Here will be the links of the incoming items from the customer';
$quoteObj = Mage::getModel('sales/quote')->load($quoteId);
$items = $quoteObj->getAllItems();
$quoteObj->collectTotals();
$quoteObj->reserveOrderId();
$quotePaymentObj = $quoteObj->getPayment();
//methods: authorizenet, paypal_express, googlecheckout, purchaseorder
$quotePaymentObj->setMethod($hpc_payment_method);
$quoteObj->setPayment($quotePaymentObj);
$convertQuoteObj = Mage::getSingleton('sales/convert_quote');
$orderObj = $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
$orderPaymentObj = $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
//annet -pk to set shipping method
// $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()))
->setShipping_method($hpc_shipping_method)
->setShippingDescription($hpc_shipping_method_description);
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
/*
$orderObj->setHpcOrderId($hpc_connector_orderid);
$orderObj->setHpcOrderFrom($hpc_connector_sitename);
*/
foreach ($items as $item) {
//@var $item Mage_Sales_Model_Quote_Item
$orderItem = $convertQuoteObj->itemToOrderItem($item);
if ($item->getParentItem()) {
$orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
}
$orderObj->addItem($orderItem);
}
$orderObj->setCanShipPartiallyItem(false);
$totalDue = $orderObj->getTotalDue();
//$orderObj->sendNewOrderEmail();
$orderObj->place(); //calls _placePayment
$orderObj->save();
// $orderId = $orderObj->getId();
// return $orderId;
$orderObj->load(Mage::getSingleton('sales/order')->getLastOrderId());
$lastOrderId = $orderObj->getIncrementId();
echo "Recent Order Id :".$lastOrderId;
/***************EMAIL*****************/
$orderObj->loadByIncrementId($lastOrderId);
try{
echo "Trying to send an mail";
$emailed = $orderObj->sendNewOrderEmail();
}catch (Exception $ex){
echo "Failed to send a confirmation mail";
}
/***************EMAIL*****************/
return $lastOrderId;
}
答案 0 :(得分:0)
我发现了我的问题。它在Magento1.5.1.0中。在此版本中,从后端发送订单确认邮件时出现问题。每当我试图通过错误发送邮件。这就是为什么我通过错误评论两行代码。那些线是关于获得订单内容的翻译。这就是为什么它没有发送完整的订单确认邮件。后来我将magento版本降级为1.4.2.0。现在它只使用相同的代码工作正常,我需要更改如下所示的一行:
$app = Mage::app();