在Magento有什么方法可以根据产品类别过滤产品属性? 其实我正在努力建立Make - >型号 - >年份类型的搜索功能。
以下代码可以很好地构建产品属性的下拉列表,但我想根据类别过滤属性
$makeattribute_code = $attr_name;
$resource = Mage::getSingleton('core/resource');
$readonce = $resource->getConnection('core_read');
$table1 = $resource->getTableName('eav_attribute');
$table2 = $resource->getTableName('catalog_product_entity_varchar');
$makequery = $readonce->query("select attribute_id from " . $table1 . " where attribute_code='" . $makeattribute_code . "'");
$row = $makequery->fetch();
$make_attributeid = $row['attribute_id'];
$genquery1 = $readonce->query("select attribute_id from " . $table1 . " where attribute_code='" . $modelattribute_code . "'");
$row = $genquery1->fetch();
$model_attributeid = $row['attribute_id'];
$queryString = "SELECT distinct value from " . $table2 . " where attribute_id=" . $model_attributeid . " and entity_id in (select entity_id from " . $table2 . " where attribute_id=" . $make_attributeid . " and value like '%" . $value . "%') order by value";
答案 0 :(得分:2)
您可以从分层导航块中窃取逻辑
// Id of category we want to get attributes for
$categoryId = 355;
// Products in that category
$products = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();
// Get all attributes
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setItemObjectClass('catalog/resource_eav_attribute')
// Filter by attribute sets of products in desired category
->setAttributeSetFilter($products->getSetIds())
->addStoreLabel(Mage::app()->getStore()->getId());
foreach ($attributes as $attribute) {
// Do things with the attributes
var_dump($attribute->getAttributeCode());
}
MySQL,糟糕!