I'm working on a module which imports orders from an external system; the code is working and orders are being created, but are appearing under the wrong Store View.

Our installation uses only a single Website, Group, and Store View: "Main Website > Main Website Store > Default Store View", and so I was surprised to see orders being imported under "Admin > Default > Admin", with an Order Number / Increment Id which doesn't align with our other orders.

How do I assign the Store View to an Order which is programatically created?

After reviewing and comparing several code samples, would it be as simple as initializing the sales/quote with:


The current code is simply:


...would the effect of omitting setStoreId() be that the quote, order, and invoice are assigned to the "Admin" store view rather than the "Default Store View"?

1 Answer 1


you can add this at the top of your import script to emulate a store view

$storeId = Mage::getModel('core/store')->load('default')->getId();
$appEmulation = \Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

when you are done add this to get back to the initial store


This way your orders will be created just like being in the frontend in the default store view.

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.