显示新产品的3个特定属性(带开始日期)


Display 3 specific attributes on new products(with startdate)

我有一个显示新产品的主页,所以有开始日期的产品。这些都在一个小部件中。问题是他们只显示名称、价格、图片。。。

我想为每个产品显示3个属性,这样用户就可以立即看到产品的一些规格,然后可以点击查看所有细节。

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

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

谢谢。

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

$_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.
        }
      }
    }
  }
}

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