對於每個產品,您都可以檢查它是否屬於某個類別的成員,然後根據關聯數組中的列表檢查並顯示屬性。就像這樣:
$_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.
}
}
}
}
}
這沒有測試,但可能會給你一個想法。您需要添加一些代碼來處理產品可能是列表中多個類別成員的情況。
來源
2013-07-11 12:45:28
DSG
感謝您的回覆。這確實是一個解決方案,但我想編寫一點清潔。因爲一切都需要硬編碼。我認爲最好的方法可能是創建一個帶有額外選項的模塊來顯示新產品。 – Wartodust