如何按商店获取产品价格过滤器
How to get product price filter by store
我正在尝试根据 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());
}
但是在 return 我得到的是默认价格,有什么我遗漏或做错了什么吗?
感谢任何帮助。
尝试在 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'))
这对我有用:
$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());
}
我正在尝试根据 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());
}
但是在 return 我得到的是默认价格,有什么我遗漏或做错了什么吗?
感谢任何帮助。
尝试在 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'))
这对我有用:
$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());
}