Magento: электронная почта заказа неполна - PullRequest
1 голос
/ 24 августа 2011

Я отправляю электронное письмо с заказом, вызывая метод 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;



}

1 Ответ

0 голосов
/ 26 августа 2011

Я нашел свою проблему. Это было в Magento 1.5.1.0. В этой версии возникла проблема с отправкой письма с подтверждением заказа из бэкэнда. Всякий раз, когда я пытаюсь отправить письмо по ошибке. Вот почему я прокомментировал две строки кода, которые из-за ошибки. Эти строки были о переводе содержания заказа. Вот почему не удалось отправить полное подтверждение заказа по почте. Позже я ухудшил версию magento до 1.4.2.0. Теперь он работает нормально с тем же кодом, мне нужно изменить одну строку, как показано ниже:

$app = Mage::app();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...