app/design/frontend/default/mytheme/catalog/product/list.phtml に一連のコードを追加できましたが、別のファイルで「名前」値を作成して簡潔に取得できる方法があるかどうか疑問に思っていました前述のファイルにあります。
すべてのアイテムの名前をハードコーディングする代わりに、各製品の属性から名前を組み合わせて、製品の種類に応じて異なるロジックを使用したいと考えています。
準擬似コード:
$attributes = $product->getAttributes();
// universal attributes:
$manuf = $attributes['manufacturer']->getFrontend()->getValue($product);
$color = $attributes['color']->getFrontend()->getValue($product);
$type = $attributes['product_type']->getFrontend()->getValue($product);
// base name, added to below
$name = $manuf . ' ' . $type . ' in ' . $color;
// then logic for specific types
switch($type) {
case 'baseball hat':
$team = $attributes['team']->getFrontend()->getValue($product);
$name .= ' for ' . $team;
break;
case 'stilts':
$length = $attributes['length']->getFrontend()->getValue($product);
$name .= ' - ' . $length . ' feet long';
break;
}
このロジックはかなり長くなる可能性があるため、すべてを list.phtml に詰め込むべきではないと思います。しかし、どうやってそれを行うにはどうすればよいですか?