在新产品上显示3个特定属性(使用startdate)

时间:2013-07-10 13:32:57

标签: php magento

我有一个主页,显示新产品,所以产品有一个startdate。这些都在一个小部件中。 问题是它们只显示名称,价格,图片......

我想为每个产品显示3个属性,因此用户可以立即看到产品的某些规格,然后可以进一步点击查看所有详细信息。

例如,台式机应具有处理器系列,硬盘容量等。 笔记本电脑应显示屏幕尺寸等。

这可能吗?问题是它们有不同的类别,因此只需将3个属性添加到模板中就会出现问题。

感谢。

1 个答案:

答案 0 :(得分:0)

对于每个产品,您可以检查它是否是某个类别的成员,然后根据关联数组中的列表检查并显示属性。像这样:

$_productsCollection = $this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');

$cats = array(  // keys are category IDs
  1 => array('processor', 'disk', 'ram'),  // attribute codes
  2 => array('screen', 'weight', 'battery')
);

// loop product collection in widget
foreach ($_productsCollection as $_product) {
  // loop array of categories
  foreach ($cat as $cat_id => $attributes) {
    // loop array of attributes if the product is in this category
    if (in_array($cat_id, $_product->getAvailableInCategories())) {
      foreach ($attributes as $attribute) {
        if ($attr = $_product->getData($attribute)) {
          $resource = $_product->getResource();
          // markup and $helper to display image here
          echo $resource->getAttribute($attribute)->getStoreLabel().': '.$attr;
          // markup and getProductUrl() here, etc.
        }
      }
    }
  }
}

这未经过测试,但可能会给你一个想法。您需要添加一些代码来处理产品可能是列表中多个类别的成员的情况。