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.

2
  • pls try my answer and let me know it works or not. Commented Oct 20, 2016 at 11:28
  • Anyone have solution for this?? Commented Oct 30, 2017 at 3:22

2 Answers 2

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();
2
  • it not works. no any order createa Commented Oct 20, 2016 at 12:05
  • and i not want to store any static information when create order Commented Oct 20, 2016 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);
3
  • in quote there is all information store already. so no any static info store. Commented Oct 21, 2016 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. Commented Dec 7, 2017 at 15:23
  • And where does $data come from in the line $payment->importData($data);? Commented Dec 7, 2017 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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