0

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:

Mage::getModel('sales/quote')
  ->setStoreId(Mage::app('default')->getStore('default')->getId());

The current code is simply:

Mage::getModel('sales/quote')

...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"?

0

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

$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

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

| improve this answer | |

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.