Magento:订单电子邮件不完整

Magento:订单电子邮件不完整,magento,Magento,我通过调用方法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/28

我通过调用方法
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;



}
//http://pragneshkaria.com/2011/08/11/generarate-order-programmaly-magento-with-sales-quotes-sales-items-and-sales-address/
//http://www.magentocommerce.com/boards/viewthread/28426/P45/
//需要一次“app/Mage.php”;
需要_once'../../../../../../../../../app/Mage.php';
//$app=Mage::app('default');
$app=Mage::init();//1.5+
包括('customer.php');
Mage::register('isSecureArea',true);//在此之前没有输出,将获得会话头错误
$customer_id=$customer->getId();//222 rmuthe
$shopping_cart=array();
$part=数组(
数组(“PartId”=>“1”,“数量”=>“1”),
数组(“PartId”=>'2',“Quantity”=>'1')
);
$shopping\u cart=$part;//必要时重复
//打印(购物车);
$params=array(“AccountNo”=>$customer\u id,“PartCart”=>$shopping\u cart);
$quote_pk=PrepareOrder($params);
$order\U pk=确认人($quote\U pk);
echo“
生成的报价Id:”.$Quote\u pk; echo“
生成的订单Id:.$Order\u pk; 回显“
完成”; 函数PrepareOrder($params){ foreach($k=>v的参数){ $$k=$v; } $customerObj=Mage::getModel('customer/customer')->load($AccountNo); $storeId=$customerObj->getStoreId(); $quoteObj=Mage::getModel('sales/quote')->assignCustomer($customerObj);//设置发货/账单地址 $storeObj=$quoteObj->getStore()->load($storeId); $quoteObj->setStore($storeObj); $productModel=Mage::getModel('catalog/product'); foreach($PartCart作为$part){ foreach($k=>v部分){ $$k=$v; } $productObj=$productModel->load($PartId); //在这里修改annet pk //$quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj); 试一试{ $quoteItem=Mage::getModel('sales/quote_item')->setProduct($productObj); }捕获(例外$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();//调用$address->collectTotals(); $quoteObj->save(); $quoteId=$quoteObj->getId(); 返回$quoteId; } 函数确认器($quoteId){ /* $hpc_连接器_订单ID='786-222222-3333333'; $hpc_connector_sitename='ebay';//ebay/amazon */ //方法:authorizenet、paypal_express、Google Checkout、purchaseorder $hpc_付款方法='checkmo'; //方法:平推法、自由推注法、自由推注法 $hpc_shipping_方法='flatrate_flatrate'; $hpc_shipping_method_description='这里是来自客户的进货链接'; $quoteObj=Mage::getModel('sales/quote')->load($quoteId); $items=$quoteObj->getAllItems(); $quoteObj->collectTotals(); $quoteObj->reserveOrderId(); $quotePaymentObj=$quoteObj->getPayment(); //方法:authorizenet、paypal_express、Google Checkout、purchaseorder $quotePaymentObj->setMethod($hpc_支付方法); $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设置装运方法 //$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()); $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress())) ->设置装运方法($hpc装运方法) ->设置装运说明($hpc\U装运方法\U说明); $orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()); /* $orderObj->setHpcOrderId($hpc\U连接器\U订单ID); $orderObj->setHpcOrderFrom($hpc\u connector\u sitename); */ foreach($items作为$item){ //@var$item Mage\u Sales\u Model\u Quote\u item $orderItem=$convertQuoteObj->itemToOrderItem($item); 如果($item->getParentItem()){ $orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()); } $orderObj->addItem($orderItem); } $orderObj->setcanshipppartiallyItem(false); $totalDue=$orderObj->getTotalDue(); //$orderObj->sendNewOrderEmail(); $orderObj->place();//调用_placePayment $orderObj->save(); //$orderId=$orderObj->getId(); //返回$orderId; $orderObj->load(Mage::getSingleton('sales/order')->getLastOrderId()); $lastOrderId=$orderObj->getIncrementId(); echo“最近订单Id:”.$lastOrderId; /***************电子邮件*****************/ $orderObj->loadByIncrementId($lastOrderId); 试一试{ 回显“试图发送邮件”; $emailed=$orderObj->sendNewOrderEmail(); }捕获(例外$ex){ echo“发送确认邮件失败”; } /***************电子邮件*****************/ 返回$lastOrderId; }
我发现了我的问题。这是在Magento1.5.1.0中。在这个版本中,从后端发送订单确认邮件时出现问题。每当我试图通过错误发送邮件时。这就是为什么我注释了两行代码,这两行代码都是错误的。这些代码是关于获取订单内容的翻译。这就是为什么它失败的原因o发送完整的订单确认邮件。稍后我将
$app = Mage::app();