如何获取Magento类别的所有制造商
我对Magento CMS有这样的问题。我需要检索类别的所有制造商。 乍一看,这不是问题,因为有一个过滤器块和层导航,您可以从中采取必要的方法 首先,我在重新定义的category model如何获取Magento类别的所有制造商,magento,attributes,categories,magento-1.4,Magento,Attributes,Categories,Magento 1.4,我对Magento CMS有这样的问题。我需要检索类别的所有制造商。 乍一看,这不是问题,因为有一个过滤器块和层导航,您可以从中采取必要的方法 首先,我在重新定义的category model/app/code/local/Mage/Catalog/model/category.php public function getManufacturers() { $collection = Mage::getResourceModel('catalog/product_attrib
/app/code/local/Mage/Catalog/model/category.php
public function getManufacturers()
{
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
->setItemObjectClass('catalog/resource_eav_attribute');
$setIds = $this->getProductCollection()->getSetIds();
$collection->getSelect()->distinct(true);
$collection
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection->addIsFilterableFilter();;
$collection->load();
return $collection;
}
我在类别模板中调用此方法:
$manufscturers = $_category->getManufacturers();
所以我们得到了一个巨大的对象Mage\u Catalog\u Model\u Resource\u Eav\u Mysql4\u Product\u Attribute\u Collection
然后:
我们得到objectMage\u Catalog\u Model\u Resource\u Eav\u属性
那我就不知道该怎么办了。那是一条死胡同。也许是走错了路
Magento-1.4.0.1的版本
谢谢你的帮助 据我所知,您已经实现了 不依赖于给定的类别或产品集合 我建议您为给定类别收集产品,如:
$layer = $this->getLayer();
$productCollection = $layer->getProductCollection();
然后遍历它并获得给定类别的所有属性值。
缓存结果。
在magento中也是如此(当然是“magento方式”)据我所知,您已经实现了产品属性集合 不依赖于给定的类别或产品集合 我建议您为给定类别收集产品,如:
$layer = $this->getLayer();
$productCollection = $layer->getProductCollection();
然后遍历它并获得给定类别的所有属性值。
缓存结果。
在magento中也是如此(当然是“magento方式”)以下是您应该如何获得某一类别的所有制造商:
$category = Mage::registry('current_category');
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$manufacturers = array();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'manufacturer') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$manufacturers[$option->getValue()] = $option->getLabel();
}
}
}
var_dump($manufacturers);
希望这有用。干杯 以下是您应该如何获得某一类别的所有制造商:
$category = Mage::registry('current_category');
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$manufacturers = array();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == 'manufacturer') {
$filterBlockName = 'catalog/layer_filter_attribute';
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$manufacturers[$option->getValue()] = $option->getLabel();
}
}
}
var_dump($manufacturers);
希望这有用。干杯 这花了很长时间,但我的回答可能会有帮助 若你们需要在分类页面上获取分类过滤器,你们可能会得到错误的结果 我的代码基于code@MagePsycho
public function getCategoryAttributeFilter($category, $attributeCode)
{
/** @var Mage_Catalog_Model_Layer $layer */
$layer = Mage::getModel('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$request = Mage::app()->getRequest();
Mage::app()->setRequest($newRequest = new Mage_Core_Controller_Request_Http());
$newRequest->setParam($attributeCode, false);
$items = array();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == $attributeCode) {
$filterBlockName = 'catalog/layer_filter_attribute';
/** @var Mage_Catalog_Block_Layer_Filter_Attribute $block */
$block = Mage::app()->getLayout()->createBlock($filterBlockName);
$result = $block->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$manufacturers[$option->getValue()] = $option->getLabel();
}
//$items = $result->getItems();
break;
}
}
Mage::app()->setRequest($request);
Zend_Debug::dump($manufacturers);
return $items;
}
$category = Mage::getModel('catalog/category')->load(/*category id here*/);
$helper->getCategoryAttributeFilter($category, 'brand');
这花了很长时间,但我的回答可能对某人有所帮助 若你们需要在分类页面上获取分类过滤器,你们可能会得到错误的结果 我的代码基于code@MagePsycho
public function getCategoryAttributeFilter($category, $attributeCode)
{
/** @var Mage_Catalog_Model_Layer $layer */
$layer = Mage::getModel('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$request = Mage::app()->getRequest();
Mage::app()->setRequest($newRequest = new Mage_Core_Controller_Request_Http());
$newRequest->setParam($attributeCode, false);
$items = array();
foreach ($attributes as $attribute) {
if ($attribute->getAttributeCode() == $attributeCode) {
$filterBlockName = 'catalog/layer_filter_attribute';
/** @var Mage_Catalog_Block_Layer_Filter_Attribute $block */
$block = Mage::app()->getLayout()->createBlock($filterBlockName);
$result = $block->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
$manufacturers[$option->getValue()] = $option->getLabel();
}
//$items = $result->getItems();
break;
}
}
Mage::app()->setRequest($request);
Zend_Debug::dump($manufacturers);
return $items;
}
$category = Mage::getModel('catalog/category')->load(/*category id here*/);
$helper->getCategoryAttributeFilter($category, 'brand');
如果要在制造商页面中添加分层导航。请将制造商添加为类别,并使用以下magento脚本以编程方式创建类别和分配产品 用于分配产品
$newCategory = array( $list[0] , $list[$key]);
foreach($newproducts as $prod)
{
$prod->setCategoryIds(
array_merge($prod->getCategoryIds(), $newCategory)
);
$prod->save();
}
如果要在制造商页面中添加分层导航。请将制造商添加为类别,并使用以下magento脚本以编程方式创建类别和分配产品 用于分配产品
$newCategory = array( $list[0] , $list[$key]);
foreach($newproducts as $prod)
{
$prod->setCategoryIds(
array_merge($prod->getCategoryIds(), $newCategory)
);
$prod->save();
}
您必须获取所有ID(已具有此属性)和查询属性产品关系我需要使用对象Mage\u Catalog\u Model\u Resource\u Eav\u属性进行此操作?您必须获取所有ID(已具有此属性)和查询属性产品关系我需要使用对象Mage\u Catalog\u Model\u Resource\u Eav\u属性进行此操作?