0

I need to modify 1 line of code in:

  Mage/Catalog/Search/Block/Autocomplete.php

$html .=  '<li title="'.$this->escapeHtml($item['title']).'" class="'.$item['row_class'].'">'
            . '<span class="amount">'.$item['num_of_results'].'</span>'.$this->escapeHtml($item['title']).'</li>'; 

What would be the best approach to do this? Do I need to override the whole controller(Mage/Catalog/Search/controllers/AjaxController.php) that calls this block or is there any simpler way?

It seems to me that creating a module just to override one line is not right.

Thanks :).

  • The question is: What in this line do you want to modify? The HTML or something that comes from $item? – Anna Völkl Nov 12 '14 at 10:36
  • I just want to move <span> to the right of $item['title']. – Alan Nov 12 '14 at 10:41
2

You need to override this block in the local

Step 1: create Yourpackagename_CatalogSearch.xml under app/etc/modules

<?xml version="1.0" ?> 
<config>
    <modules>
        <Yourpackagename_CatalogSearch>
            <active>true</active> 
            <codePool>local</codePool> 
        </Yourpackagename_CatalogSearch>
    </modules>
</config>

Step 2: Now create Yourpackage folder under app/code/local/ and create CatalogSearch folder under Yourpackage.now create etc/config.xml folder under app/code/local/etc/config.xml

<?xml version="1.0" ?> 
  <config>
    <modules>
      <Yourpackagename_CatalogSearch>
        <version>0.0.1</version> 
      </Yourpackagename_CatalogSearch>
    </modules>
    <global>
      <blocks>
        <catalogsearch>
          <rewrite>
            <autocomplete>Yourpackage_CatalogSearch_Block_Autocomplete</autocomplete>
          </rewrite>
        </catalogsearch>
      </blocks>
    </global>
  </config>

Step 3: Now create Autocomplete.php under the app/code/local/Yourpackage/CatalogSearch/Block/ with the following code

<?php
    class Yourpackage_CatalogSearch_Block_Autocomplete extends Mage_CatalogSearch_Block_Autocomplete
    {
        protected function _toHtml(){
            // u can add ur code changes here
        }
    }
  • Thanks for the extensive explanation :)! This seems to be the only 'best-practice' way. – Alan Nov 12 '14 at 11:03

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.