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