magento产品系列

magento产品系列,magento,Magento,在扩展中,我在目录产品视图页面上看到的产品集合如下所示: if (!$product = Mage::registry('product')) { return new Varien_Data_Collection(); } $category = new Mage_Catalog_Model_Category(); $category->load($product->getCategoryId()); $collection = $category->getProdu

在扩展中,我在目录产品视图页面上看到的产品集合如下所示:

if (!$product = Mage::registry('product')) {
    return new Varien_Data_Collection();
}
$category = new Mage_Catalog_Model_Category();
$category->load($product->getCategoryId());
$collection = $category->getProductCollection();
如何向该集合添加其他属性

例如,我不能得到这样的东西

$collection->addAttributeToSelect('manufacturer');
我希望通过代码添加一些属性(而不是id,因为这可能是在布局中添加的不同属性),然后通过该属性对数据进行分组


thnx

您可以实例化产品集合并对其进行过滤,而不是直接获取特定类别的产品:

if (!$product = Mage::registry('product')) {
    return new Varien_Data_Collection();
}
// get a product collection and filter it by category
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addCategoryFilter($product->getCategoryId());
// add the attributes you need
$collection->addAttributeToSelect('manufacturer');
$collection->setOrder('manufacturer', 'asc');
// load the collection and return it
$collection->load();
return $collection;
小心:加载集合后不能向集合添加属性! 此外,您不必显式地调用
load()
——集合将按需加载


希望这有帮助。

您可以实例化产品集合并对其进行筛选,而不是直接获取特定类别的产品:

if (!$product = Mage::registry('product')) {
    return new Varien_Data_Collection();
}
// get a product collection and filter it by category
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addCategoryFilter($product->getCategoryId());
// add the attributes you need
$collection->addAttributeToSelect('manufacturer');
$collection->setOrder('manufacturer', 'asc');
// load the collection and return it
$collection->load();
return $collection;
小心:加载集合后不能向集合添加属性! 此外,您不必显式地调用
load()
——集合将按需加载

希望这有帮助。

试试这个

<?php echo $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); ?>

试试这个

<?php echo $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); ?>


这将适用于平板电脑,但不适用于我的帐篷,因为我在帐篷下面-我尝试过这个。但是我不能启用平面结构,因为产品和服务器配置有500多个属性不允许这样做。我不确定如果没有平面结构,这是否有效。不管怎样,我想这不是你在禁用flat/服务器太慢时遇到的唯一问题。Magento必须在良好的基础设施上运行。这将适用于平板电脑,但不适用于我的帐篷不足的情况-我尝试过这个。但是我不能启用平面结构,因为产品和服务器配置有500多个属性不允许这样做。我不确定如果没有平面结构,这是否有效。不管怎样,我想这不是你在禁用flat/服务器太慢时遇到的唯一问题。Magento必须在良好的基础设施上运行。