gpt4 book ai didi

magento - 获取类别中的产品属性

转载 作者:行者123 更新时间:2023-12-02 01:46:35 24 4
gpt4 key购买 nike

在 Magento 中,有什么方法可以根据产品类别过滤产品属性?实际上,我正在努力构建 Make -> Model -> Year 类型的搜索功能。

这是构建产品属性下拉列表的代码,但我想根据类别过滤属性

$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";

最佳答案

您可以从分层导航 block 中窃取逻辑

// 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,糟糕!

关于magento - 获取类别中的产品属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25330500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com