I'm in the process of manually turning a few quotes into orders. Someone was kind enough to provide me the code that should do it from another question (How to manually convert a series of quotes to invoices (orders)). I'm not familiar with how to implement the following snippet:

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

// convert quote to order
$service = Mage::getModel('sales/service_quote', $quote);

$order = $service->getOrder();

Should this be inserted into a new controller and executed by namespace URL? I was originally going to preface this code with:


require_once('app/Mage.php'); //Path to Magento

However I'm told it will not trigger events.

With that said, what would be the best way to implement this? Thank you.

Secondary Question: What does the "load(1)" mean in the first line of code? Is that a reference to the quote ID?

  1. Resolve the sales/quote argument to a class (Mage_Sales_Model_Quote by default)
  2. Have the model invoke its resource model (Mage_Sales_Model_Resource_Quote by default) to transact with storage
  3. Read the sales/quote entity data with primary key of 1
  4. If the record exists, decorate the sales/quote instance with data

You should perhaps work through Alan Storm's articles in the Magento KB - particularly the ORM chapter.

If you want to run it via Web request I would lock the script down. What you are doing is a utility activity and probably doesn't require configuring a route (especially if it's a one-off or infrequent process). Whereas any PHP script in the webroot can be accessed directly, you can just do this as you are intending to - with what I call a workbench script (link contains notes):


error_reporting(E_ALL | E_STRICT);

require 'app/Mage.php';
#Mage::setIsDeveloperMode(true); //uncomment if stuff's broken


Now, if you need emails to go out, you want to make sure that theme and locale settings are applied. Do this with app emulation:

$appEmulation = Mage::getSingleton('core/app_emulation');
//Start environment emulation of the specified store
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
 * Any code thrown here will be executed as we are currently running that store
 * with applied locale, design and similar
//Stop environment emulation and restore original store

Then you just need to load the proper areas:

     ->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS)

(I might be getting superfluous with the emulation (getting rusty), but it shouldn't hurt and someone will correct me if I'm wrong.)

  • Thank you, that's very informative! This is a one-off solution so the workbench script method would suffice. However I'm getting a long error when I attempt either method that seems to be related to process: 'Quote totals must be collected before this operation.' dropbox.com/s/hhyb8hd4v59q5dq/… – sparecycle Dec 11 '14 at 18:59

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.