2011-08-24 107 views
1

我通過調用方法發送訂單電子郵件sendNewOrderEmail(); 但是電子郵件只與郵件的主題一起發送。沒有消息就是有:( 什麼錯了,我想提出?Magento:訂單電子郵件不完整

//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

我發現我的問題。這是在Magento1.5.1.0。在這個版本中有從發送的訂單確認郵件的問題後端,每當我嘗試通過錯誤發送郵件時,這就是爲什麼我通過錯誤評論了兩行代碼,這些行是關於獲取訂單內容的翻譯,這就是爲什麼它沒有發送完整的訂單確認郵件。 magento版本到1.4.2.0。現在它工作正常,只有相同的代碼,我需要改變一行如下:

$app = Mage::app(); 
相關問題