5

I want to create order from quote id . I am using this code but order is not getting created

$quote = Mage::getModel('sales/quote')->load(94251);
$convertQuote = Mage::getSingleton('sales/convert_quote'); 
$order = $convertQuote->toOrder($quote);

I get error that Credit card number mismatch with credit card type. payment method already store in quote. payment method is authnetcim.

  • pls try my answer and let me know it works or not. – Nikunj Vadariya Oct 20 '16 at 11:28
  • Anyone have solution for this?? – Jigs Parmar Oct 30 '17 at 3:22
0

Try something like below :

$store = Mage::getSingleton('core/store')->load(1);

$quote = Mage::getModel('sales/quote')->setStore($store)->load(94251);
$quote->assignCustomer(Mage::getSingleton('customer/session')->getCustomer());

$quote->collectTotals()
    ->getPayment()->setMethod('purchaseorder');

$convert = Mage::getModel('sales/convert_quote');
$order = $convert->toOrder($quote)
    ->setBillingAddress(
        $convert->addressToOrderAddress($quote->getBillingAddress())
    )
    ->setShippingAddress(
        $convert->addressToOrderAddress($quote->getShippingAddress())
    )
    ->setPayment(
        $convert->paymentToOrderPayment($quote->getPayment())
    );

foreach ($quote->getAllItems() as $quoteItem) {
    $orderItem = $convert->itemToOrderItem($quoteItem);
    if ($quoteItem->getParentItem()) {
        $orderItem->setParentItem(
            $order->getItemByQuoteItemId($quoteItem->getParentItem()->getId())
        );
    }
    $order->addItem($orderItem);
}

$order->save();
  • it not works. no any order createa – Jigs Parmar Oct 20 '16 at 12:05
  • and i not want to store any static information when create order – Jigs Parmar Oct 20 '16 at 12:05
0

Here is the script:

$quote = Mage::getModel('sales/quote')->load(5428);

$convert = Mage::getModel('sales/convert_quote');

$order = $convert->toOrder($quote);
$order->addressToOrder($quote->getAddress(),$order);

foreach($quote->getAllItems() as $item){
    $orderItem = $convert->itemToOrderItem($item);
    if ($item->getParentItem()) {
       $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
    }
    $order->addItem($orderItem);
}

$quote->getShippingAddress()->setPaymentMethod('paypal_express');
$quote->getShippingAddress()->setCollectShippingRates(true);

$payment = $quote->getPayment();
$payment->importData($data);
$quote->save();

$payment = $convert->paymentToOrderPayment($quote->getPayment());

$order->setPayment($quote->getPayment());

$message = '[Notice] - Order converted from quote manually';
$order->addStatusToHistory($order->getStatus(), $message);
$order->place();
$order->save();

$quote->setIsActive(false)->save();

Other solution:-

Have you tried the toOrder Method?

http://docs.magentocommerce.com/Mage_Sales/Mage_Sales_Model_Convert_Quote.html#toOrder

EDIT :-

$convertQuote = Mage::getSingleton('sales/convert_quote'); $order = $convertQuote->toOrder($quote);
  • in quote there is all information store already. so no any static info store. – Jigs Parmar Oct 21 '16 at 3:35
  • Your "other solution" is just the beginning bit of your main solution. It's also the same as what jigs tried already, as shown in his question. – Doug McLean Dec 7 '17 at 15:23
  • And where does $data come from in the line $payment->importData($data);? – Doug McLean Dec 7 '17 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.