2015-04-14 119 views
0

我正在開發Magento的高級serach。 我按4個屬性進行搜索。現在,當我選擇其中一個屬性時,我需要重新加載其他屬性以禁用不符合所選屬性的屬性。這有可能以一些簡單的方式?用其他屬性過濾magento的產品屬性

回答

0

rzeka,

你可以過濾這種方式...

$collection = Mage::getModel('catalog/product')->getCollection(); 
$collection->addAttributeToSelect('name'); 
$collection->addAttributeToSelect('orig_price');  

//filter for products whose orig_price is greater than (gt) 100 
$collection->addFieldToFilter(array(
    array('attribute'=>'orig_price','gt'=>'100'), 
)); 

//AND filter for products whose orig_price is less than (lt) 130 
$collection->addFieldToFilter(array(
    array('attribute'=>'orig_price','lt'=>'130'), 
)); 
While this will filter by a name that equals one thing OR another. 

$collection = Mage::getModel('catalog/product')->getCollection(); 
$collection->addAttributeToSelect('name'); 
$collection->addAttributeToSelect('orig_price');  

//filter for products who name is equal (eq) to Widget A, or equal (eq) to Widget B 
$collection->addFieldToFilter(array(
    array('attribute'=>'name','eq'=>'Widget A'), 
    array('attribute'=>'name','eq'=>'Widget B'),   
));