Text next to Swatch on Layered navigation
-
27-01-2021 - |
문제
Magento 1.9.3
Is it possible to get the name of the configurable swatch next to the swatch box in the layered navigation? EG.
[ ] White (1)
Currently its just [ ] (1) and you can hover for the name of the swatch.
해결책
Yes, copy the following template file:
/app/design/frontend/rwd/default/template/configurableswatches/catalog/layer/filter/swatches.phtml
To your own theme so that you can modify it:
/app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/configurableswatches/catalog/layer/filter/swatches.phtml
Then add the following line inside the anchor link tags (<a>
) where you'd like to output the swatch label:
<?php echo $_label; ?>
Example (Comment included with added line <!-- -->
):
<li<?php if ($_hasImage){ echo ' style="line-height: ' . $_lineHeight . 'px;"'; } ?>>
<?php if ($_hasItems): ?>
<a href="<?php echo $this->urlEscape($_item->getUrl()) ?>" class="<?php echo $_linkClass ?>">
<?php else: ?>
<span class="<?php echo $_linkClass ?>">
<?php endif; ?>
<span class="swatch-label"<?php if ($_hasImage){ echo ' style="' . $_linkCss . '"'; } ?>>
<?php if ($_hasImage): ?>
<img src="<?php echo $_swatchUrl; ?>" alt="<?php echo $_label; ?>" title="<?php echo $_label ?>" width="<?php echo $_swatchInnerWidth ?>" height="<?php echo $_swatchInnerHeight ?>" />
<span><?php echo $_label; ?></span> <!-- Here is where I am outputting the label of each color swatch -->
<?php else: ?>
<?php echo $_label; ?>
<?php endif; ?>
</span>
<?php if ($this->shouldDisplayProductCount()): ?>
<span class="count">(<?php echo $_item->getCount() ?>)</span>
<?php endif; ?>
<?php if ($_hasItems): ?>
</a>
<?php else: ?>
</span>
<?php endif; ?>
</li>
Once you get the label outputting to the page, you'll likely need to modify CSS styles to make it look good.