1

I've created attributes that I use successfully in the layered navigation of Magento.

Those attributes get output in the additional data section of the product page, however, attributes used in layered navigation don't appear as links. They're in plain text.

Simple example, I sell CDs, I have an artist attribute. I want to be able to click on the artist name, from the product page additional data section, to access the layered navigation results page that displays CDs only where this artist appears. Logic from a user point of view.

In other words, I want to get the layered navigation link from an attribute, in the product page.

Here’s what I find in catalog/product/view/attributes.html:

<?php foreach ($_additional as $_data): ?>
    <?php echo $this->htmlEscape($this->__($_data['label'])) ?>
    <?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endforeach; ?>

And here's the layered navigation loop:

<?php foreach ($this->getItems() as $_item): ?>

    <?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 endforeach ?>

Thanks much for your help.

tomakun
  • 134
  • 10

1 Answers1

1

If you enter the Artist name as text you can easily integrate it with the Advanced Search like this in catalog/product/view/attributes.html:

<?php if ($_data['label'] == "Artist"): ?>
<a href="/catalogsearch/advanced/result/?artist=<?php echo $_data['value']; ?>">
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></a>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endif; ?>

Let me know if this is what you meant :)

EDIT: Also not that this method only works if you enable your attribute for use in teh advanced search.

Adam Moss
  • 5,582
  • 13
  • 46
  • 64
  • This will filter only by one attribute (artist), it will break current layered navigation filters. – Snowcore Jun 24 '11 at 06:59
  • This code is only meant for the product page, other navigation filters won't even be used? – Adam Moss Jun 24 '11 at 16:14
  • Hi Adam, thanks for the answer and sorry for the lack of feedback on my end. Your code basically works. Although for Multiple Select Attributes, it will return an array, with basically one link that includes all the values in it. I'd like to foreach each value separately with it's own link. Would you have any ideas? – tomakun Nov 21 '11 at 12:43