<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>amitsamtani.com</title>
	<atom:link href="http://www.amitsamtani.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.amitsamtani.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 13 Aug 2011 21:11:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Writing a custom module in Magento</title>
		<link>http://www.amitsamtani.com/2011/03/18/writing-a-custom-module-in-magento/</link>
		<comments>http://www.amitsamtani.com/2011/03/18/writing-a-custom-module-in-magento/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 19:14:23 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=334</guid>
		<description><![CDATA[There are a number of articles on the internet that explain how to write custom modules in magento but for a new developer that has never worked with Zend and has little experience coding for Magento even the simplest task can be daunting. In this article I will go over building a simple twitter module [...]]]></description>
			<content:encoded><![CDATA[<p>There are a number of articles on the internet that explain how to write custom modules in magento but for a new developer that has never worked with Zend and has little experience coding for Magento even the simplest task can be daunting. In this article I will go over building a simple twitter module with database and session caching that is configurable via the administrative panel.</p>
<h3>Twitters API Call</h3>
<p>http://twitter.com/statuses/user_timeline/USERNAME.json?count=NUMBER_OF_TWEETS_TO_RETURN</p>
<p>This is the call to the Twitter API that retrieves the last tweets made by the specified user. Don&#8217;t ever try to throw this in one of your view templates making a call to the Twitter API every page you visit as you will only get blocked by Twitter. Read number three on the <a href="http://dev.twitter.com/pages/api_terms">API Terms of Service</a>. The module that I will develop here caches the result of the API call in the database and the users session. If another user visits the site before the database cache times out, the user will fetch the result from the database instead of making an unnecessary API call. Once a user fetches the result, any subsequent page that they visit will grab the result from the session until it expires. Both timeouts will be set in the admin panel of the module.</p>
<h3>Codepools and telling magento about your new module</h3>
<p>Magento has three codepools: core, community and local. The core codepool is dedicated for all of magentos system modules, the community codepool is for modules developed by magentos partners and the local codepool is for you as the developer to write custom code. Lets set up a new package and module for our new twitter module. Since I wrote this for my company (<a href="http://www.techandhouse.com">Tech And House</a>) my package will be TechAndHouse and the module will be Twitter. (This module is not used on our site, just something I was playing with to document magento module creation). Set up the following folder structure under /app/code/local/:</p>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/09/magento-file-structure.png"><img class="aligncenter size-full wp-image-359" title="magento-file-structure" src="http://www.amitsamtani.com/wp-content/uploads/2010/09/magento-file-structure.png" alt="" width="175" height="170" /></a></p>
<p>Next, declare your shell module and its codepool. Create a file named TechAndHouse_Tweet.xml under /app/etc/modules/ with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TechAndHouse_Tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>local<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TechAndHouse_Tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>SQL setup</h3>
<p>Now that magento knows about our module, lets set up the database table that will cache the API call. Create config.xml under /app/code/local/TechAndHouse/Tweet/etc/ and define the modules setup handler:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TechAndHouse_Tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TechAndHouse_Tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>TechAndHouse_Tweet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_write<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_read<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Create install script, mysql4-install-0.1.0.php to create table th_tweet in the following directory: /app/code/local/TechAndHouse/Tweet/sql/tweet_setup/</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000088;">$installer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
    DROP TABLE IF EXISTS {<span style="color: #006699; font-weight: bold;">$this-&gt;getTable</span>('th_tweet')};
&nbsp;
    CREATE TABLE {<span style="color: #006699; font-weight: bold;">$this-&gt;getTable</span>('th_tweet')} (
      `tweet_id` int(11) NOT NULL AUTO_INCREMENT,
      `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      `twitter_id` bigint(20) NOT NULL,
      `text` text NOT NULL,
      PRIMARY KEY (`tweet_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1
  &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>With this code in place, visit any page on your store and the table will be created. What happens is that upon instantiation, magento reads the /app/etc/modules directory to get information about all its active modules. Then the config.xml file of each module is read. If a SQL setup handler is found then the appropriate version number is read after comparing to the core_resource table. If the core_resource table does not have a SQL handler listed, magento runs the installer. If the version number in the config file is greater than the version number in the core_resource table, magento runs the proper updater SQL file. For example, if the version number in the config file is 0.1.0 and in the config file the version number is 0.2.0, then magento will run the mysql4-upgrade-0.1.0-0.2.0.php.</p>
<h3>Administration Section And ACL</h3>
<p>Create a new file, system.xml in /app/code/local/TechAndHouse/Tweet/etc/ with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tabs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;techandhouse</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tech And House Modules<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/techandhouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tabs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;techandhouse</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Twitter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tab<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>techandhouse<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tab<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/techandhouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>With this little snippet we have added a Tech And House tab with a sub section of Twitter. Doesn&#8217;t really do much, and when we click on the Twitter section we get an Access Denied error. This happens because our Adminhtml application can not find an entry for our new section in the ACL. Go back to the modules config.xml file and add the following (dots represent areas that we are not touching):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;acl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;admin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;techandhouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tech And House Module<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/techandhouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/children<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/admin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/acl<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After adding this, log out of the magento admin and log in again. Just clearing the cache will not work in this case. After you log in you will be able to click on the new module without the Access Denied error and there will be a new section in the ACL. See screenshots below:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/Magento_new_module_without_access_denied.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/Magento_new_module_without_access_denied-300x207.png" alt="" title="Magento_new_module_without_access_denied" width="300" height="207" class="aligncenter size-medium wp-image-376" /></a><br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/Magento_ACL.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/Magento_ACL.png" alt="" title="Magento_ACL" width="370" height="206" class="aligncenter size-full wp-image-375" /></a></p>
<h3>Administration Fields</h3>
<p>This administration panel needs some fields now. Adding options like a Yes/No dropdown and text fields can just be declared, like this:</p>
<p>In your system.xml file add the following under sections -> groups:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tabs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tabs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;techandhouse</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            ...
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;general</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>General Options<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>60<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;enabled</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Enable Twitter Module<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>adminhtml/system_config_source_yesno<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/enabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;username</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Twitter Username<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>20<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/username<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/general<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/techandhouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After reloading you will see your two new fields as seen in the screenshot below:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/admin_new_fields.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/admin_new_fields-300x71.png" alt="" title="admin_new_fields" width="300" height="71" class="aligncenter size-medium wp-image-378" /></a></p>
<p>Now, if we want to give users specific options and state what our drop down options are going to be we have to do a little more work. Lets say we wanted the site administrator to set the amount of tweets to cache in the database and set the amount of time to expire the database and session caches we would perform the following steps:</p>
<p>Under the model folder (/app/code/local/TechAndHouse/Tweet/model/) create the following files: Database.php, Session.php and Store.php. Each file will hold options to their pertaining select box in the administration panel:</p>
<p>Database.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Database
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toOptionArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'10'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'15'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>            
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'20'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'25'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'30'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">35</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'35'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'40'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">45</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'45'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'50'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'55'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'60'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>                  
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Session.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Session
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toOptionArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'10'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'15'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>            
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'20'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'25'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'30'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">35</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'35'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'40'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">45</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'45'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'50'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">55</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'55'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'60'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>                    
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Store.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Store
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toOptionArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'3'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>            
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'6'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'7'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'8'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'9'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>          
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'10'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>                     
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In your modules system.xml file, add the following fields:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tabs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tabs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;techandhouse</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            ...
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;general</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    ...
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                         ...
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweets_to_store</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Number Of Tweets To Store In Database<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tweet/store<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>30<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweets_to_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session_expiry</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Session Expires in (minutes)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Once tweets are loaded into the session, this module will consult the Session for tweets. After the amount of minutes set here expire, the module will consult the database to see if the database has newer tweets stored. This prevents making database calls every time a page is loaded.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tweet/session<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>40<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session_expiry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;database_expiry</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Database cache expires in (minutes)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Once the session is expired and a tweet is requested, the database is consulted to see if newer tweets are available. If new tweets are not available, the database copy is refreshed by calling the Twitter API and loaded into the session. Set the amount of time database sessions are valid here.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tweet/database<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/database_expiry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/general<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/techandhouse<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Update (8/13/2011):</strong> Make sure your log settings are enabled in System > Developer > Log Settings for next section to work.</p>
<p>Now, if we reload our page we will notice that we get a blank page. To see the error, take a look at your log files. I have tail -f running on the system.log and exception.log under the /var/log/ directory at all times. If we take a look at the system.log we will notice the following error:</p>
<p><i>2010-10-01T16:58:33+00:00 ERR (3): Warning: include() [<a href='function.include'>function.include</a>]: Failed opening &#8216;Mage/Tweet/Model/Store.php&#8217; for inclusion (include_path=&#8217;/Applications/MAMP/htdocs/techandhouse/app/code/local:/Applications/MAMP/htdocs/techandhouse/app/code/community:/Applications/MAMP/htdocs/techandhouse/app/code/core:/Applications/MAMP/htdocs/techandhouse/lib:.:/Applications/MAMP/bin/php5/lib/php&#8217;)  in /Applications/MAMP/htdocs/techandhouse/lib/Varien/Autoload.php on line 93</i></p>
<p>But why is it looking into the Mage package when Store.php was created in the TechAndHouse package? This is because its falling back to the core to look for this file. We have not declared in our config that we are using these modules.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>TechAndHouse_Tweet_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  		    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resourceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tweet_mysql4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resourceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet_mysql4<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>TechAndHouse_Tweet_Model_Mysql4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>th_tweet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet_mysql4<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            ...
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Returning to the admin panel, we still get presented with the blank page. If we take a look at the system.log file, we notice that the error has changed. We are missing the default helper. A lot of magento code expects a default helper, so lets add this as well:</p>
<p>The error:<br />
2010-10-01T17:01:13+00:00 ERR (3): Warning: include() [<a href='function.include'>function.include</a>]: Failed opening &#8216;Mage/Tweet/Helper/Data.php&#8217; for inclusion (include_path=&#8217;/Applications/MAMP/htdocs/techandhouse/app/code/local:/Applications/MAMP/htdocs/techandhouse/app/code/community:/Applications/MAMP/htdocs/techandhouse/app/code/core:/Applications/MAMP/htdocs/techandhouse/lib:.:/Applications/MAMP/bin/php5/lib/php&#8217;)  in /Applications/MAMP/htdocs/techandhouse/lib/Varien/Autoload.php on line 93</p>
<p>Under /app/code/local/TechAndHouse/Tweet/Helper add the default helper Data.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Helper_Data <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Helper_Abstract
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the modules config.xml file add:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;helpers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>TechAndHouse_Tweet_Helper<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tweet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/helpers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	    ...
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            ...
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now if we reload the admin page, we will see our complete configuration options:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/magento_twitter_complete_admin.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/magento_twitter_complete_admin-300x207.png" alt="" title="magento_twitter_complete_admin" width="300" height="207" class="aligncenter size-medium wp-image-386" /></a></p>
<h3>Front Controller</h3>
<p>Before we get this to do something remotely useful, lets add a front controller to be able to access and test some module model classes. </p>
<p>In the config.xml file, add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TechAndHouse_Tweet_TweetRouter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>standard<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>TechAndHouse_Tweet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>techandhouse-tweet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TechAndHouse_Tweet_TweetRouter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And add a new controller, IndexController.php in the /app/code/local/TechAndHouse/Tweet/controllers/ folder:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_IndexController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Controller_Front_Action
<span style="color: #009900;">&#123;</span>   
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>   
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Hello World!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>When we go to http://127.0.0.1:8888/techandhouse-tweet we should now see a blank page with <i>Hello World!</i>. Now, before we continue to write the Twitter Model to get our objective done, lets go over some quick concepts on how to read/write to the database and session and how to retrive system configurations that we set up in the administration panel.</p>
<h3>Accessing System Configurations In Admin</h3>
<p>Change the indexAction in the IndexController to contain the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>   
      <span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getStoreConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'techandhouse/general'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Database Expiry:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;database_expiry&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Session Expiry:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;session_expiry&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Tweets To Store:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tweets_to_store&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Results:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span>enabled<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span>
    <span style="color: #009900;">&#91;</span>username<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> techandhouse
    <span style="color: #009900;">&#91;</span>tweets_to_store_in_db<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span>
    <span style="color: #009900;">&#91;</span>tweets_to_store<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span>
    <span style="color: #009900;">&#91;</span>session_expiry<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span>
    <span style="color: #009900;">&#91;</span>database_expiry<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span>
<span style="color: #009900;">&#41;</span>
Database Expiry<span style="color: #339933;">:</span><span style="color: #cc66cc;">15</span>
Session Expiry<span style="color: #339933;">:</span><span style="color: #cc66cc;">15</span>
Tweets To Store<span style="color: #339933;">:</span><span style="color: #cc66cc;">5</span></pre></div></div>

<h3>Working with Magento Session</h3>
<p>Change the indexAction to have the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRandomVariable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will not return anything</span>
      Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRandomVariable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hi&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRandomVariable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will return &quot;hi&quot;</span>
&nbsp;
      Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRandomVariable</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;var&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;goodbye world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//can even do arrays</span>
      <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRandomVariable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//will return array(&quot;text&quot;=&gt;&quot;hello world&quot;,&quot;var&quot;=&gt;&quot;goodbye world&quot;)</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Working with Models And Database</h3>
<p>Before we can start working with the table we created earlier in this post we need to create a model that will hold all of our business logic and the collection object in case we work with the built in collection classes.</p>
<p>Create Tweet.php in /app/code/local/TechAndHouse/Tweet/model with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Tweet <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      parent<span style="color: #339933;">::</span>_construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Create Tweet.php in /app/code/local/TechAndHouse/Tweet/model/Mysql4/ with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Mysql4_Tweet <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Mysql4_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tweet_id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Create Collection.php in /app/code/local/TechAndHouse/Tweet/model/Mysql4/Tweet/ with:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Mysql4_Tweet_Collection <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Mysql4_Collection_Abstract 
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>_construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The model directory structure should now look like this:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/magento_model_directory_structure.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/magento_model_directory_structure.png" alt="" title="magento_model_directory_structure" width="194" height="154" class="aligncenter size-full wp-image-394" /></a></p>
<p>Now, go back to the IndexController.php and change the indexAction to contain:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTwitterId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1234&quot;</span><span style="color: #009900;">&#41;</span>
      	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;My new tweet!&quot;</span><span style="color: #009900;">&#41;</span>
      	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Refresh the page (http://127.0.0.1:8888/techandhouse-tweet) and you will have the following created in your database:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/db_entry.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/db_entry-300x26.png" alt="" title="db_entry" width="300" height="26" class="aligncenter size-medium wp-image-396" /></a></p>
<p>Next, lets try reading from the database. Change the indexAction to now contain:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_read'</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;th_tweet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text like '%tweet%'&quot;</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Output: array(1) { [0]=> array(1) { ["text"]=> string(13) &#8220;My new tweet!&#8221; } }</p>
<p>Need to empty the table? Try:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TRUNCATE TABLE th_tweet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Check the database, it should now be empty.</p>
<h3>Tweet Model &#8211; API Call and database caching</h3>
<p>Ok, with all the concepts discussed in the section above, reading the following code should be straight forward. When getTweets is called, the function will first check against our table, th_tweet to see if we have a cached copy that has not expired. If no tweets are returned, the API call is made, result stored in the database and retured to the controller:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Tweet_Model_Tweet <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      parent<span style="color: #339933;">::</span>_construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTweets<span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$username</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;techandhouse&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$database_expiry</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span><span style="color: #000088;">$tweets_to_store</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>    
      <span style="color: #000088;">$tweets</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastUnexpiredTweets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">,</span><span style="color: #000088;">$database_expiry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweets</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
        <span style="color: #000088;">$tweets</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">refreshTweets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span><span style="color: #000088;">$tweets_to_store</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tweets</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> refreshTweets<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span><span style="color: #000088;">$tweets_to_store</span><span style="color: #339933;">,</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TRUNCATE TABLE th_tweet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$tweets</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://twitter.com/statuses/user_timeline/<span style="color: #006699; font-weight: bold;">{$username}</span>.json?count=<span style="color: #006699; font-weight: bold;">{$tweets_to_store}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweets</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
        Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTwitterId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
          <span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
          <span style="color: #000088;">$return</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>      
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getLastUnexpiredTweets<span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$database_expiry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_read'</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;th_tweet&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;updated BETWEEN DATE_SUB(NOW(), INTERVAL <span style="color: #006699; font-weight: bold;">{$database_expiry}</span> MINUTE) AND NOW()&quot;</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                   <span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, lets test this out. Change the indexAction to have the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getStoreConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'techandhouse/general'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tweet/tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTweets</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;database_expiry&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tweets_to_store&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 *Result: Array ( [0] =&gt; Array ( [text] =&gt; New blog post: Cool Off With Panasonic Inverter Air Conditioners http://bit.ly/9Pj1VY ) )
 */</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2011/03/18/writing-a-custom-module-in-magento/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Setting up a Magento Staging Area</title>
		<link>http://www.amitsamtani.com/2011/03/16/setting-up-a-magento-staging-area/</link>
		<comments>http://www.amitsamtani.com/2011/03/16/setting-up-a-magento-staging-area/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 03:47:04 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=518</guid>
		<description><![CDATA[Copy Production Store Login to SSH and go to the Document Root for the staging directory cd staging Copy all data from the live site to the staging directory cp -R ../public_html/* ../public_html/.htaccess . Copy production database to staging database mysqldump -u PRODUCTION_DBUSER -p PRODUCTION_DBNAME &#62; data.sql mysql -u STAGING_DBUSER -p STAGING_DBNAME &#60; data.sql Change [...]]]></description>
			<content:encoded><![CDATA[<h3>Copy Production Store</h3>
<ol>
<li>
Login to SSH and go to the Document Root for the staging directory</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> staging</pre></div></div>

</li>
<li>
Copy all data from the live site to the staging directory</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> ..<span style="color: #000000; font-weight: bold;">/</span>public_html<span style="color: #000000; font-weight: bold;">/*</span> ..<span style="color: #000000; font-weight: bold;">/</span>public_html<span style="color: #000000; font-weight: bold;">/</span>.htaccess .</pre></div></div>

</li>
<li>
Copy production database to staging database</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump <span style="color: #660033;">-u</span> PRODUCTION_DBUSER <span style="color: #660033;">-p</span> PRODUCTION_DBNAME <span style="color: #000000; font-weight: bold;">&gt;</span> data.sql</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> STAGING_DBUSER <span style="color: #660033;">-p</span> STAGING_DBNAME <span style="color: #000000; font-weight: bold;">&lt;</span> data.sql</pre></div></div>

</li>
<li>
Change credentials to store staging database configuration in:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">~<span style="color: #000000; font-weight: bold;">/</span>staging<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>local.xml</pre></div></div>

</li>
<li>
Run the following sql query on the staging database and update the values to point to the staging url:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`core_config_data`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`path`</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%base_url%'</span>;</pre></div></div>

</li>
</ol>
<h3>Update (7/21/2011): Git</h3>
<p>Not sure why it took me this long to finally get the Tech And House site on Git, but finally did it today. I&#8217;m currently versioning just the app and skin folders and the themes that are in use, everything else has been placed in .gitignore. Since the staging domain is on the same server as the production domain, my hosting provider flips and disables my backups because I&#8217;m not allowed to have that many files on the server. I have to make my updates on dev, test on staging and right after pushing to production, I need to clear out my staging server. If you&#8217;re in this boat, here are the steps I follow:</p>
<p>Steps on Staging Server:</p>
<ol>
<li>Make changes on development box, git commit, git push</li>
<li>Prep staging server by pulling production code to staging folder

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> ..<span style="color: #000000; font-weight: bold;">/</span>public_html<span style="color: #000000; font-weight: bold;">/*</span> ..<span style="color: #000000; font-weight: bold;">/</span>public_html<span style="color: #000000; font-weight: bold;">/</span>.htaccess .</pre></div></div>

</li>
<li>Since we keep deleting all the files on the staging server, reset it to the last committed state of the git repo:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git reset <span style="color: #660033;">--hard</span> HEAD</pre></div></div>

</li>
<li>Pull changes that were made on the development machine:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git pull</pre></div></div>

</li>
<li>Set permissions and clear cache and sessions

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">chmod</span> o+<span style="color: #c20cb9; font-weight: bold;">w</span> var var<span style="color: #000000; font-weight: bold;">/</span>.htaccess includes includes<span style="color: #000000; font-weight: bold;">/</span>config.php app<span style="color: #000000; font-weight: bold;">/</span>etc
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> o+<span style="color: #c20cb9; font-weight: bold;">w</span> media
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;">755</span> var
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> var<span style="color: #000000; font-weight: bold;">/</span>cache
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> var<span style="color: #000000; font-weight: bold;">/</span>session
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">550</span> mage
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">550</span> pear
<span style="color: #666666; font-style: italic;">#chmod 550 pear Magento &lt;= 1.5 chmod 550 mage for Magento &gt;= 1.5</span></pre></div></div>

</li>
<li>Update database connection details to point to the staging servers db: /app/etc/local.xml</li>
</ol>
<p>Maybe &#8220;Update 2&#8243; will have Capistrano involved handling the deploy as well, but for now, I&#8217;m ok with this little setup. Usually just skip staging all together as thats the most time consuming process due to hosting providers TOS. Change/Test on dev, git pull straight to production.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2011/03/16/setting-up-a-magento-staging-area/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Excel: Conditional Formatting Row Color Based On Cell Value</title>
		<link>http://www.amitsamtani.com/2011/01/25/excel-conditional-formatting-row-color-based-on-cell-value/</link>
		<comments>http://www.amitsamtani.com/2011/01/25/excel-conditional-formatting-row-color-based-on-cell-value/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 05:02:55 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Conditional Formatting]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=505</guid>
		<description><![CDATA[At times when you&#8217;re staring at an Excel spreadsheet for a while it is nice to have certain rows stand out based on certain conditions. A little Excel feature I use every now and then is the conditional formatting found in menu item Format > Conditional Formatting&#8230; If you would just like to highlight a [...]]]></description>
			<content:encoded><![CDATA[<p>At times when you&#8217;re staring at an Excel spreadsheet for a while it is nice to have certain rows stand out based on certain conditions. A little Excel feature I use every now and then is the conditional formatting found in menu item Format > Conditional Formatting&#8230;</p>
<p>If you would just like to highlight a cell, use the &#8220;Cell value is&#8221; condition and edit the formatting background. If you would like to highlight the entire row, use the &#8220;Formula is&#8221; condition with the =INDIRECT() function. </p>
<p>For example, if you would like to highlight all rows where cell C of a row has a value less than 0, use =INDIRECT(&#8220;C&#8221;&#038;ROW())<0</p>
<p>See screenshots:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2011/01/Screen-shot-2011-01-25-at-10.29.28-PM.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2011/01/Screen-shot-2011-01-25-at-10.29.28-PM.png" alt="" title="Screen shot 2011-01-25 at 10.29.28 PM" width="226" height="143" class="aligncenter size-full wp-image-507" /></a><br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2011/01/Screen-shot-2011-01-25-at-10.30.20-PM.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2011/01/Screen-shot-2011-01-25-at-10.30.20-PM-300x101.png" alt="" title="Screen shot 2011-01-25 at 10.30.20 PM" width="300" height="101" class="aligncenter size-medium wp-image-508" /></a><br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2011/01/Screen-shot-2011-01-25-at-10.31.04-PM.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2011/01/Screen-shot-2011-01-25-at-10.31.04-PM.png" alt="" title="Screen shot 2011-01-25 at 10.31.04 PM" width="227" height="145" class="aligncenter size-full wp-image-509" /></a></p>
<p>[<a href="http://www.asap-utilities.com/blog/index.php/2005/11/07/conditional-row-color-based-on-a-cell-value/">Original Source</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2011/01/25/excel-conditional-formatting-row-color-based-on-cell-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Magento on Rackspace CouldServer</title>
		<link>http://www.amitsamtani.com/2010/12/16/setting-up-magento-on-rackspace-couldserver/</link>
		<comments>http://www.amitsamtani.com/2010/12/16/setting-up-magento-on-rackspace-couldserver/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 22:08:25 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cloudserver]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[rackspace]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=477</guid>
		<description><![CDATA[Objective: Prep a test server for a Magento installation on Ubuntu 10.10 In this example I spun up a quick server on Rackspace that has the bare minimums of Ubuntu installed. So everything needs to get installed. Before getting started, take a look at the server requirements to run Magento and run the magento check [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Objective</strong>: Prep a test server for a Magento installation on Ubuntu 10.10</p>
<p>In this example I spun up a quick server on Rackspace that has the bare minimums of Ubuntu installed. So everything needs to get installed. Before getting started, take a look at the <a href="http://www.magentocommerce.com/system-requirements">server requirements</a> to run Magento and run the <a href="http://www.magentocommerce.com/knowledge-base/entry/how-do-i-know-if-my-server-is-compatible-with-magento">magento check utility</a> before attempting to install magento to make sure all required components are installed.</p>
<p><strong>Step 1</strong>: Update apt-get</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update</pre></div></div>

<p><strong>Step 2</strong>: Install updatedb. Not necessary, just like having it around.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">locate</span></pre></div></div>

<p><strong>Step 3</strong>: Install PHP 5</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5</pre></div></div>

<p><strong>Step 4</strong>: Install Apache 2.2</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2</pre></div></div>

<p><strong>Step 5</strong>: Enable Apache Mod Rewrite and restart Apache</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod rewrite
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p><strong>Step 6</strong>: Install MySQL 5</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server</pre></div></div>

<p><strong>Step 7</strong>: Install required PHP extensions and restart Apache</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-mysql php5-mcrypt php5-gd php5-curl php-pear php5-dev libmysqlclient-dev libcurl3-openssl-dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p><strong>Step 8</strong>: Setup a virtualhost for the new test site <a href="https://help.ubuntu.com/community/ApacheMySQLPHP">Further Reading</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>default <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>techandhouse_dev</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>techandhouse_dev</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Change the DocumentRoot to point to the new location. Example:</span>
<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>techecom_dev<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Change the Directory directive, replace:</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/&gt;</span> to <span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>techecom_dev<span style="color: #000000; font-weight: bold;">/&gt;</span></pre></div></div>

<p>Sample config:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--Change AllowOverride to All for our site for mod rewrite to work--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VirtualHost</span> *:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
        ServerAdmin webmaster@localhost
        ServerName techandhouse_dev
&nbsp;
        DocumentRoot /home/techecom_dev/public_html/
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                Options FollowSymLinks
                AllowOverride All
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> /home/techecom_dev/public_html<span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> <span style="color: #ff0000;">&quot;/usr/lib/cgi-bin&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        ErrorLog ${APACHE_LOG_DIR}/error.log
&nbsp;
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
&nbsp;
        CustomLog ${APACHE_LOG_DIR}/access.log combined
&nbsp;
    Alias /doc/ &quot;/usr/share/doc/&quot;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> <span style="color: #ff0000;">&quot;/usr/share/doc/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Deactivate the old site, activate the new one, and restart Apache.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2dissite default <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> a2ensite techandhouse_dev
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart</pre></div></div>

<p>If you run the <a href="http://www.magentocommerce.com/_media/magento-check.zip">magento check utility</a> and go to the IP address or domain of your machine, you should see:</p>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/12/Screen-shot-2010-12-16-at-3.36.31-PM.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/12/Screen-shot-2010-12-16-at-3.36.31-PM-300x194.png" alt="" title="Magento Server Ready" width="300" height="194" class="aligncenter size-medium wp-image-491" /></a></p>
<p><a href="http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/moving_magento_to_another_server">Follow instructions here to move the web site to the test server&#8230;</a></p>
<p>After moving the web site, update a couple values so that the site doesn&#8217;t route itself back to the real domain because of the database or cached files:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">update</span> core_config_data <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #990099; font-weight: bold;">value</span><span style="color: #CC0099;">=</span><span style="color: #008000;">&quot;http://DOMAIN/&quot;</span> <span style="color: #990099; font-weight: bold;">where</span> path<span style="color: #CC0099;">=</span>’web<span style="color: #CC0099;">/</span>unsecure<span style="color: #CC0099;">/</span>host’<span style="color: #000033;">;</span>     
<span style="color: #990099; font-weight: bold;">update</span> core_config_data <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #990099; font-weight: bold;">value</span><span style="color: #CC0099;">=</span><span style="color: #008000;">&quot;http://DOMAIN/&quot;</span> <span style="color: #990099; font-weight: bold;">where</span> path<span style="color: #CC0099;">=</span>’web<span style="color: #CC0099;">/</span>secure<span style="color: #CC0099;">/</span>host’<span style="color: #000033;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>magento<span style="color: #000000; font-weight: bold;">/</span>site
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-r</span> var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/*</span> var<span style="color: #000000; font-weight: bold;">/</span>session<span style="color: #000000; font-weight: bold;">/*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/12/16/setting-up-magento-on-rackspace-couldserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu: Create new user with sudo access</title>
		<link>http://www.amitsamtani.com/2010/12/12/ubuntu-create-new-user-with-sudo-access/</link>
		<comments>http://www.amitsamtani.com/2010/12/12/ubuntu-create-new-user-with-sudo-access/#comments</comments>
		<pubDate>Sun, 12 Dec 2010 17:16:16 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[user management]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=462</guid>
		<description><![CDATA[Objective: Create new user on Ubuntu with sudo access Create New User $ adduser username Adding user `username` ... Adding new group `username` &#40;1000&#41; ... Adding new user `username` &#40;1000&#41; with group `username` ... Creating home directory `/home/username` ... Copying files from `/etc/skel` ... Enter new UNIX password: Retype new UNIX password: passwd: password updated [...]]]></description>
			<content:encoded><![CDATA[<p>Objective: Create new user on Ubuntu with sudo access</p>
<h3>Create New User</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ adduser username
Adding user <span style="color: #000000; font-weight: bold;">`</span>username<span style="color: #000000; font-weight: bold;">`</span> ...
Adding new group <span style="color: #000000; font-weight: bold;">`</span>username<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> ...
Adding new user <span style="color: #000000; font-weight: bold;">`</span>username<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> with group <span style="color: #000000; font-weight: bold;">`</span>username<span style="color: #000000; font-weight: bold;">`</span> ...
Creating home directory <span style="color: #000000; font-weight: bold;">`/</span>home<span style="color: #000000; font-weight: bold;">/</span>username<span style="color: #000000; font-weight: bold;">`</span> ...
Copying files from <span style="color: #000000; font-weight: bold;">`/</span>etc<span style="color: #000000; font-weight: bold;">/</span>skel<span style="color: #000000; font-weight: bold;">`</span> ...
Enter new UNIX password: 
Retype new UNIX password: 
<span style="color: #c20cb9; font-weight: bold;">passwd</span>: password updated successfully
Changing the user information <span style="color: #000000; font-weight: bold;">for</span> username
Enter the new value, or press ENTER <span style="color: #000000; font-weight: bold;">for</span> the default
	Full Name <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Username
	Room Number <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: 
	Work Phone <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: 
	Home Phone <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: 
	Other <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: 
Is the information correct? <span style="color: #7a0874; font-weight: bold;">&#91;</span>Y<span style="color: #000000; font-weight: bold;">/</span>n<span style="color: #7a0874; font-weight: bold;">&#93;</span> y</pre></div></div>

<h3>Add to sudoers file</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ visudo</pre></div></div>

<p>Add (change <strong>username</strong> to your username):<br />
username ALL=(ALL) ALL</p>
<p>Under:<br />
root    ALL=(ALL) ALL</p>
<p>Thats it. This new user can only do superuser commands via sudo. One thing I am still not sure of is how to do is restrict this user from <code>cd ..</code>&#8216;ing back up and snooping around other directories. If you know how, please let me know. For now, I can continue setting up my test server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/12/12/ubuntu-create-new-user-with-sudo-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Custom attributes for customer profiles</title>
		<link>http://www.amitsamtani.com/2010/11/30/magento-custom-attributes-for-customer-profiles/</link>
		<comments>http://www.amitsamtani.com/2010/11/30/magento-custom-attributes-for-customer-profiles/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 00:06:05 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=446</guid>
		<description><![CDATA[If you&#8217;re looking to synchronize your customer, sales order and invoices between your back office system and Magento you&#8217;re going to need to store the back offices unique ID within Magento. Unlike products, adding custom attributes and attribute sets is not so straight forward. You can not just add it within the administration interface. Task: [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking to synchronize your customer, sales order and invoices between your back office system and Magento you&#8217;re going to need to store the back offices unique ID within Magento. Unlike products, adding custom attributes and attribute sets is not so straight forward. You can not just add it within the administration interface. </p>
<p><strong>Task:</strong> Add field erp_customer_id to customer profile (same concept applies to sales orders and invoices)</p>
<p><strong>Step 1:</strong> Let Magento know we are creating a new module and add TechAndHouse_Customer.xml in /app/etc/modules/ with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TechAndHouse_Customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>local<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TechAndHouse_Customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Step 2:</strong> Create a new module under /app/code/local/ with the following directory structure:</p>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/11/Screen-shot-2010-11-30-at-6.25.36-PM.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/11/Screen-shot-2010-11-30-at-6.25.36-PM.png" alt="" title="Tech And House Customer Module Directory Structure" width="159" height="112" class="aligncenter size-full wp-image-447" /></a></p>
<p><strong>Step 3a:</strong> Copy the contents of  /app/code/core/Mage/Customer/etc/config.xml into /app/code/local/TechAndHouse/Customer/etc/config.xml and change:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Mage_Customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>x.x.x<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Mage_Customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TechAndHouse_Customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TechAndHouse_Customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Step 3b:</strong> In this same file, config.xml add the variable erp_customer_id into the global fieldset under customer_account</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;erp_customer_id<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;create<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/create<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;update<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/update<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/erp_customer_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Step 4a:</strong> Copy the getDefaultEntities method from /app/code/core/Mage/Customer/Model/Entity/Setup.php file to /app/code/local/TechAndHouse/Model/Entity/Setup.php and put it in the following class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> TechAndHouse_Customer_Model_Entity_Setup <span style="color: #000000; font-weight: bold;">extends</span> Mage_Customer_Model_Entity_Setup <span style="color: #009900;">&#123;</span></pre></div></div>

<p><strong>Step 4b:</strong> Add the following attribute in the array right before website_id</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'erp_customer_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                  	<span style="color: #0000ff;">'label'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ERP Customer ID'</span><span style="color: #339933;">,</span>
                  	<span style="color: #0000ff;">'visible'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                  	<span style="color: #0000ff;">'required'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span></pre></div></div>

<p><strong>Step 5:</strong> Add the following in any theme file and visit the page, like
<theme>/template/customer/form/register.phtml to create the attribute in the database:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$setup</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TechAndHouse_Customer_Model_Entity_Setup<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core_setup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$setup</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'customer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'erp_customer_id'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'label'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ERP Customer ID'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'type'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'varchar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'input'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'visible'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'required'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'position'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Step 6:</strong> Check if the variable got created in the eav_attribute table.</p>
<p><strong>Step 7:</strong> Did it work? At this point you can run a quick test and see if you can write and read from your new attribute. Never modify core files, and do not do anything on a production machine. The following was done on a development box.</p>
<p>Add the following to /design/adminhtml/default/default/template/customer/tab/view.phtml:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCustomer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setErpCustomerId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;1234&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCustomer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getErpCustomerId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Visit a customer in the admin section and you will see the following:</p>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/11/erp_customer_id.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/11/erp_customer_id-300x118.png" alt="" title="erp_customer_id" width="300" height="118" class="aligncenter size-medium wp-image-450" /></a></p>
<h3>Credit</h3>
<p>Original Article: <a href="http://www.fontis.com.au/blog/magento/custom-customer-signup-attributes">Fontis</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/11/30/magento-custom-attributes-for-customer-profiles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Index Manager Error On Magento</title>
		<link>http://www.amitsamtani.com/2010/10/18/index-manager-error-on-magento/</link>
		<comments>http://www.amitsamtani.com/2010/10/18/index-manager-error-on-magento/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 23:15:15 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=421</guid>
		<description><![CDATA[The Problem After performing an upgrade to version 1.4.1.0 my index management and catalog search stopped working. The Alert: &#8220;One or more of the Indexes are not up to date: Catalog Search Index. Click here to go to Index Management and rebuild required indexes.&#8221; The Error: &#8220;Cannot initialize the indexer process&#8221; The Screenshot: Whats going [...]]]></description>
			<content:encoded><![CDATA[<h3>The Problem</h3>
<p>After performing an upgrade to version 1.4.1.0 my index management and catalog search stopped working. </p>
<p><strong>The Alert:</strong><br />
<i>&#8220;<strong>One or more of the Indexes are not up to date:</strong> Catalog Search Index. Click here to go to Index Management and rebuild required indexes.&#8221;</i></p>
<p><strong>The Error:</strong><br />
<i>&#8220;Cannot initialize the indexer process&#8221;</i></p>
<p><strong>The Screenshot:</strong><br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/indexer-error.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/indexer-error-300x104.png" alt="" title="indexer error" width="300" height="104" class="aligncenter size-medium wp-image-422" /></a></p>
<h3>Whats going on?</h3>
<p>A table in <a href="http://dev.mysql.com/doc/refman/5.1/en/column-count-limit.html">MySQL has a limitation of 65535 bytes of overall row length</a>. It may severely limit the number of columns in a table when it has varchar/char columns. In Magento starting from 1.3 the products catalog in the &#8220;flat&#8221; mode suffers from this limitation depending on the number and combination of the product attributes that participate in the flat product index. Source: <a href='http://www.amitsamtani.com/wp-content/uploads/2010/10/SUP-MySQLLimitationsontheFlatCatalogProduct-29Jul10-0343PM-17.pdf'>SUP-MySQLLimitationsontheFlatCatalogProduct-29Jul10-0343PM-17</a></p>
<p>The workaround that stood out was setting &#8220;Used in Product Listing&#8221; = No:</p>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/used-in-product-listing.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/used-in-product-listing-300x217.png" alt="" title="used in product listing" width="300" height="217" class="aligncenter size-medium wp-image-433" /></a></p>
<p>Apparently, when I originally set up the store I was under the impression that this field always has to be set to Yes. Of course I want this attribute to be used in my product listing. Whats the point of creating an attribute that will not be used in the product listing, right? Well, no. This field controls if the attribute will be used in the &#8220;grid&#8221; or &#8220;list&#8221; view when showing multiple products per page. In my opinion you only need certain fields set to yes for those views, and its already preset when you set up magento for the first time. Fields like, price, special price, name and short description. Not EVERY attribute!</p>
<h3>Solution</h3>
<p>Take a look at the catalog_eav_attribute and eav_attribute tables. Update the used_in_product_listing field to 0 for all user defined fields that are set to 1. Before running this, use a SELECT clause and see what fields its pulling out. Also, run on a test environment first!!</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">update</span> <span style="color: #008000;">`catalog<span style="color: #008080; font-weight: bold;">_</span>eav<span style="color: #008080; font-weight: bold;">_</span>attribute`</span> <span style="color: #990099; font-weight: bold;">as</span> cea <span style="color: #000099;">left</span> <span style="color: #990099; font-weight: bold;">join</span> eav_attribute <span style="color: #990099; font-weight: bold;">as</span> ea <span style="color: #990099; font-weight: bold;">on</span> cea.attribute_id <span style="color: #CC0099;">=</span> ea.attribute_id <span style="color: #990099; font-weight: bold;">set</span> cea.used_in_product_listing <span style="color: #CC0099;">=</span> <span style="color: #008080;">0</span> <span style="color: #990099; font-weight: bold;">where</span> cea.used_in_product_listing <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span> <span style="color: #CC0099; font-weight: bold;">and</span> is_user_defined <span style="color: #CC0099;">=</span> <span style="color: #008080;">1</span></pre></div></div>

<h3>&#8230;and Fixed!</h3>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/indexer-error-fix.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/indexer-error-fix-300x92.png" alt="" title="indexer error fix" width="300" height="92" class="aligncenter size-medium wp-image-423" /></a></p>
<h3>With a working search&#8230;</h3>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/working-search.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/working-search-300x171.png" alt="" title="working search" width="300" height="171" class="aligncenter size-medium wp-image-439" /></a></p>
<h3>Another solution</h3>
<p>I was trying to find the thread where I found the original PDF to give credit to the person who led me in this direction and ended up stumbling across another solution: <a href="http://www.sonassi.com/knowledge-base/magento-knowledge-base/mysql-limitations-on-the-flat-catalogue-in-magento/">http://www.sonassi.com/knowledge-base/magento-knowledge-base/mysql-limitations-on-the-flat-catalogue-in-magento/</a>. If my solution does not help, maybe Sonassis solution will.</p>
<p>Good Luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/10/18/index-manager-error-on-magento/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Inode Usage Exceeds Hosting TOS</title>
		<link>http://www.amitsamtani.com/2010/10/16/inode-usage-exceeds-hosting-tos/</link>
		<comments>http://www.amitsamtani.com/2010/10/16/inode-usage-exceeds-hosting-tos/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 23:06:00 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=407</guid>
		<description><![CDATA[Periodically I get an email from my hosting provider alerting me that my inode usage exceeds their resource abuse policy. Since I&#8217;m using magento on the server they recommend clearing out the contents of downloader/pearlib/cache/* and downloader/pearlib/download/* and deleting all empty .svn folders. My inode usage was still a little higher than necessary after completing [...]]]></description>
			<content:encoded><![CDATA[<p>Periodically I get an email from my hosting provider alerting me that my inode usage exceeds their resource abuse policy. Since I&#8217;m using magento on the server they recommend clearing out the contents of downloader/pearlib/cache/* and downloader/pearlib/download/* and deleting all empty .svn folders. My inode usage was still a little higher than necessary after completing these steps.</p>
<p>First of all, what is an inode?  An inode stores basic information about a regular file, directory, or other file system object. So in a nutshell, any file, directory or file system object counts toward a point against your inode usage. Messing around I decided to clear all my caches (css, js and images). The image cache really penalized me. By clearing out the image cache my inode usage dropped from 56K to about 40K. Now, this was obviously a temporary fix as my cache is going to be rebuilt as visits come through. </p>
<p>One thing I did realize though was my media folder had high inode usage. Apparently when I was doing my initial product imports using the importing tools I kept on creating image files that were not really used on the site. Why keep those files around? I wrote a little script to clear those images out. Right now my inode usage has dropped to 26K and I don&#8217;t have to worry about getting suspended by my hosting provider for a little bit more time. </p>
<p>Before I post the script, a couple things&#8230; Test it out in a test environment before running it in production. Make a back up of your site and your image folder in case you miss something and go off deleting a bunch of random files. This is a simple script I put together to remove any unused product images in the site. I threw it up very quickly, I know it could be cleaned up quite a bit with added features and a lot of good blah blah, but I needed to bring my inode usage down quick and this script helped me clear a lot of unused images. Don&#8217;t track me down if something bad happens to your site. BACKUP! TEST! You have been warned!</p>
<p>Put the following two files in the /media/catalog/product/ folder:</p>
<p>1) Export contents of the <em>catalog_product_entity_media_gallery</em> table with only the value field:<br />
<a href="http://www.amitsamtani.com/wp-content/uploads/2010/10/export.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/10/export-300x179.png" alt="" title="export" width="300" height="179" class="aligncenter size-medium wp-image-411" /></a></p>
<p>2) Run the following code in the product folder. Before running the commented out code with the <em>rm</em> statements, see what its doing and test properly! This script will drill down into every subdirectory within the product directory looking for images and then will compare against the export file to see if the image is being used or not. If the image is not being used, the image will be deleted.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> removeUnusedImages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #339933;">,</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'..'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'placeholder'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">===</span> <span style="color: #0000ff;">'cache'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$prefix</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
        removeUnusedImages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> 
        <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$images</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Remove: <span style="color: #006699; font-weight: bold;">{$file}</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">//system('ls ' . substr($file,1));</span>
          <span style="color: #666666; font-style: italic;">//system('rm ' . substr($file,1));</span>
        <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> 
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Dont Remove: <span style="color: #006699; font-weight: bold;">{$file}</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$images</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'export.txt'</span><span style="color: #339933;">,</span>FILE_IGNORE_NEW_LINES<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
removeUnusedImages<span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/10/16/inode-usage-exceeds-hosting-tos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Third World Email Solutions</title>
		<link>http://www.amitsamtani.com/2010/08/12/third-world-email-solutions/</link>
		<comments>http://www.amitsamtani.com/2010/08/12/third-world-email-solutions/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 04:00:33 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[google apps]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=314</guid>
		<description><![CDATA[I find it difficult to believe that companies in Panama are still using their internet service providers email addresses as their email solution. Email addresses like, company@cwpanama.net or company@gmail.com are perfectly normal to find here. At these companies, one lucky person has access to all inbound company email or, multiple people access the same account. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/08/mail.jpg"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/08/mail.jpg" alt="" title="mail" width="460" height="151" class="aligncenter size-full wp-image-315" /></a><br />
I find it difficult to believe that companies in Panama are still using their internet service providers email addresses as their email solution. Email addresses like, company@cwpanama.net or company@gmail.com are perfectly normal to find here. At these companies, one lucky person has access to all inbound company email or, multiple people access the same account. I&#8217;m sure you see the problem with this. If you know of a company guilty of this, show them the light and get a Google App account configured. Not only can you create as many users as you want, you can create mailing lists like sales@company.com which is routed to multiple recipients. Best of all your company email will be backed by the power of gmail and all its features! If you need help, I&#8217;m willing to assist. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/08/12/third-world-email-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP: Session value is favicon.ico, Why?</title>
		<link>http://www.amitsamtani.com/2010/06/28/cakephp-session-value-is-favicon-ico-why/</link>
		<comments>http://www.amitsamtani.com/2010/06/28/cakephp-session-value-is-favicon-ico-why/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 05:39:40 +0000</pubDate>
		<dc:creator>Amit</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cakePHP]]></category>

		<guid isPermaLink="false">http://www.amitsamtani.com/?p=302</guid>
		<description><![CDATA[It was time to give CakePHPs Auth component a little test drive. Thinking I followed the manual to the key, there was no way I missed a step. I mean, there isn&#8217;t really much to do to set up simple authentication using CakePHP right? Well, for some reason after logging in I would get pushed [...]]]></description>
			<content:encoded><![CDATA[<p>It was time to give CakePHPs Auth component a little test drive. Thinking I followed the manual to the key, there was no way I missed a step. I mean, there isn&#8217;t really much to do to set up simple authentication using CakePHP right? Well, for some reason after logging in I would get pushed to http://localhost:8888/users/favicon.ico:</p>
<p><a href="http://www.amitsamtani.com/wp-content/uploads/2010/06/favicon_error.png"><img src="http://www.amitsamtani.com/wp-content/uploads/2010/06/favicon_error.png" alt="" title="favicon_error" width="450" height="310" class="alignleft size-full wp-image-306" /></a></p>
<p>Anyway, googling, asking for help on #cakephp didn&#8217;t really help as the problem was so stupid, not many people have had this problem. I stumbled across this post on the <a href="http://groups.google.com/group/cake-php/browse_thread/thread/3c40de92e9e1778e/b8258e6a8c33721a?lnk=gst&#038;q=favicon#b8258e6a8c33721a">CakePHP google group</a>.</p>
<p>Basically &#8211; &#8220;make sure the link to favicon.ico is root-relative (/favicon.ico). Otherwise the server&#8217;s looking for /controller/action/favicon.ico and the broken link gets captured as the current page. Same thing for your css and js.&#8221; &#8211; Chris Cassell </p>
<p>(Thank you sir!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amitsamtani.com/2010/06/28/cakephp-session-value-is-favicon-ico-why/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
