tags:

views:

182

answers:

2

Hi all,

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 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 takes in a search term and looks in all source files and reports back number of hits. I used this tool and looked for unique strings that appear on the advanced search page. But the text is to be found nowhere!

My next attempt was looking in 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

+2  A: 

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.

benz001
Thank you benz. I will re-read your answer several times to understand it. Currently, I am very naive in Magento and your suggestions are too advanced for me. But I will learn over time and will try some of the tricks you have suggested.
Majid
+1  A: 

The URL's in Magento tell you where the template files are for a certain module.

For example, 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 the advanced folder you will have two files:

1) form.phtml 2) result.phtml

Fishpig
Thank you Fishpig! I found two things with your help -1. The file I was looking for, and2. Why the tool I made failed to find the file - it only checked for .php and .html files!
Majid