Question

I have been struggling with a stupid situation. A customer has asked me to alter his 'advanced search' page to add a few options. The URL of this page is like http://www.domainname.com/index.php/catalogsearch/advanced/

This is a Magento store and I have no experience with this framework. I tried to learn it but found the learning curve too steep to gain enough knowledge to finish the project on-time.

So I first made a small PHP tool that searches in all source files for a search term and reports back te number of hits. I used this tool to look for unique strings that appear on the advanced search page. But the text is nowhere to be found!

My next attempt was looking at the database to find the string. So I exported all DB data and copied the resulting queries into my code editor and searched again, and found nothing!

This is very awkward and is driving me mad. I cannot find the block of code that outputs the advanced search options!

'ANY' help would be MUCH appreciated.

Thanks, Majid

Was it helpful?

Solution

The URLs in Magento tell you where the template files are for a certain module.

For example, when you're looking for catalogsearch/advanced/, all template files are location in app/design/frontend/default/your-theme/.

Look inside that folder and it should be obvious. You will have a folder called catalogsearch and inside that a folder called advanced; inside which there are two files:

  • form.phtml
  • result.phtml

OTHER TIPS

So far I've been using the following tactics on a local dev box - don't try this on a live store obviously!:

  1. Turn on Template Path Hints + Block Names in System -> Config -> Developer. This will get you to the phtml file that does the final render and also the block object type that it uses. Unless you've IP limited this, every visitor will see these!
  2. Then in the phtml files to dig further you can easily Zend_Debug::dump($var) to inspect the variable/object in question and find the object type etc.
  3. Search in your editor or grep through /app/code directories to find which files define the object type you've just found - although as it based on Zend the correct file path can be worked out most of the time from the object class.

Also

  • A handy trick is to deliberately insert an error in a php/phtml file, Magento gives you a nicely formatted error screen with a call stack which is interesting reading
  • echo() statements in the core files normally work pretty well, in the Magento set up they don't normally trigger the html headers to be sent at the wrong time
  • Use an IDE like Netbeans/Eclipse/Zend studio etc and put all the Magento code into your project, the resulting phpdoc information, 'open declaration' and code assist will save you hours of searching
  • Spend the time to get Xdebug working on your test server with an IDE that allows you to make use of it. The easiest one I've found to setup from scratch (on a Mac) is a local Mamp install with Netbeans as the IDE - the Netbeans site will walk you through this, once you've got this working well you can forget about most of the other tricks!

These are just the things I've tried so far - more suggestions please! I've still not found a technique to debug config problems from XML issues in the multitude of XML files that Magento uses, problems here tend to fail silently and are really hard to track down as a result + the xml documentation is awful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top