1

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.

  1. 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)

  2. 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>

Nike,Reebok,Adidas,Etc

I want it like this:

Required Output:

<a href="http://127.0.0.1/magento/index.php/catalogsearch/advanced/result/?manufacturer[]=14">Nike</a>

Nike

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..!

2

You were almost there. This combination of your codes should to the trick:

<?php if( $_product->getAttributeText('manufacturer') ): ?>
    <p class="manufacturer">
        Brand:<br/>
        <a href="<?php echo Mage::getUrl('catalogsearch/advanced/result', [
            '_query' => ['manufacturer' => $_product->getData('manufacturer')]
        ]) ?>">
            <?php echo $_product->getAttributeText('manufacturer')?>
        </a>
    </p>
<?php endif; ?>

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.

| improve this answer | |
0

you can use http_build_query();
Example:

<?php
$data = array('foo', 'bar', 'baz', 'boom', 'cow' => 'milk', 'php' =>'hypertext processor');

echo http_build_query($data) . "\n";
?>

Output :
foo=bar&baz=boom&cow=milk&php=hypertext+processor
see more

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.