Skip to content

Instantly share code, notes, and snippets.

@ProxiBlue
Created May 20, 2016 03:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ProxiBlue/69c19211f197946cda06500c7fb46841 to your computer and use it in GitHub Desktop.
Save ProxiBlue/69c19211f197946cda06500c7fb46841 to your computer and use it in GitHub Desktop.
Magento 1: Convert Quote to Order
<?php
/**
* Convert a quote to an order object
* Note Bundle items selections do not show
*
* @author Lucas van Staden
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
require_once '../shell/abstract.php';
class Mage_Shell_ConvertQuote extends Mage_Shell_Abstract {
/**
* Runner
*/
public function run() {
if ($this->getArg('id')) {
$quote = Mage::getModel('sales/quote')->setStoreId(1)->load($this->getArg('id'));
$payment = $quote->getPayment();
$items = $quote->getAllVisibleItems();
try {
//$this->createOrder(6112, $payment);
$convertObj = Mage::getSingleton('sales/convert_quote');
//$order = $convertObj->toOrder($quote);
$order = $convertObj->addressToOrder($quote->getShippingAddress());
$order->setPayment($convertObj->paymentToOrderPayment($payment));
$order->setBillingAddress($convertObj->addressToOrderAddress($quote->getBillingAddress()));
$order->setShippingAddress($convertObj->addressToOrderAddress($quote->getShippingAddress()));
// convert quote items
foreach ($items as $item) {
// @var $item Mage_Sales_Model_Quote_Item
$orderItem = $convertObj->itemToOrderItem($item);
$options = array();
if ($productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) {
$options = $productOptions;
}
if ($addOptions = $item->getOptionByCode('additional_options')) {
$options['additional_options'] = unserialize($addOptions->getValue());
}
if ($options) {
$orderItem->setProductOptions($options);
}
if ($item->getParentItem()) {
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
}
$order->addItem($orderItem);
}
$order->setCanShipPartiallyItem(false);
$order->setStatus('Processing');
$order->save();
} catch (Exception $e) {
die($e->getMessage());
}
} else {
die($this->usageHelp());
}
echo "Done.";
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp() {
return <<<USAGE
Usage: php -f convertQuoteToOrder -- [options]
--id <quote id> Covert the quote id to an order
USAGE;
}
}
$shell = new Mage_Shell_ConvertQuote();
$shell->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment