[原创]替换magento左列的颜色列表为图标样式。

发布时间:2010-05-12

默认的是black,white,red 这样的文字列表。通过下面的方法,可以改成相对应的颜色值图标。

修改 app\design\frontend\base\default\template\catalog\layer\filter.phtml 文件

<?php
/**
 * Template for filter items block
 *
 * @see Mage_Catalog_Block_Layer_Filter
 */
$i = 0;
?>

<ol>
<?php foreach ($this->getItems() as $_item): ?>
  <?php
  /* author:dmh begin */
  ?>
  <?php if ($this->__($_item->getName()) == 'Color' && $_item->getCount() > 0): ?>
  <?php if ($_item->getValue() == '24'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/black.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '25'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/blue.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '26'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/red.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '59'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/brown.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '61'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/gray.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '22'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/green.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '58'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/magenta.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '57'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/pink.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '23'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/silver.png') ?>" /></a>
  <?php elseif ($_item->getValue() == '60'): ?>
  <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><img src="<?php echo $this->getSkinUrl('images/catalog/product/color/white.png') ?>" /></a>
  <?php endif; ?>
  <?php elseif ($this->__($_item->getName()) == 'Brand'): ?>
  <?php if ($i == 0) echo "<div style='height:120px;overflow-y:auto;'>"; ?>
  <li>
        <?php if ($_item->getCount() > 0): ?>
        <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
        <?php else: echo $_item->getLabel() ?>
        <?php endif; ?>
        (<?php echo $_item->getCount() ?>)
    </li>
  <?php if ($i+1 == count($this->getItems())) echo '</div>'; ?>
  <?php else: ?>
  <?php
  /* author:dmh middle */
  ?>
    <li>
        <?php if ($_item->getCount() > 0): ?>
        <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
        <?php else: echo $_item->getLabel() ?>
        <?php endif; ?>
        (<?php echo $_item->getCount() ?>)
    </li>
    <?php endif; ?>
    <?php
  /* author:dmh end */
  $i++;
  ?>
<?php endforeach ?>
</ol>