I've been asked to reverse engineer some orders (from an Ebay Extension) and find out which store they really used.
To flesh out an example; we run several stores from one Magento backend selling various products. These are all sold on eBay using a single merchant account.
So what I need to do is load the order as it stands assigned against the eBay store, load the items attached to that order and then see what other stores that item is used on. Once I get that far I can simply filter out the admin storeID and the eBay storeID which will leave with the store I'm looking for.
this is what I have so far:
foreach($collection->getItems() as $order):
// need to do this to load correct order information
$order = Mage::getModel('sales/order')->loadByIncrementID($order->getIncrementId());
$items = $order->getItemsCollection();
foreach($items as $item) {
// need to do this to get the actual item, not the item on the order
$item = Mage::getModel('catalog/product')->load($item->getItemId());
// do something to get the other store ids
}
endforeach;
try this
$item = Mage::getModel('catalog/product')->load($item->getItemId());
$storeId = $item->getStoreId();
this works just fine for me.
You can use Mage_Catalog_Model_Product::getStoreIds() method to get list of these stores:
$item = Mage::getModel('catalog/product')->load($item->getItemId());
$storeIds = $item->getStoreIds();
Then $storeIds will contain array of store ids, and when you dump that:
var_dump($storeIds)
you should get following result:
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "3"
[2]=>
string(1) "5"
}