0

私は新製品を表示するホームページを持っているので、製品には開始日があります。これらはウィジェットにあります。問題は、名前、価格、写真などしか表示されないことです...

製品ごとに 3 つの属性を表示したいので、ユーザーはすぐに製品の仕様を確認し、さらにクリックしてすべての詳細を表示できます。

たとえば、デスクトップにはプロセッサ ファミリ、ハードディスク容量などを表示する必要があります。ラップトップには画面サイズなどを表示する必要があります。

これは可能ですか?問題は、カテゴリが異なるため、テンプレートに 3 つの属性を追加するだけで問題が発生することです。

ありがとう。

4

1 に答える 1

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

これはテストされていませんが、アイデアが得られるかもしれません。製品がリスト内の複数のカテゴリのメンバーである可能性がある場合を処理するには、いくつかのコードを追加する必要があります。

于 2013-07-11T12:45:28.553 に答える