I am showing the manufacturer
attribute in catalog_product_view
page on product/view.phtml
using Code 1 (see below). I successfully included a list of all manufacturer
attributes from Code 2.
-
How to show the result of Code 1 with
href
link as in Code 2, which should redirect to advanced search result and show a list of all products for that selected manufacturer?(OR)
-
How to restrict the results of Code 2 as in Code 1 (Instead of showing all results for manufacturer make it to show only one value as in Code 1)
Code 1
<?php if( $_product->getAttributeText('manufacturer') ): ?>
<p class="manufacturer">Brand:<br/><?php echo $_product->getAttributeText('manufacturer')?></p>
<?php endif; ?>
Example Output of Code 1:
Nike
Code 2
<?php
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
?>
<ul id="manufacturer_list">
<?php foreach ($manufacturers as $manufacturer): ?>
<li><a href="<?php echo Mage::getBaseUrl(); ?>catalogsearch/advanced/result/?manufacturer[]=<?php echo $manufacturer['value'] ?>"><?php echo $_product->getAttributeText('manufacturer')?></a></li>
<?php endforeach; ?>
</ul>
Example Output of Code 2:
<a href="http://127.0.0.1/magento/index.php/catalogsearch/advanced/result/?manufacturer[]=14">Nike</a>,<a href="http://127.0.0.1/magento/index.php/catalogsearch/advanced/result/?manufacturer[]=11">Reebok</a>,<a href="http://127.0.0.1/magento/index.php/catalogsearch/advanced/result/?manufacturer[]=18">Adidas</a>,<a href="http://127.0.0.1/magento/index.php/catalogsearch/advanced/result/?manufacturer[]=17">Etc</a>
I want it like this:
Required Output:
<a href="http://127.0.0.1/magento/index.php/catalogsearch/advanced/result/?manufacturer[]=14">Nike</a>
Like in Amazon:
http://www.amazon.in/s/ref=bl_dp_s_web_976392031?ie=UTF8&node=976392031&field-brandtextbin=Nike
Am using 1.9.2 Rwd theme,Any help would be appreciated..!
Best Answer
You were almost there. This combination of your codes should to the trick:
Note that I used the standard Magento way to construct URLs instead of concatenating base URL, path and query parameters as you did. The result is the same.
What's important is that
$product->getData('manufacturer')
returns the internal value that you need for the link and$product->getAttributeText('manufacturer')
returns the localized frontend value.