如何通过商店过滤产品价格

时间:2015-03-23 04:20:17

标签: magento magento-1.9

我想根据Magento的商店ID获取产品价格。我使用以下代码:

$store_id=2;
$collection=Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect(array('name','image', 'price','special_price', 'special_packing','prosort','description','special_from_date','special_to_date'))
->addStoreFilter($store_id)
->addAttributeToSort('position');
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

foreach($collection as $product){

$products = Mage::getModel('catalog/product')->load($product->getId());
print_r($products->getPrice());
}

但作为回报,我得到默认价格,我有什么遗漏或做错了吗?

任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:0)

尝试在getCollection之后使用setStoreId()而不是addStoreFilter

$collection = Mage::getModel('catalog/product')->getCollection()->setStoreId($store_id);
$collection->addAttributeToSelect(array('name','image', 'price','special_price', 'special_packing','prosort','description','special_from_date','special_to_date'))

答案 1 :(得分:0)

这对我有用:

$store_id=2;
$collection=Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect(array('name','image', 'price','special_price', 'special_packing','prosort','description','special_from_date','special_to_date'))
->setStore($store_id)
->addAttributeToSort('position');

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    foreach($collection as $product){

    $products = Mage::getModel('catalog/product')->load($product->getId());
    print_r($products->getPrice());
    }