<?xml version='1.0' encoding='utf-8' ?>
<feed xmlns='http://www.w3.org/2005/Atom'>
  <title type='text'>ginger leprechaun</title>
  <generator uri='http://effectif.com/nesta'>Nesta</generator>
  <id>tag:www.gingerleprechaun.com,2009:/</id>
  <link href='http://www.gingerleprechaun.com/articles.xml' rel='self' />
  <link href='http://www.gingerleprechaun.com' rel='alternate' />
  <subtitle type='text'>Barry Keenan's notes on Ruby, PHP, JavaScript and Web Development.</subtitle>
  <updated>2011-03-10T20:49:26+13:00</updated>
  <author>
    <name>Barry Keenan</name>
    <uri>http://www.gingerleprechaun.com</uri>
    <email>me@keeny.co.uk</email>
  </author>
  <entry>
    <title>Integrate Magento and Silverstripe autoloaders</title>
    <link href='http://www.gingerleprechaun.com/magento/integrate-magento-silverstripe-autoloaders' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2011-03-10:/magento/integrate-magento-silverstripe-autoloaders</id>
    <content type='html'>
      &lt;p&gt;When you try to include the Magento &lt;code&gt;Mage&lt;/code&gt; class in your SilverStripe project, Magento will try to load classes that have already been loaded by SilverStripe&amp;#8217;s &lt;code&gt;__autoload()&lt;/code&gt; method. (bleh, try saying that 3 times fast ;)&lt;/p&gt;
      
      &lt;p&gt;What I did was really hacky&amp;#8230; Magento is really well namespaced, so I just gave it&amp;#8217;s autoloader a list of classes that it was allowed to load. Anything else is handled by SilverStripe&amp;#8217;s autoloader.&lt;/p&gt;
      
      &lt;p&gt;Change &lt;code&gt;store/lib/Varien/Autoload.php&lt;/code&gt; [line 80-ish] from this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;/**&amp;#x000A; * Load class source code&amp;#x000A; *&amp;#x000A; * @param string $class&amp;#x000A; */&amp;#x000A;public function autoload($class)&amp;#x000A;{&amp;#x000A;    if ($this-&amp;gt;_collectClasses) {&amp;#x000A;        $this-&amp;gt;_arrLoadedClasses[self::$_scope][] = $class;&amp;#x000A;    }&amp;#x000A;    if ($this-&amp;gt;_isIncludePathDefined) {&amp;#x000A;        $classFile = $class;&amp;#x000A;    } else {&amp;#x000A;        $classFile = str_replace(&amp;#39; &amp;#39;, DIRECTORY_SEPARATOR, ucwords(str_replace(&amp;#39;_&amp;#39;, &amp;#39; &amp;#39;, $class)));&amp;#x000A;    }&amp;#x000A;    $classFile.= &amp;#39;.php&amp;#39;;&amp;#x000A;    return include $classFile;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;to this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;/**&amp;#x000A; * Load class source code&amp;#x000A; *&amp;#x000A; * @param string $class&amp;#x000A; */&amp;#x000A;public function autoload($class)&amp;#x000A;{	&amp;#x000A;	if ( $this-&amp;gt;is_magento_class($class) ) {&amp;#x000A;		if ($this-&amp;gt;_collectClasses) {&amp;#x000A;			$this-&amp;gt;_arrLoadedClasses[self::$_scope][] = $class;&amp;#x000A;		}&amp;#x000A;		if ($this-&amp;gt;_isIncludePathDefined) {&amp;#x000A;			$classFile = $class;&amp;#x000A;		} else {&amp;#x000A;			$classFile = str_replace(&amp;#39; &amp;#39;, DIRECTORY_SEPARATOR, ucwords(str_replace(&amp;#39;_&amp;#39;, &amp;#39; &amp;#39;, $class)));&amp;#x000A;		}&amp;#x000A;		$classFile.= &amp;#39;.php&amp;#39;;&amp;#x000A;		return include $classFile;	&amp;#x000A;	}&amp;#x000A;}&amp;#x000A;&amp;#x000A;/**&amp;#x000A; * You need to manually maintain this list of classes - if you install a module for example&amp;#x000A; */&amp;#x000A;private function is_magento_class($className) {&amp;#x000A;	$namespaces = array(&amp;#39;Zend&amp;#39;, &amp;#39;Varien&amp;#39;, &amp;#39;Mage&amp;#39;, &amp;#39;other&amp;#39;, &amp;#39;3rd party&amp;#39;, &amp;#39;modules&amp;#39;);&amp;#x000A;&amp;#x000A;	$is_mage_class = false;&amp;#x000A;	foreach($namespaces as $namespace) {&amp;#x000A;		if( strpos($className, $namespace) !== false) {&amp;#x000A;			$is_mage_class = true;&amp;#x000A;		}&amp;#x000A;	}&amp;#x000A;&amp;#x000A;	return $is_mage_class;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Obviously this is ridiculously hacky and I did it this way cause I was running out of time to get a specific project working.&lt;/p&gt;
      
      &lt;p&gt;Maybe someone clever out there could devise some way of dynamically getting Magento&amp;#8217;s classes? Or maybe do it on the silverstripe end - silverstripe maintains a manifest of its classes. something like that&amp;#8230;&lt;/p&gt;
    </content>
    <published>2011-03-10T20:49:26+13:00</published>
    <updated>2011-03-10T20:49:26+13:00</updated>
    <category term='magento'></category>
    <category term='silverstripe'></category>
  </entry>
  <entry>
    <title>Integrate SilverStripe menu to display on Magento pages</title>
    <link href='http://www.gingerleprechaun.com/magento/silverstripe-menu-in-magento' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-12-01:/magento/silverstripe-menu-in-magento</id>
    <content type='html'>
      &lt;h2 id='expose_silverstripe_menu_using_restful_server'&gt;Expose SilverStripe menu using RESTful Server&lt;/h2&gt;
      
      &lt;p&gt;First we need to get SilverStripe to output a JSON representation of the pages in our site. I did this by creating a &lt;code&gt;REST&lt;/code&gt; class. The idea is to have one place to put any functions for access over REST. That way you know where everything is, and can control security better.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;/**&amp;#x000A; * RESTful Server to expose certain SilverStripe data to Magento&amp;#x000A; * e.g. menus, etc.&amp;#x000A; *&amp;#x000A; * @package default&amp;#x000A; * @author Barry Keenan&amp;#x000A; */&amp;#x000A;class REST extends DataObject {&amp;#x000A;&amp;#x000A;	static $db = array(&amp;#x000A;	);&amp;#x000A;&amp;#x000A;	static $api_access = true;&amp;#x000A;&amp;#x000A;	// important - must explicity allow the actions we want to access over REST&amp;#x000A;	static $allowed_actions = array(&amp;#x000A;		&amp;#39;TopMenu&amp;#39;&amp;#x000A;	);&amp;#x000A;&amp;#x000A;	function canEdit() { return true; }&amp;#x000A;	function canView() { return true; }&amp;#x000A;	function canCreate() { return true; }&amp;#x000A;&amp;#x000A;&amp;#x000A;	// return second teir navigation pages&amp;#x000A;	function TopMenu() {&amp;#x000A;		$base_url = &amp;quot;http://&amp;quot; . $_SERVER[&amp;#39;SERVER_NAME&amp;#39;] . &amp;quot;/&amp;quot;;&amp;#x000A;	&amp;#x000A;		$whereStatement = &amp;quot;ShowInMenus = 1&amp;quot;;&amp;#x000A;		$pages = DataObject::get(&amp;quot;Page&amp;quot;, $whereStatement);&amp;#x000A;	&amp;#x000A;		$nav = array();&amp;#x000A;		foreach($pages as $page) {&amp;#x000A;			$nav[] = array(&amp;#x000A;				&amp;#39;menuTitle&amp;#39; =&amp;gt; $page-&amp;gt;MenuTitle,&amp;#x000A;				&amp;#39;url&amp;#39; =&amp;gt; $base_url . $page-&amp;gt;URLSegment&amp;#x000A;			);&amp;#x000A;		}&amp;#x000A;	&amp;#x000A;		echo json_encode($nav);&amp;#x000A;		die();&amp;#x000A;	}&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;You need to manually add a &lt;code&gt;REST&lt;/code&gt; record to the database. And then you&amp;#8217;ll be able to access it at URLs like this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;http://localhost/api/v1/REST/1/&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;You can see that I&amp;#8217;m accessing my one and only &lt;code&gt;REST&lt;/code&gt; object using the id &lt;code&gt;1&lt;/code&gt;. A great little tool for testing your RESTful URLs is &lt;a href='http://ditchnet.org/httpclient/'&gt;HTTP Client&lt;/a&gt;. If you use HTTP CLient to POST an empty string to this address:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;http://localhost/api/v1/REST/1/TopMenu&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;You should get the following (example) data back from SilverStripe:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::json&amp;#x000A;[{&amp;quot;menuTitle&amp;quot;:&amp;quot;home&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;localhost\/home&amp;quot;},{&amp;quot;menuTitle&amp;quot;:&amp;quot;store&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;localhost\/store&amp;quot;},{&amp;quot;menuTitle&amp;quot;:&amp;quot;about&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;localhost\/about&amp;quot;},{&amp;quot;menuTitle&amp;quot;:&amp;quot;faq&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;localhost\/faq&amp;quot;},{&amp;quot;menuTitle&amp;quot;:&amp;quot;contact&amp;quot;,&amp;quot;url&amp;quot;:&amp;quot;localhost\/contact&amp;quot;}]&lt;/code&gt;&lt;/pre&gt;
      
      &lt;h2 id='write_a_magento_module_to_grab_the_silverstripe_data'&gt;Write a Magento module to grab the SilverStripe data&lt;/h2&gt;
      
      &lt;p&gt;So now we can get the data we need by simply posting to the above URL. Great :)&lt;/p&gt;
      
      &lt;p&gt;All we need to do is write a custom magento module that grabs this data. (I intend to write a guide that details how to do this fairly soon(ish) ;) ) &lt;!-- If you need to get started with writing you own Magento module see this guide. --&gt;&lt;/p&gt;
      
      &lt;p&gt;I&amp;#8217;ll be using &lt;a href='http://www.gen-x-design.com/archives/making-restful-requests-in-php/'&gt;Gen X Design&amp;#8217;s&lt;/a&gt; &lt;a href='http://www.gen-x-design.com/wp-content/uploads/2009/05/restrequestincphp1.zip'&gt;excellent REST class&lt;/a&gt; to make my requests. I&amp;#8217;m not completely sure if I&amp;#8217;ve got the Magento concepts correct yet, but my &amp;#8216;controller&amp;#8217; looks like this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;/**&amp;#x000A;* Display menu items from JSON source. In this case Silverstripe&amp;#x000A;*&amp;#x000A;* @codepool   Local&amp;#x000A;* @category   Craft&amp;#x000A;* @package    Craft_Silverstripe&amp;#x000A;* @module     Silverstripe&amp;#x000A;*/&amp;#x000A;&amp;#x000A;require (&amp;#39;RestRequest.inc.php&amp;#39;);&amp;#x000A;&amp;#x000A;class Craft_Silverstripe_Block_Navigation extends Mage_Core_Block_Template {&amp;#x000A;&amp;#x000A;	protected $base_url = &amp;#39;http://localhost/api/v1/REST&amp;#39;;&amp;#x000A;&amp;#x000A;	public function menuItems() {&amp;#x000A;&amp;#x000A;		$request_data = array();&amp;#x000A;		$request = new RestRequest($this-&amp;gt;base_url . &amp;#39;/1/TopMenu&amp;#39;, &amp;#39;POST&amp;#39;, $request_data);&amp;#x000A;&amp;#x000A;		// Is auth required??&amp;#x000A;		// $request-&amp;gt;setUsername (&amp;#39;user&amp;#39;);&amp;#x000A;		// $request-&amp;gt;setPassword (&amp;#39;pass&amp;#39;);&amp;#x000A;		$request-&amp;gt;execute();&amp;#x000A;&amp;#x000A;		// this will be an array of stdClass Objects&amp;#x000A;		$items_json = json_decode($request-&amp;gt;getResponseBody());&amp;#x000A;&amp;#x000A;		// Mage::log($items_json);&amp;#x000A;&amp;#x000A;		return $items_json;&amp;#x000A;	}&amp;#x000A;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;So we have our &amp;#8216;controller&amp;#8217; We also need a &amp;#8216;view&amp;#8217; to display our menu:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;&amp;lt;ul id=&amp;quot;nav_top&amp;quot;&amp;gt;&amp;#x000A;&amp;lt;?php foreach($this-&amp;gt;menuItems() as $page) { ?&amp;gt;&amp;#x000A;	&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&amp;lt;?php echo $page-&amp;gt;url ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;?php echo $page-&amp;gt;menuTitle ?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;#x000A;&amp;lt;?php } ?&amp;gt;&amp;#x000A;&amp;lt;/ul&amp;gt;&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;All you need to do now, is tell Magento about this block in your &lt;code&gt;page.xml&lt;/code&gt; configuration using something like this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::xml&amp;#x000A;&amp;lt;block type=&amp;quot;craft_silverstripe/navigation&amp;quot; name=&amp;quot;silverstripe.navigation&amp;quot; as=&amp;quot;ssNav&amp;quot; template=&amp;quot;silverstripe/navigation/view.phtml&amp;quot;/&amp;gt;&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And then actually call the block, defined above, in your templates using this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;&amp;lt;?php echo $this-&amp;gt;getChildHtml(&amp;#39;ssNav&amp;#39;) ?&amp;gt;&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Hey presto! SilverStripe menu in Magento :)&lt;/p&gt;
    </content>
    <published>2010-12-01T13:25:43+13:00</published>
    <updated>2010-12-01T13:25:43+13:00</updated>
    <category term='magento'></category>
    <category term='silverstripe'></category>
  </entry>
  <entry>
    <title>Integrate Magento categories menu with Silverstripe</title>
    <link href='http://www.gingerleprechaun.com/magento/magento-menu-silverstripe-integration' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-11-22:/magento/magento-menu-silverstripe-integration</id>
    <content type='html'>
      &lt;p&gt;In my case I&amp;#8217;m integrating with Silverstripe, but I&amp;#8217;m sure you could adapt the &lt;code&gt;Mage&lt;/code&gt; calls to your CMS of choice.&lt;/p&gt;
      
      &lt;p&gt;In my setup I have SilverStripe installed in the root directory, and I have Magento installed in the sub directory &lt;code&gt;store&lt;/code&gt;.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;public_html/&amp;#x000A;	silverstripe folder/&amp;#x000A;	silverstripe folder/&amp;#x000A;	..&amp;#x000A;	store/&amp;#x000A;		magento folder/&amp;#x000A;		magento folder/&amp;#x000A;		..&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;I want to be able to use Magento&amp;#8217;s categories as my main menu everywhere on the site and that means I need to access Magento data outside of it&amp;#8217;s install directory.&lt;/p&gt;
      
      &lt;h2 id='initialse_the_mage_object'&gt;Initialse the Mage object&lt;/h2&gt;
      
      &lt;p&gt;In &lt;code&gt;mysite/code/Page.php&lt;/code&gt; we need to initialise the &lt;code&gt;Mage&lt;/code&gt; object.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;class Page_Controller extends ContentController {&amp;#x000A;&amp;#x000A;	public function init() {&amp;#x000A;		parent::init();&amp;#x000A;&amp;#x000A;		...	&amp;#x000A;&amp;#x000A;		// docroot&amp;#x000A;		$site_path = realpath(dirname(__FILE__) . &amp;#39;/../..&amp;#39; );&amp;#x000A;	&amp;#x000A;		// initialise Magento connection&amp;#x000A;		require_once &amp;quot;$site_path/store/app/Mage.php&amp;quot;;&amp;#x000A;		Mage::app(&amp;#39;default&amp;#39;);&amp;#x000A;	}&amp;#x000A;	&amp;#x000A;	...&amp;#x000A;	&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;We can now make calls to &lt;code&gt;Mage&lt;/code&gt; elsewhere in our Page class, in order to pull data from Magento. The best way to access and manipulate data in Magento is by using the &lt;code&gt;Mage&lt;/code&gt; object&amp;#8217;s functions. For example: &lt;code&gt;getModel()&lt;/code&gt; and &lt;code&gt;getHelper()&lt;/code&gt;. Refer to my &lt;a href='http://www.gingerleprechaun.com/magento/magento-code-cheatsheet'&gt;Magento code cheatsheet&lt;/a&gt; for further info.&lt;/p&gt;
      
      &lt;h2 id='mapping_magento_categories_to_silverstripe_pages'&gt;Mapping Magento categories to SilverStripe pages&lt;/h2&gt;
      
      &lt;p&gt;I want to use Magento&amp;#8217;s categories as my main menu, so I just went ahead and overrode SilverStripe&amp;#8217;s &lt;code&gt;getMenu()&lt;/code&gt; function. You may not want such extreme behaviour, so put the code in a different function if you wish.&lt;/p&gt;
      
      &lt;p&gt;In my case I added another function &lt;code&gt;TopMenu()&lt;/code&gt;, so I could actually access my SilverStripe pages.&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;class Page_Controller extends ContentController {&amp;#x000A;&amp;#x000A;	...&amp;#x000A;&amp;#x000A;	/**&amp;#x000A;	 * Overrides ContentController&amp;#x000A;	 *&amp;#x000A;	 * Use Magento categories rather than Silverstripe menus&amp;#x000A;	 * @return DataObjectSet&amp;#x000A;	 */&amp;#x000A;	public function getMenu($level = 1) {&amp;#x000A;&amp;#x000A;		// TODO: control levels. e.g. for sub categories&amp;#x000A;&amp;#x000A;		$cat_helper = Mage::helper(&amp;#39;catalog/category&amp;#39;); // get the magento category helper&amp;#x000A;		$categories = $cat_helper-&amp;gt;getStoreCategories(); // get top level categories&amp;#x000A;&amp;#x000A;		$pages = new DataObjectSet();&amp;#x000A; 		if(isset($categories)) {&amp;#x000A;			foreach($categories as $category) {				&amp;#x000A;				// Map magento &amp;#39;Category&amp;#39; to a silverstripe &amp;#39;Page&amp;#39; model &amp;#x000A;				$pages-&amp;gt;push( new Page( array(&amp;#x000A;					&amp;#39;Title&amp;#39; =&amp;gt; $category-&amp;gt;getName(),&amp;#x000A;					&amp;#39;MenuTitle&amp;#39; =&amp;gt; $category-&amp;gt;getName(),&amp;#x000A;					&amp;#39;URLSegment&amp;#39; =&amp;gt; &amp;#39;/store/&amp;#39; . $category-&amp;gt;getUrlKey() // I want all URLs to have a /store/ prefix&amp;#x000A;				)));&amp;#x000A;			}&amp;#x000A;		}&amp;#x000A;&amp;#x000A;		return $pages;&amp;#x000A;	}&amp;#x000A;&amp;#x000A;	// return second teir navigation pages&amp;#x000A;	function TopMenu() {&amp;#x000A;		$whereStatement = &amp;quot;ShowInMenus = 1&amp;quot;;&amp;#x000A;		return DataObject::get(&amp;quot;Page&amp;quot;, $whereStatement);		&amp;#x000A;	}&amp;#x000A;	&amp;#x000A;	...&amp;#x000A;	&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;h2 id='nice_clean_templates'&gt;Nice clean templates&lt;/h2&gt;
      
      &lt;p&gt;In my SilverStripe templates I can now do this :-D&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::html&amp;#x000A;&amp;lt;!-- SilverStripe menu --&amp;gt;&amp;#x000A;&amp;lt;ul id=&amp;quot;nav_top&amp;quot; class=&amp;quot;nav clearfix&amp;quot;&amp;gt;&amp;#x000A;	&amp;lt;% control TopMenu %&amp;gt;	  &amp;#x000A;		&amp;lt;li class=&amp;quot;$LinkingMode&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;$Link&amp;quot; title=&amp;quot;Go to the $Title.XML page&amp;quot;&amp;gt;$MenuTitle.XML&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;#x000A;	&amp;lt;% end_control %&amp;gt;&amp;#x000A;&amp;lt;/ul&amp;gt;&amp;#x000A;&amp;#x000A;&amp;lt;!-- Magento categories menu --&amp;gt;&amp;#x000A;&amp;lt;ul id=&amp;quot;nav_main&amp;quot; class=&amp;quot;nav clearfix&amp;quot;&amp;gt;&amp;#x000A;	&amp;lt;% control Menu(1) %&amp;gt;	  &amp;#x000A;		&amp;lt;li class=&amp;quot;$LinkingMode&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;$Link&amp;quot; title=&amp;quot;Go to the $Title.XML page&amp;quot;&amp;gt;$MenuTitle.XML&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;#x000A;	&amp;lt;% end_control %&amp;gt;&amp;#x000A;&amp;lt;/ul&amp;gt;&lt;/code&gt;&lt;/pre&gt;
    </content>
    <published>2010-11-22T13:44:22+13:00</published>
    <updated>2010-11-22T13:44:22+13:00</updated>
    <category term='magento'></category>
    <category term='silverstripe'></category>
  </entry>
  <entry>
    <title>Magento code cheatsheet</title>
    <link href='http://www.gingerleprechaun.com/magento/magento-code-cheatsheet' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-11-22:/magento/magento-code-cheatsheet</id>
    <content type='html'>
      &lt;p&gt;This is blatantly stolen from &lt;a href='http://www.sycha.com/magento-database-models-helpers-raw-sql-queries'&gt;sycha.com&lt;/a&gt; for my reference&amp;#8230;&lt;/p&gt;
      
      &lt;h2 id='magento_database_models'&gt;Magento Database Models&lt;/h2&gt;
      
      &lt;p&gt;The best way to access and manipulate data in Magento is by using the provided objects and their associated functionality.. For example, you can get a Magento category model like this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;$model_category = Mage::getModel(&amp;#39;catalog/category&amp;#39;);&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;With your category model you now retrieve data e.g. get all child categories of category ID 2 and echo the name&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;$model_category = Mage::getModel(&amp;#39;catalog/category&amp;#39;);&amp;#x000A;foreach ($model_category-&amp;gt;getCategories($id=2) as $category) {&amp;#x000A;	echo $category-&amp;gt;getName();&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Refer to the API documentation to see what methods are available.&lt;/p&gt;
      
      &lt;h2 id='magento_helper_classes'&gt;Magento Helper Classes&lt;/h2&gt;
      
      &lt;p&gt;Magento has helper classes which are pretty handy also. For example, you can get a Magento category helper like this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;$helper = Mage::helper(&amp;#39;catalog/category&amp;#39;);&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Your helper will have a bunch of methods defined for performing common tasks. For example, you can get all your stores top level categories as follows:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::php&amp;#x000A;$helper = Mage::helper(&amp;#39;catalog/category&amp;#39;);&amp;#x000A;foreach ($helper-&amp;gt;getStoreCategories() as $category) {&amp;#x000A;	echo $category-&amp;gt;getName();&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Check this file to see what methods are available in the catalog category helper: magento/app/code/core/Mage/Catalog/Helper/Category.php&lt;/p&gt;
      
      &lt;blockquote&gt;
      &lt;p&gt;References: &lt;a href='http://www.sycha.com/magento-database-models-helpers-raw-sql-queries'&gt;Magento Database Models, Helpers and Raw SQL Queries&lt;/a&gt;&lt;/p&gt;
      &lt;/blockquote&gt;
    </content>
    <published>2010-11-22T13:44:22+13:00</published>
    <updated>2010-11-22T13:44:22+13:00</updated>
    <category term='magento'></category>
  </entry>
  <entry>
    <title>Adding additional gems to nesta</title>
    <link href='http://www.gingerleprechaun.com/nesta/customising-nesta-adding-gems' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-10-17:/nesta/customising-nesta-adding-gems</id>
    <content type='html'>
      &lt;p&gt;It&amp;#8217;s worth noting for the newbies that nesta uses &lt;a href='http://gembundler.com/'&gt;bundler&lt;/a&gt;, so you need to explicitly add gems to your &lt;code&gt;Gemfile&lt;/code&gt; or you won&amp;#8217;t be able to require them. I was getting&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;no such file to load --&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;from passenger using RVM. With excellent help from &lt;a href='http://blog.ninjahideout.com/about-me'&gt;sutto&lt;/a&gt; on &lt;a href='irc://freenode/rvm'&gt;irc://freenode/rvm&lt;/a&gt;, I did two things:&lt;/p&gt;
      
      &lt;ol&gt;
      &lt;li&gt;Made sure I had the files &lt;code&gt;.rvmrc&lt;/code&gt; and &lt;code&gt;config/setup_load_paths.rb&lt;/code&gt; to correctly set my gem path.&lt;/li&gt;
      
      &lt;li&gt;Added the additional gems I wanted to use, to &lt;code&gt;Gemfile&lt;/code&gt; in my nesta install.&lt;/li&gt;
      &lt;/ol&gt;
      
      &lt;p&gt;So in my case, my &lt;code&gt;Gemfile&lt;/code&gt; now starts like this:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::ruby&amp;#x000A;source :gemcutter&amp;#x000A;&amp;#x000A;gem &amp;quot;builder&amp;quot;, &amp;quot;2.1.2&amp;quot;&amp;#x000A;gem &amp;quot;haml&amp;quot;, &amp;quot;3.0.12&amp;quot;&amp;#x000A;gem &amp;quot;maruku&amp;quot;, &amp;quot;0.6.0&amp;quot;&amp;#x000A;gem &amp;quot;RedCloth&amp;quot;, &amp;quot;4.2.2&amp;quot;&amp;#x000A;gem &amp;quot;sinatra&amp;quot;, &amp;quot;1.0&amp;quot;&amp;#x000A;# I want to be able to require these aswell...&amp;#x000A;gem &amp;quot;rack-funky-cache&amp;quot;, &amp;quot;0.0.3&amp;quot;&amp;#x000A;gem &amp;quot;coderay&amp;quot;, &amp;quot;0.9.5&amp;quot;&amp;#x000A;gem &amp;quot;rack-codehighlighter&amp;quot;, &amp;quot;0.4.7&amp;quot;&amp;#x000A;&amp;#x000A;...&lt;/code&gt;&lt;/pre&gt;
      
      &lt;blockquote&gt;
      &lt;p&gt;References:&lt;br /&gt;&lt;a href='http://blog.ninjahideout.com/posts/the-path-to-better-rvm-and-passenger-integration'&gt;The Path to Better RVM &amp;amp; Passenger Integration&lt;/a&gt;&lt;br /&gt;&lt;a href='http://blog.ninjahideout.com/posts/a-guide-to-a-nginx-passenger-and-rvm-server'&gt;A Guide to a Nginx, Passenger and RVM Server&lt;/a&gt;&lt;/p&gt;
      &lt;/blockquote&gt;
    </content>
    <published>2010-10-17T23:34:52+12:00</published>
    <updated>2010-10-17T23:34:52+12:00</updated>
    <category term='nesta'></category>
  </entry>
  <entry>
    <title>Debugging to stdout with Ruby 1.9.2p0</title>
    <link href='http://www.gingerleprechaun.com/ruby/debugging-to-stdout-with-ruby-1.9.2p0' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-10-10:/ruby/debugging-to-stdout-with-ruby-1.9.2p0</id>
    <content type='html'>
      &lt;p&gt;For the life of me I could not figure out why the most simple of simplest tasks to write &lt;code&gt;foo&lt;/code&gt; to a file would not work using the following:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;:::ruby&amp;#x000A;log = File.new(&amp;quot;help.log&amp;quot;, &amp;quot;a+&amp;quot;)&amp;#x000A;$stdout.reopen(log)&amp;#x000A;&amp;#x000A;require &amp;quot;sinatra&amp;quot;&amp;#x000A;&amp;#x000A;helpers do&amp;#x000A;  def set_common_variables&amp;#x000A;    puts &amp;quot;more log output&amp;quot;&amp;#x000A;  end&amp;#x000A;end&amp;#x000A;&amp;#x000A;get &amp;quot;/&amp;quot; do&amp;#x000A;  set_common_variables&amp;#x000A;&amp;#x000A;  puts &amp;quot;some log output&amp;quot;&amp;#x000A;&amp;#x000A;  &amp;quot;browser output&amp;quot;&amp;#x000A;end&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Turns out with Ruby 1.9.2 I needed to do &lt;code&gt;$stdout.flush&lt;/code&gt; after every &lt;code&gt;puts&lt;/code&gt;, or do &lt;code&gt;$stdout.sync = true&lt;/code&gt; which &lt;em&gt;should&lt;/em&gt; be the default behaviour. This is not an issue in other versions of Ruby.&lt;/p&gt;
    </content>
    <published>2010-10-10T15:03:30+12:00</published>
    <updated>2010-10-10T15:03:30+12:00</updated>
    <category term='ruby'></category>
    <category term='sysadmin'></category>
  </entry>
  <entry>
    <title>Ebola and outsourcing your comment system</title>
    <link href='http://www.gingerleprechaun.com/blog_commenting_with_twitter' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-10-09:/blog_commenting_with_twitter</id>
    <content type='html'>
      &lt;p&gt;Happy Cog (I heart Happy Cog) recently launched a blog, &lt;a href='http://cognition.happycog.com/article/is-this-thing-on'&gt;Cognition&lt;/a&gt;.&lt;/p&gt;
      
      &lt;blockquote&gt;
      &lt;p&gt;Speaking of experiments, there’s our comments section. &lt;span&gt;W&lt;/span&gt;e’ve collocated our comments on Twitter. Share a tweet-length response here, and, with your permission, it will go there. If you are moved to respond with more than 140 characters, post the response on your website, and it will show up here.&lt;/p&gt;
      &lt;/blockquote&gt;
      
      &lt;p&gt;Yeah-yeah, so I &amp;#8216;get it&amp;#8217; that you can either say something quick and that perhaps something more involved belongs in it&amp;#8217;s own space, so you don&amp;#8217;t look like the-guy-that&amp;#8217;s-been-blabbering-at-the-pub-table-for-10minutes-without-letting-anyone-else-get-a-word-in-edgeways&amp;#8230;.&lt;/p&gt;
      
      &lt;p&gt;But what about the mid-level discussion, that you can&amp;#8217;t squeeze into 140chars, but that doesn&amp;#8217;t warrant it&amp;#8217;s own blog post? This often happens on technical blogs when discussing code. I mean&amp;#8230; often blogs are full of half realised brain-farts as it is, without making them home&amp;#8217;s for snippets of conversation without the context.&lt;/p&gt;
      
      &lt;p&gt;Perhaps we should do as &lt;a href='http://giles.tumblr.com/'&gt;Giles&lt;/a&gt; does and&amp;#8230;&lt;/p&gt;
      
      &lt;blockquote&gt;
      &lt;p&gt;post random things that are too small for my main blog and too big for Twitter&lt;/p&gt;
      &lt;/blockquote&gt;
      
      &lt;p&gt;so that we can use a comment system that, to be fair, could potentially spread your article like weaponised ebola.&lt;/p&gt;
      
      &lt;p&gt;&lt;img alt='Ebola' src='../attachments/ebola.jpg' /&gt;&lt;br /&gt;&lt;sup&gt;&lt;a href='http://en.wikipedia.org/wiki/Viral_marketing' title='Viral marketing - Wikipedia'&gt;
      	Viral marketing - Wikipedia&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
    </content>
    <published>2010-10-09T12:20:53+12:00</published>
    <updated>2010-10-09T12:20:53+12:00</updated>
  </entry>
  <entry>
    <title>Email attachments garbled in osx mail using gmail imap</title>
    <link href='http://www.gingerleprechaun.com/general/email-attachments-garbled-mail-osx-gmail-imap' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-10-09:/general/email-attachments-garbled-mail-osx-gmail-imap</id>
    <content type='html'>
      &lt;p&gt;Never had this problem before I switched to GMail&amp;#8217;s servers to host my email.&lt;/p&gt;
      
      &lt;p&gt;Using &lt;code&gt;mailbox -&amp;gt; rebuild&lt;/code&gt; fixes the problem temporarily&amp;#8230;&lt;/p&gt;
    </content>
    <published>2010-10-09T12:20:53+12:00</published>
    <updated>2010-10-09T12:20:53+12:00</updated>
    <category term='osx'></category>
  </entry>
  <entry>
    <title>Hide 'All Mail' from GMail</title>
    <link href='http://www.gingerleprechaun.com/general/hide_allmail_from_gmail' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-10-06:/general/hide_allmail_from_gmail</id>
    <content type='html'>
      &lt;p&gt;If like me you prefer to use your desktop mail app for accessing your GMail account, you&amp;#8217;re probably sick of imap syncing with the &amp;#8216;All Mail&amp;#8217; folder all the time.&lt;/p&gt;
      
      &lt;p&gt;To hide the &amp;#8216;All Mail&amp;#8217; folder, go to &lt;code&gt;Settings&amp;gt;Labs&lt;/code&gt; and add the &amp;#8216;Advanced IMAP Controls widget&amp;#8217;.&lt;/p&gt;
      
      &lt;p&gt;Now you can go to &lt;code&gt;Settings&amp;gt;Labels&lt;/code&gt; and untick &lt;code&gt;Show in IMAP&lt;/code&gt; for &amp;#8216;All Mail&amp;#8217; and &amp;#8216;Starred&amp;#8217;. (Email you mark as &amp;#8216;Flagged&amp;#8217; in your desktop client will show up in the &amp;#8216;Starred&amp;#8217; folder in Web GMail)&lt;/p&gt;
    </content>
    <published>2010-10-06T10:59:08+12:00</published>
    <updated>2010-10-06T10:59:08+12:00</updated>
  </entry>
  <entry>
    <title>Serving multiple versions of PHP with Apache on OSX</title>
    <link href='http://www.gingerleprechaun.com/php/multiple_versions_php_with_apache_on_osx' rel='alternate' type='text/html' />
    <id>tag:www.gingerleprechaun.com,2010-09-29:/php/multiple_versions_php_with_apache_on_osx</id>
    <content type='html'>
      &lt;p&gt;I need to be able to test sites in PHP5.2 &lt;em&gt;and&lt;/em&gt; PHP5.3. You can only have one version of PHP loaded as an apache module, all the others have to use &lt;code&gt;php-cgi&lt;/code&gt;&lt;/p&gt;
      
      &lt;p&gt;I already had PHP5.3 installed as an apache module on my development system (Snow Leopard), so I built and added 5.2 using cgi as follows.&lt;/p&gt;
      
      &lt;p&gt;Possible gotcha: &lt;strong&gt;The HTTP Authentication hooks in PHP are only available when it is running as an Apache module and is hence not available in the CGI version.&lt;/strong&gt; And &lt;a href='http://theserverpages.com/php/manual/en/features.http-auth.php'&gt;workaround&lt;/a&gt;.&lt;/p&gt;
      
      &lt;blockquote&gt;
      &lt;p&gt;I tried installing the &lt;a href='http://www.entropy.ch/software/macosx/php/'&gt;entropy package&lt;/a&gt; in it&amp;#8217;s own directory but it doesn&amp;#8217;t come with php-cgi, I couldn&amp;#8217;t get it to work, and it wrote a symlink into my apache &lt;code&gt;conf/other&lt;/code&gt; directory which caused SegFaults in apache whenever I tried to unload the PHP module. Moral of the story? If in doubt - use the source.&lt;/p&gt;
      &lt;/blockquote&gt;
      
      &lt;h2 id='install_php_into_its_own_directory'&gt;Install PHP into it&amp;#8217;s own directory&lt;/h2&gt;
      
      &lt;p&gt;First, get the source for the &lt;a href='http://php.net/downloads.php'&gt;version PHP you need&lt;/a&gt;. Decompress with the following commands:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;&amp;gt; gunzip php-5.2.14.tar.gz&amp;#x000A;&amp;gt; tar xf php-5.2.14.tar&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;You’ll now have a directory called /php-5.2.14.&lt;/p&gt;
      
      &lt;p&gt;As you add more modules to your installation, you’ll also need more flags to the ./configure command. This is what I needed:&lt;/p&gt;
      
      &lt;ul&gt;
      &lt;li&gt;curl&lt;/li&gt;
      
      &lt;li&gt;cli&lt;/li&gt;
      
      &lt;li&gt;fastcgi&lt;/li&gt;
      
      &lt;li&gt;zlib&lt;/li&gt;
      
      &lt;li&gt;mysql&lt;/li&gt;
      
      &lt;li&gt;pdo-mysql driver&lt;/li&gt;
      &lt;/ul&gt;
      
      &lt;p&gt;And this is the command I used:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;&amp;gt; ./configure --prefix=/usr/local/php5.2.14 --with-config-file-path=/usr/local/php5.2.14 --with-curl --enable-cli --enable-fastcgi --enable-force-cgi-redirect --enable-discard-path --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --with-mysql-sock=/var/mysql --with-zlib-dir=/usr --with-pdo-mysql=/usr/local/mysql/bin/mysql_config&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Note the &lt;code&gt;--prefix&lt;/code&gt; flag installs php into it&amp;#8217;s own directory leaving your existing install untouched. Don&amp;#8217;t use the &lt;code&gt;--with-apxs&lt;/code&gt; flag - we don&amp;#8217;t want to install as an apache module.&lt;/p&gt;
      
      &lt;p&gt;Also note the mysql flags. This assumes you have mysql installed in &lt;code&gt;usr/local&lt;/code&gt;. If not, adjust for your system or follow the &lt;a href='http://hivelogic.com/articles/compiling-mysql-on-snow-leopard'&gt;hivelogic instructions to install mysql&lt;/a&gt; in &lt;code&gt;/usr/local&lt;/code&gt;.&lt;/p&gt;
      
      &lt;p&gt;So anyway&amp;#8230; once configured do:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;&amp;gt; make&amp;#x000A;&amp;gt; make test&amp;#x000A;&amp;gt; sudo make install&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Okay so now now we have PHP safely installed in &lt;code&gt;/usr/local/php5.2.14&lt;/code&gt; away from your existing PHP install :-)&lt;/p&gt;
      
      &lt;h2 id='configure_virtual_hosts_for_the_version_of_php_you_require'&gt;Configure Virtual Hosts for the version of PHP you require&lt;/h2&gt;
      
      &lt;p&gt;I made a quick folder in my &lt;code&gt;DocumentRoot&lt;/code&gt; in order to test my setup. Add a single file, &lt;code&gt;index.php&lt;/code&gt; which contains:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;&amp;lt;?php&amp;#x000A;	phpinfo();&amp;#x000A;?&amp;gt;&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;Then set up your virtual host for the test file:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;&amp;#x000A;    ServerAdmin me@my_domain.co.uk&amp;#x000A;    DocumentRoot /Library/WebServer/Documents/testphp/public&amp;#x000A;    ServerName testphp.dev&amp;#x000A;    ServerAlias www.testphp.dev&amp;#x000A;    ErrorLog /Library/WebServer/Documents/testphp/public/log/apache_error_log&amp;#x000A;    CustomLog /Library/WebServer/Documents/testphp/public/log/apache_access_log common&amp;#x000A;&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And restart apache&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;sudo apachectl graceful&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;I already had PHP5.3 running as an apache module, so visiting &lt;code&gt;www.testphp.dev&lt;/code&gt; in a browser gives a nice big 5.3 output. Great :-)&lt;/p&gt;
      
      &lt;p&gt;To switch to 5.2 simply modify your virtual host to use &lt;code&gt;php-cgi&lt;/code&gt; as follows:&lt;/p&gt;
      
      &lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;&amp;#x000A;    ServerAdmin me@my_domain.co.uk&amp;#x000A;    DocumentRoot /Library/WebServer/Documents/testphp/public&amp;#x000A;    ServerName testphp.dev&amp;#x000A;    ServerAlias www.testphp.dev&amp;#x000A;    ErrorLog /Library/WebServer/Documents/testphp/public/log/apache_error_log&amp;#x000A;    CustomLog /Library/WebServer/Documents/testphp/public/log/apache_access_log common&amp;#x000A;&amp;#x000A;    # apache 2.2 denies access to the php-cgi executable, unless it is explicitly granted&amp;#x000A;	&amp;lt;Directory /usr/local/php5.2.14/bin&amp;gt;&amp;#x000A;		&amp;lt;Files php-cgi&amp;gt;&amp;#x000A;			Allow from all&amp;#x000A;		&amp;lt;/Files&amp;gt;	&amp;#x000A;	&amp;lt;/Directory&amp;gt;&amp;#x000A;	# required to access content which is not directly under the DocumentRoot&amp;#x000A;	ScriptAlias /php52 /usr/local/php5.2.14&amp;#x000A;	# it would be handy to use php_value directives, but CGI versions of php will not grok them, so we rely on different php.ini&amp;#x000A;	# SetEnv PHPRC /php52&amp;#x000A;	# Add PHP 5 parsing (via CGI) handler and action&amp;#x000A;	AddHandler application/x-httpd-php52 .php&amp;#x000A;	Action application/x-httpd-php52 /php52/bin/php-cgi&amp;#x000A;&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;
      
      &lt;p&gt;And of course, restart apache.&lt;/p&gt;
      
      &lt;p&gt;Now you can choose which sites run on PHP5.2 or PHP5.3 simply by modifying their virtual host entries.&lt;/p&gt;
      
      &lt;blockquote&gt;
      &lt;p&gt;References:&lt;br /&gt;&lt;a href='http://developer.apple.com/internet/opensource/php.html'&gt;PHP on Mac OS X&lt;/a&gt;&lt;br /&gt;&lt;a href='http://cuadradevelopment.com/blog/26/multiple-php-versions-with-apache-using-fastcgi-on-os-x/'&gt;Multiple PHP versions with Apache using FastCGI on OS X&lt;/a&gt;&lt;br /&gt;&lt;a href='http://gggeek.altervista.org/2007/07/21/running-multiple-php-versions-on-a-single-apache-install/'&gt;Running multiple php versions on a single Apache install&lt;/a&gt;&lt;br /&gt;&lt;a href='http://www.malisphoto.com/tips/php-on-os-x.html'&gt;Enabling, Compiling and Installing PHP 5 on Mac OS X Leopard or Snow Leopard&lt;/a&gt;&lt;/p&gt;
      &lt;/blockquote&gt;
    </content>
    <published>2010-09-29T17:05:07+12:00</published>
    <updated>2010-09-29T17:05:07+12:00</updated>
    <category term='osx'></category>
    <category term='php'></category>
  </entry>
</feed>

