我被要求对一些订单进行逆向工程(来自Ebay扩展),并找出他们真正使用的商店。
为了充实一个例子;我们从一个Magento后端经营几家商店,销售各种产品。这些都是使用单个商家帐户在eBay上出售的。
因此,我需要做的是加载分配给eBay商店的订单,加载附加到该订单的项目,然后查看该项目用于哪些其他商店。一旦我走到了这一步,我就可以简单地过滤掉管理员商店ID和eBay商店ID,它们将与我正在寻找的商店一起离开。
这是我到目前为止所拥有的:
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;
您可以使用 Mage_Catalog_Model_Product::getStoreIds() 方法来获取这些存储的列表:
$item = Mage::getModel('catalog/product')->load($item->getItemId());
$storeIds = $item->getStoreIds();
然后$storeIds将包含存储 ID 数组,当您转储它时:
var_dump($storeIds)
您应该得到以下结果:
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "3"
[2]=>
string(1) "5"
}
试试这个
$item = Mage::getModel('catalog/product')->load($item->getItemId());
$storeId = $item->getStoreId();
这对我来说很好用。