<?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>Subesh Pokhrel&#039;s Blog - Magento Development Tips</title>
	<atom:link href="http://subesh.com.np/feed/" rel="self" type="application/rss+xml" />
	<link>http://subesh.com.np</link>
	<description>PHP &#38; Magento Tips and Tutorials</description>
	<lastBuildDate>Wed, 01 Feb 2012 04:09:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MagDoc – Powered by Scribd Released on Magento Connect</title>
		<link>http://subesh.com.np/2012/02/magdoc-powered-by-scribd-released-on-magento-connect/</link>
		<comments>http://subesh.com.np/2012/02/magdoc-powered-by-scribd-released-on-magento-connect/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 04:09:38 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Free Extensions]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Extensions]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=315</guid>
		<description><![CDATA[MagDoc will give store administrator a feature of managing/displaying document in the Magento storefront powered by richly featured “the world’s largest social reading and publishing platform” &#8211; Scribd. This module provides a unique user experience for reading a document online using the Scribd Reader application embedded in HTML. Get this extension on Magento Connect Features [...]]]></description>
			<content:encoded><![CDATA[<p>MagDoc will give store administrator a feature of managing/displaying document in the Magento storefront powered by richly featured “<strong><em>the world’s largest social reading and publishing platform</em></strong>” &#8211;  <strong>Scribd</strong>. This module provides a unique user experience for reading a document online using the Scribd Reader application embedded in HTML.</p>
<p>Get this extension on <a target="_blank" href="http://www.magentocommerce.com/magento-connect/sp-magdoc-8372.html">Magento Connect</a></p>
<h2>Features</h2>
<ol>
<li>Uses the <strong>free API service</strong> provided by Scribd to upload and manage your document from the Magento administration area.</li>
<li>Upload as much document you want to upload, because there is <strong>no restriction on the storage limit.</strong></li>
<li>Tag your uploaded documents on Scribd.</li>
<li>Set scope <strong>Private</strong> or <strong>Public</strong> for your uploaded document.</li>
<li>Upload and transform any file &#8212; <strong>including PDF, Word and PowerPoint</strong> &#8212; into a web document that’s discoverable through <strong>search engines, shared on social networks and read on billions of mobile devices.</strong></li>
<li>Assign uploaded files to your product which can be shown in the storefront using a multi functional online <strong>Scribd Reader</strong>.</li>
<li>Supports <strong>all the document formats</strong> supported by Scribd. This list of the supported format can be found on <a target="_blank" href="http://www.scribd.com/developers/api?method_name=doc_types" target="_blank"> This Location </a></li>
</ol>
<h2>Installation Guide</h2>
<ol>
<li>Get the extension from<a target="_blank" href="http://www.magentocommerce.com/magento-connect/sp-magdoc-8372.html" target="_blank"> Magento Connect</a>.</li>
<li>Install the extension from Magento Connect Manager.</li>
<li>Voila! Installation completed.</li>
</ol>
<h2>Setting up the Module</h2>
<ol>
<li>Sign up for an account on <a target="_blank" href="http://www.scribd.com"> http://www.scribd.com </a></li>
<li>Get the API Key and Secret Key from Scribd. The procedure for getting your API key and Secret Key is described on <a target="_blank" href="http://support.scribd.com/entries/25453-where-can-i-find-my-api-key">http://support.scribd.com/entries/25453-where-can-i-find-my-api-key</a>.</li>
<li>In Magento backend goto System&#8211;&gt;Configuration&#8211;&gt;MagDoc&#8211;&gt;Settings.</li>
<li>Fill out the API key and Secret Key value you obtain from Scribd and save the settings.</li>
<li>Now the module is set up and ready to be used.</li>
</ol>
<h2>User Guide</h2>
<ol>
<li> Document can be uploaded on Scribd from Magento administration area. In admin area go to <strong>Magdoc&#8211;>Manage Document</strong>. You can add/edit/delete documents from here.</li>
<li>Documents can be assigned to product. Create or Edit any product. A new  option for selecting the document for the product will be visible in the  product edit area. But make sure the attribute “<strong>magdoc_id</strong>” is already  in the attribute set of the product being edited. Select the required  document and save the product.</li>
<li>Visit the product details page on the frontend. The document will be visible using <strong>Scribd Reader</strong>.</li>
</ol>
<h2>Developer Guide</h2>
<p>To display Scribd document in the product details page. This should be placed in appropriate place. Also you can see that the height and width for the Scribd Reader can be configured from layout.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;block type=&quot;magdoc/magdoc&quot; name=&quot;magdoc&quot; template=&quot;magdoc/magdoc.phtml&quot;&gt;
            	&lt;action method=&quot;setDocumentHeight&quot;&gt;&lt;width&gt;600px&lt;/width&gt;&lt;/action&gt;
            	&lt;action method=&quot;setDocumentWidth&quot;&gt;&lt;width&gt;850px&lt;/width&gt;&lt;/action&gt;
 &lt;/block&gt;
</pre>
<p>Here’s a tip for showing the Scribd document on tabs on product details page.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;block type=&quot;catalog/product_view_tabs&quot; name=&quot;product.info.tabs&quot; as=&quot;info_tabs&quot; template=&quot;catalog/product/view/tabs.phtml&quot; &gt;
                    &lt;action method=&quot;addTab&quot; translate=&quot;title&quot; module=&quot;catalog&quot;&gt;
                    	&lt;alias&gt;magdoc&lt;/alias&gt;
                    	&lt;title&gt;Document&lt;/title&gt;
                    	&lt;block&gt;magdoc/magdoc&lt;/block&gt;
                    	&lt;template&gt;magdoc/magdoc.phtml&lt;/template&gt;
                   	&lt;/action&gt;
        &lt;/block&gt;
</pre>
<p>I hope the module will be useful for the store owners. If you have any feedbacks, please report in the comment section below.</p>
<p><br/></p>
<blockquote><p>Disclaimer: <strong>Scribd</strong> is the property of Scribd Inc. This module is NOT the official module of Scribd.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2012/02/magdoc-powered-by-scribd-released-on-magento-connect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Magento Using Eclipse on Ubuntu</title>
		<link>http://subesh.com.np/2012/01/debugging-magento-using-eclipse-on-ubuntu/</link>
		<comments>http://subesh.com.np/2012/01/debugging-magento-using-eclipse-on-ubuntu/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 10:25:13 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=321</guid>
		<description><![CDATA[I&#8217;ve previously posted http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger but currently I think it was just a snub. What I currently do now is far more better approach then the previous one. Here is how you can set up a debugging environment in Ubuntu using Eclipse for debugging Magento. [Note: I am describing here based on Ubuntu.] Step 1: Download [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve previously posted <a href="http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger/" title="http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger/" target="_blank">http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger</a> but currently I think it was just a snub. What I currently do now is far more better approach then the previous one. Here is how you can set up a debugging environment in Ubuntu using Eclipse for debugging Magento.</p>
<p>[Note: I am describing here based on Ubuntu.]</p>
<p><strong>Step 1: Download and Install Eclipse</strong><br />
<a href="http://www.eclipse.org/pdt/downloads/" title="Download" target="_blank">Download</a> and Install Eclipse. Choose the relevant package to download. Unzip the package and copy to some location. Lets say /home/user/ Please note that the Eclipse IDE requires that a Java Runtime Environment (JRE) be installed on your machine to run. Java SE 5 or greater is recommended.</p>
<p><strong>Step 2: Setting up PHP Project</strong><br />
Next thing you have to do is to setup the project in Eclipse. Open the Eclipse IDE and it will ask for your Workspace. Browse to your workspace (Where your Magento site is running locally) or by default point it to <strong><em>/var/www</em></strong> and click OK. Now click on <strong>File&#8211;>New &#8211;> New PHP Project</strong>, and add your folder name on Project Name and click Finish. Eclipse will take few time on building your project, so take a coffee break if you want and be back in few minutes to go through the steps below.</p>
<p><strong>Step 3: Installing X-Debugger</strong></p>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install php5-xdebug
</pre>
<p><strong>Step 4: Configure X-Debugger</strong><br />
Type this in your command prompt.</p>
<pre class="brush: bash; title: ; notranslate">
sudo gedit /etc/php5/apache2/conf.d/xdebug.ini
</pre>
<p>And add this settings on the .ini file</p>
<pre class="brush: bash; title: ; notranslate">
xdebug.remote_enable=1
</pre>
<p>And restart the apache server.</p>
<pre class="brush: bash; title: ; notranslate">
sudo /etc/init.d/apache2 restart
</pre>
<p><strong>Step 5: Debug Configuration on Eclipse</strong></p>
<p>On menu click <strong>Window&#8211;>Preference</strong>. Find <strong>PHP&#8211;>Debug</strong> Node in the left. When you click Debug you can see screen like this. <strong>Select PHP Debugger &#8211; XDebug</strong>.</p>
<p><img alt="" src="https://lh4.googleusercontent.com/-VPXpprs69Zs/TyJt9pH7SUI/AAAAAAAAAIw/xNflpZ_t3GY/w612-h503-k/php-Debug.png" title="PHP - Eclipse - Debugger Settings" class="aligncenter" width="611" height="502" /></p>
<p>To Set Server click <strong>PHP Servers</strong> and add new server as follows and click Finish.</p>
<p><img alt="" src="https://lh3.googleusercontent.com/-A9yecKpDgNk/TyJwssyq9MI/AAAAAAAAAJU/uwWKVvWvmiM/w306-h222-n-k/Server.png" title="PHP-Eclipse-Magento Server Configuration" class="aligncenter" width="306" height="222" /></p>
<p><strong>Step 6: Configuring debug conf for Magento Projects</strong></p>
<p>On menu click<strong> Run&#8211;> Debug Configurations</strong>. Find <strong>PHP Web Page</strong> and Right click for adding new configuration. Add something similar to like this.</p>
<p><img alt="" src="https://lh6.googleusercontent.com/-e0CrUe0yLyE/TyJ3RqF5VPI/AAAAAAAAAJ0/0btGPXdLfcA/w291-h222-n-k/Debug%2BSettings.png" title="PHP - Eclipse - Magento - Web Page configuration." class="aligncenter" width="291" height="222" /></p>
<p><strong>Step 7: Add Break-Point and start debugging</strong></p>
<p>Now almost all the settings are done. Now you can just add a break-point on your code and start debugging your script by clicking the BUG icon on the top bar.</p>
<p>Few tips though before you start.</p>
<ol>
<li> Set up an external browser to run your debug configuation. Go to <strong>Window&#8211;>Preference</strong> and type in <strong><em>web browse</em>r</strong> in the top left search. And you will get a result. Click on Web Browser to select Use External Web Browser. If that is not clickable first click the restore default button and then the external web browser should be clickable.</li>
<li> You can enable multi-session debug, because you do not want to always click the debug button after each debug end. For that go to preference. Search for debug. Find <strong> PHP &#8211;> Debug &#8211;>Installed Debugger</strong>. Click the <strong>XDebug</strong> and then click configure. You can then Check the <strong>Use Multisession</strong> checkbox and save.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2012/01/debugging-magento-using-eclipse-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Happy Dashain Holidays!</title>
		<link>http://subesh.com.np/2011/09/happy-dashain-holidays/</link>
		<comments>http://subesh.com.np/2011/09/happy-dashain-holidays/#comments</comments>
		<pubDate>Fri, 30 Sep 2011 09:19:49 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=305</guid>
		<description><![CDATA[Its time for all of Nepal to mark their &#8220;only&#8221; long term holidays. It&#8217;d Dashain time and don&#8217;t expect me to come up with things during this week long holidays. Image courtesy: nepalifonts.blogspot.com]]></description>
			<content:encoded><![CDATA[<p>Its time for all of Nepal to mark their &#8220;only&#8221; long term holidays. It&#8217;d Dashain time and don&#8217;t expect me to come up with things during this week long holidays.<br />
Image courtesy: nepalifonts.blogspot.com</p>
<p><a href="http://subesh.com.np/2011/09/happy-dashain-holidays/dashain-cards2011_page_2/" rel="attachment wp-att-306"><img src="http://subesh.com.np/wp-content/uploads/2011/09/dashain-cards2011_Page_2-300x240.jpg" alt="" title="dashain cards2011_Page_2" width="300" height="240" class="aligncenter size-medium wp-image-306" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2011/09/happy-dashain-holidays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Query In Magento a Zend Approach [Updated]</title>
		<link>http://subesh.com.np/2011/08/custom-query-in-magento-a-zend-approach/</link>
		<comments>http://subesh.com.np/2011/08/custom-query-in-magento-a-zend-approach/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 10:11:05 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=300</guid>
		<description><![CDATA[I&#8217;ve already mentioned about custom query in Magento, before but now I think its time to upgrade that method to next level because it would always be good to have standard code for reference.So it is just a new improved way of using a custom query. First of all we will need is a connection [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve already mentioned about<a href="http://subesh.com.np/2009/12/using-custom-query-in-magento/"> custom query in Magento</a>, before but now I think its time to upgrade that method to next level because it would always be good to have standard code for reference.So it is just a new improved way of using a custom query.<br />
First of all we will need is a connection instance. Lets use default_setup instance because it can used for read and write purpose.</p>
<pre class="brush: php; title: ; notranslate">
$connection = Mage::getSingleton('core/resource')-&gt;getConnection('default_setup');
</pre>
<p>Then we will use this connection to instanciate Zend_Db_Select object and write query like</p>
<pre class="brush: php; title: ; notranslate">
$select = new Zend_Db_Select($connection);
$table = 'catalog_product_index_price';
$select-&gt;from($table, array('entity_id'))
	-&gt;where('entity_id = ?', $entityId);

// Getting result

$result = $select-&gt;query();
$rowCount = $result-&gt;rowCount();

if ($rowCount) {
	foreach ($result-&gt;fetchAll() as $data) {
		return $data['entity_id'];
	}
}
</pre>
<p>The above one is for select but what about inserting data? It is simple as well. All you have to do is create an associative array of data to be inserted and use connection to add data. For example</p>
<pre class="brush: php; title: ; notranslate">
$connection = Mage::getSingleton('core/resource')-&gt;getConnection('default_setup');
$table = 'catalog_product_index_price';

$insertData = array();
$insertData ['price'] = $productPrice;
$insertData ['final_price'] = $productPrice;
$insertData ['min_price'] = $productPrice;
$insertData ['max_price'] = $productPrice;
$insertData ['tier_price'] = $productPrice;

$connection-&gt;insert($table, $insertData);
</pre>
<p>I think this should be a good enough code for using custom query in Magento. About Zend_Db_Select please visit <a href="http://framework.zend.com/manual/en/zend.db.select.html">http://framework.zend.com/manual/en/zend.db.select.html</a>.</p>
<p><strong>[UPDATE]</strong></p>
<p>If you want to update the data with custom query and have a condition then you can send the conditions as array as third params to update function. For example.</p>
<pre class="brush: php; title: ; notranslate">
$connection = Mage::getSingleton('core/resource')-&gt;getConnection('default_setup');
$table = 'catalog_product_index_price';

$updateCond = array(); // Update condition array container.
$insertData = array();
$insertData ['price'] = $productPrice;
$insertData ['final_price'] = $productPrice;
$insertData ['min_price'] = $productPrice;
$insertData ['max_price'] = $productPrice;
$insertData ['tier_price'] = $productPrice;

$updateCond [] = 'store_id = 0';
$updateCond [] = 'entity_id = 3';

$connection-&gt;insert($table, $insertData, $updateCond);
</pre>
<p>Happy Brogramming!!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2011/08/custom-query-in-magento-a-zend-approach/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Generating Invoice/Order&#039;s Next Increment ID in Magento</title>
		<link>http://subesh.com.np/2010/12/generating-invoiceorders-next-increment-id-in-magento/</link>
		<comments>http://subesh.com.np/2010/12/generating-invoiceorders-next-increment-id-in-magento/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 08:32:40 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=294</guid>
		<description><![CDATA[Magento has its own way of generating increment ID for new invoices and new orders after they are saved. But how about knowing them before hand, i.e before the invoice or the order is created! Lets first understand the working of those increment ID generation before jumping to the code. As all of us must [...]]]></description>
			<content:encoded><![CDATA[<p>Magento has its own way of generating increment ID for new invoices and new orders after they are saved. But how about knowing them before hand, i.e before the invoice or the order is created! Lets first understand the working of those increment ID generation before jumping to the code. As all of us must have known there are &#8220;Entity Types&#8221; in Magento. And those &#8220;Entity Types&#8221; are stored in table named <strong><em>eav_entity_type</em></strong>. If you look into that table for <strong>entity_type_code = order or invoice</strong>, in <strong>increment_model</strong> column you can see the Model alias used to generate new increment ID code. Lets take the case of invoice..so the increment model is <strong><em>eav/entity_increment_numeric</em></strong> and additionally this increment is store dependent as for this row <strong><em>increment_per_store</em></strong> is set to 1.</p>
<p>Next place to look into will be .. Yes! the model <strong><em>eav/entity_increment_numeric</em></strong>. And if you see the model class <strong>Mage_Eav_Model_Entity_Increment_Numeric</strong> there is only one Method in this class the <em>public function getNextId()</em> which is responsible to the the Next increment ID, needless to say its parent has other methods as well since you might have already understood. So if some how you can trigger the right Increment Model for any entity type and the call this method, you must get the next increment ID of order/invoice/shippment.</p>
<p>That was the &#8220;prose&#8221; part now lets get down to the &#8220;code poetry&#8221;. Here&#8217;s how you first find the appropriate increment ID and then fetch the new Increment ID.</p>
<pre class="brush: php; title: ; notranslate">
            //Get the Entity Type Increment Model you want, our case invoice
            // @var $entity_type_model Mage_Eav_Model_Entity_Type
            $entity_type_model=Mage::getSingleton('eav/config')-&gt;getEntityType('invoice');

            //Triggering the getNextId() of the Increment Model
            //@var $invoiceNew Mage_Sales_Model_Order_Invoice
            $new_incr_id = $entity_type_model-&gt;fetchNewIncrementId($invoiceNew-&gt;getOrder()-&gt;getStoreId());
</pre>
<p>Now, you have the generated Invoice Increment ID. This can be helpful in cases when you want to do something else before Invoice is created but you want to now the Increment Id before hand. Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/12/generating-invoiceorders-next-increment-id-in-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding Custom Javascript on Admin form in Magento (Backend)</title>
		<link>http://subesh.com.np/2010/09/adding-custom-javascript-on-admin-form-in-magento-backend/</link>
		<comments>http://subesh.com.np/2010/09/adding-custom-javascript-on-admin-form-in-magento-backend/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 12:25:01 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=271</guid>
		<description><![CDATA[Sometimes in Magento, while creating a custom module we need to add our custom Javascript code in our Admin form. These Admin forms we create are extened from the Magento&#8217;s core form widget. So there is a less flexibiliy of adding a custom Javasccript code in such types of Admin forms. What to do if [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes in Magento, while creating a custom module we need to add our custom Javascript code in our Admin form. These Admin forms we create are extened from the Magento&#8217;s core form widget. So there is a less flexibiliy of adding a custom Javasccript code in such types of Admin forms. What to do if you really need to add some custom Javascripts to give user a better user experience? In this post I&#8217;d like to point two conditions how/where to add such custom Javascript codes in the Form class, so that you can give user an interactive Admin form.</p>
<p>The two conditions are:</p>
<ol>
<li>If an element of the form already has a value, disable that form element.</li>
<li>On triggering an event by acting on some form element to change other form&#8217;s element&#8217;s attribute value.</li>
</ol>
<h2>If an element of the form already has a value, disable that form element</h2>
<p>Lets take an example of core&#8217;s customer creation Admin form. What we can see while creating a customer from Admin end, the field &#8220;Associate to Website&#8221; is available to change for the first time. But when you are editing a customer info the very field is disabled. Lets see how this can be acheivable. If you look into <strong>Mage_Adminhtml_Block_Customer_Edit_Tab_Account</strong> class you can see the following chunk of code.</p>
<pre class="brush: php; title: ; notranslate">
  if ($customer-&gt;getId()) {
            $form-&gt;getElement('website_id')-&gt;setDisabled('disabled');
            $form-&gt;getElement('created_in')-&gt;setDisabled('disabled');
        }
</pre>
<p>What this does is checks for the Id of the customer if it is present the form elements disabled attribute is set to disabled. So initially while creating a new customer this condition is not fulfilled while on edition of the customer data the condition is fulfilled and hence the form element <em>website_id</em> and the <em>created_in</em> are disabled. This was just an example, you can also write similar conditions for your custom form. Suppose your data for the current form is in <em>$formData</em> variable and then by checking certain field value you can add similar condition.</p>
<pre class="brush: php; title: ; notranslate">
$formData=Mage::registry('current_custom_data');

if(!empty($formData-&gt;getMyField())){
	$targetElement=$form-&gt;getElement(&quot;my_field&quot;);

	//For Disabling the field (Value will not be posted on form submit)
	$targetElement-&gt;setDisabled('disabled');

	//Or for making the field readonly
	$targetElement-&gt;setReadonly(true);

}
</pre>
<h2>On triggering an event by acting on some form element to change other form&#8217;s element&#8217;s attribute value</h2>
<p>Lets take the same customer edition page, you can see a checkbox with label <strong>Send auto-generated password</strong>. If you check that checkbox then the <strong>New Password</strong> textfield above it gets disabled. To get the similar interactivity for custom form you will have to do as following.</p>
<pre class="brush: php; title: ; notranslate">
$eventElem=$fieldset-&gt;addField('nocode', 'checkbox', array(
                'label' =&gt; Mage::helper('customer')-&gt;__('Event Element'),
                'name'  =&gt; 'eventelem',
                'id'    =&gt; 'eventelem',
				'value'=&gt;1,
				'onclick'=&gt;'modifyTargetElement(this)',
            ));

		$eventElem-&gt;setAfterElementHtml('&lt;script&gt;
			function modifyTargetElement(checkboxElem){
				if(checkboxElem.checked){
					$(&quot;target_element&quot;).disabled=true;
				}
				else{
					$(&quot;target_element&quot;).disabled=false;
				}
			}
		&lt;/script&gt;');
</pre>
<p>What you can see is after an element of a form is initiallized you can add HTML codes (which of course for us is only Javascript code) by calling a <strong>setAfterElementHtml</strong> method and write the implementation of the function called on the event of the Event element.<br />
I&#8217;ve tried to be more explanatory as possible, if you still have any confusion there is always a comment box below. Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/09/adding-custom-javascript-on-admin-form-in-magento-backend/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Adding CSS Class name to My Account Link (Anchor Tag) in Magento through XML Layout</title>
		<link>http://subesh.com.np/2010/09/adding-css-class-name-to-my-account-link-anchor-tag-in-magento-through-xml-layout/</link>
		<comments>http://subesh.com.np/2010/09/adding-css-class-name-to-my-account-link-anchor-tag-in-magento-through-xml-layout/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 11:17:31 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=264</guid>
		<description><![CDATA[At the first instance I thought WTH! must be pretty simple, add params in XML layout and &#8220;Voila!&#8220;. But later I found that it was not simpler as I thought. I had to get into the addLink method for sometime (1/2hr) and finally I came up with correct structure of XML layout. At the end [...]]]></description>
			<content:encoded><![CDATA[<p>At the first instance I thought WTH! must be pretty simple, add params in XML layout and &#8220;<strong>Voila!</strong>&#8220;. But later I found that it was not simpler as I thought. I had to get into the addLink method for sometime <strong>(1/2hr)</strong> and finally I came up with correct structure of XML layout. At the end it again seemed simple though, but it needed a healthy effort.</p>
<p>Here&#8217;s the XML structure of layout from <em>customer.xml</em> where you add class to <strong>My Account link</strong>.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- customer.xml--&gt;
    &lt;reference name=&quot;top.links&quot;&gt;
        &lt;action method=&quot;addLink&quot; translate=&quot;label title&quot; module=&quot;customer&quot;&gt;
			&lt;label&gt;My Account&lt;/label&gt;
			&lt;url helper=&quot;customer/getAccountUrl&quot;/&gt;
			&lt;title&gt;My Account&lt;/title&gt;
			&lt;prepare/&gt;
			&lt;urlParams/&gt;
			&lt;class/&gt;
			&lt;position&gt;10&lt;/position&gt;
			&lt;aParams&gt;
				&lt;class&gt;my-class-name&lt;/class&gt;
			&lt;/aParams&gt;
		&lt;/action&gt;
    &lt;/reference&gt;
&lt;!-- customer.xml--&gt;
</pre>
<p>One notable thing in the structure above is the <strong>aParams</strong> which is responsible for adding the class to the Anchor tag, not the List tag. Hope this helps someone! Happy Coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/09/adding-css-class-name-to-my-account-link-anchor-tag-in-magento-through-xml-layout/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Working with Ajax and JSON Objects in Magento [Case: Ajax Powered Login Functionality]</title>
		<link>http://subesh.com.np/2010/08/working-ajax-json-objects-magento-case-ajax-powered-login-functionality/</link>
		<comments>http://subesh.com.np/2010/08/working-ajax-json-objects-magento-case-ajax-powered-login-functionality/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 08:46:08 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=278</guid>
		<description><![CDATA[Previously I have written about Working With Ajax in Magento. And after a huge response I received from that post I was compelled to write more on implementing Ajax in Magento. And this time I want to say additionally about handling JSON (JavaScript Object Notation) along with Ajax, within the Magento enviornment. JSON Objects and [...]]]></description>
			<content:encoded><![CDATA[<p>Previously I have written about <a href="http://subesh.com.np/2009/11/working-with-ajax-in-magento/">Working With Ajax in Magento</a>. And after a huge response I received from that post I was compelled to write more on implementing Ajax in Magento. And this time I want to say additionally about handling JSON (<strong>JavaScript Object Notation</strong>) along with Ajax, within the Magento enviornment. JSON Objects and Ajax can be very helpful technique to get the work done. You can learn about JSON from <a href="http://www.json.org/">Here</a>.</p>
<p>I will try to describe this issue by taking a case of changing the Magento&#8217;s login functionality to a Ajax powered login functionality. So after this you will be able to implement a login function in a pop-up div in any page, unlike the default Magento&#8217;s seperate login page. I will leave the pop-up div part to you and get started with the real business (AJAX and JSON).</p>
<p>Presuming that you will use <strong>Mini-Login</strong> form. Here is how you proceed.</p>
<ol>
<li>Change Submit type button to Button type button.</li>
<li>Register OnClick Javascript event of that button and its Handler</li>
<li>In the Handler function call Ajax Request for login</li>
<li>Show Error Message or redirect to customer Dashboard</li>
</ol>
<p>Your mini.login.phtml should be like this</p>
<pre class="brush: xml; title: ; notranslate">
&lt;form action=&quot;&lt;?php //echo $this-&gt;getPostActionUrl() ?&gt;&quot; id=&quot;mini-login-form&quot; method=&quot;post&quot;&gt;
    &lt;fieldset&gt;
        &lt;p&gt;&lt;label&gt;&lt;?php echo $this-&gt;__('Email') ?&gt;:&lt;/label&gt; &lt;input name=&quot;login[username]&quot; class=&quot;input-text&quot; /&gt;&lt;/p&gt;
        &lt;p&gt;&lt;label&gt;&lt;?php echo $this-&gt;__('Password') ?&gt;:&lt;/label&gt; &lt;input name=&quot;login[password]&quot; class=&quot;input-text&quot; /&gt;&lt;/p&gt;
        &lt;p&gt;&lt;input type=&quot;button&quot; onClick=&quot;handlerFunction()&quot; value=&quot;&lt;?php echo $this-&gt;__('Login') ?&gt;&quot; /&gt;&lt;/p&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
function handlerFunction(){

// Write These codes only after form Validation

// Making Ajax Request
		var request = new Ajax.Request(
			//Defining Ajax Request URL, We are calling custom Controller Ns_Mylogin_AccountController Class (Defined Below)
        	'&lt;?php echo $this-&gt;getUrl(&quot;mylogin/account/loginPost&quot;) ?&gt;',
           	{
            	method: 'post',
                onComplete: function(transport){ // Defining Complete Callback Function

                	// Getting Ajax Response Text Which is JSON Object
                	var jsonResponse=transport.responseText;
                	//Checking JSON Objects property and performing related action
                	// You will understand the response Text format after going through the controller description (Below)
                	if(jsonResponse.error){
                		alert(&quot;Error Occured&quot;);
						return false;
                	}
                	else{
                		window.location.href=jsonResponse.url;
                	}
                },
                parameters: Form.serialize($(&quot;mini-login-form&quot;))	// Seriallizing the form input values
        	}
        );
}
//--&gt;
&lt;/script&gt;
</pre>
<p>Please see inline comments for better understanding. Now our next set should be setting up our custom controller. I&#8217;ll not get into details of setting up modules and all but directly to our controller class <strong>Ns_Mylogin_AccountController</strong>. What I&#8217;ve done is just taken the core&#8217;s  <strong>loginPostAction </strong>function of <strong>Mage_Customer_AccountController</strong> and added some codes there. Please see there is a comment on each line added apart from the default Magento&#8217;s core code.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once(&quot;Mage/Customer/controllers/AccountController.php&quot;);
class Ns_Mylogin_AccountController extends Mage_Customer_AccountController{
	/**
	 * Login post action
	 * @return JSON Object
	 */
	public function loginPostAction()
	{
		// Added Line #1
		$result[&quot;error&quot;]=0;

		$session = $this-&gt;_getSession();

		if ($this-&gt;getRequest()-&gt;isPost()) {
			$login = $this-&gt;getRequest()-&gt;getPost('login');
			if (!empty($login['username']) &amp;amp;&amp;amp; !empty($login['password'])) {
				try {
					$session-&gt;login($login['username'], $login['password']);
					if ($session-&gt;getCustomer()-&gt;getIsJustConfirmed()) {
						$this-&gt;_welcomeCustomer($session-&gt;getCustomer(), true);
					}
				} catch (Mage_Core_Exception $e) {
					switch ($e-&gt;getCode()) {
						case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
							//Added Line #2
							$result[&quot;error&quot;]=1;
							$message = Mage::helper('customer')-&gt;__('This account is not confirmed. &lt;a href=&quot;%s&quot;&gt;Click here&lt;/a&gt; to resend confirmation email.', 						Mage::helper('customer')-&gt;getEmailConfirmationUrl($login['username']));
							break;
						case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
							//Added Line #3
							$result[&quot;error&quot;]=1;
							$message = $e-&gt;getMessage();
							break;
						default:
							//Added Line #4
							$result[&quot;error&quot;]=1;
							$message = $e-&gt;getMessage();
					}
					$session-&gt;addError($message);
					$session-&gt;setUsername($login['username']);
				} catch (Exception $e) {
					// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
				}
			} else {
				//Added Line #5
				$result[&quot;error&quot;]=1;
				$session-&gt;addError($this-&gt;__('Login and password are required'));
				//Added Line #6
				$this-&gt;getResponse()-&gt;setBody(Mage::helper('core')-&gt;jsonEncode($result));
			}
		}
		//Added Line #7
		$result[&quot;url&quot;]=$this-&gt;_loginPostRedirect();
		//Added Line #8
		$this-&gt;getResponse()-&gt;setBody(Mage::helper('core')-&gt;jsonEncode($result));
	}
</pre>
<p>What I&#8217;ve done is added an array <strong>$result</strong> that will hold value if there is error or not while processing the user&#8217;s request. If there is error that array will hold $result['error']=1 else it will be as initiallized in <em>Added Line #1</em>. From <em>Added Line #2</em> through <em>Added Line #5</em>, we have various condition to check for error and set our <strong>$result</strong> variable.</p>
<p>On <em>Added Line #7</em> we have called another function (which we we rewrite as well) that will give us the url location identifying which location should be redirect after successful login. The implementation of function is given below. Finally in <em>Added Line #8</em> and <em>Line #6</em> we have encoded our $result array into <strong>JSON</strong> format and send as the response.</p>
<p>For visuallization our $result array will be one of the following.</p>
<ol>
<li> Case (No Error) : $result["error"]=0; $result["url"]=&#8221;SOME Redirect URL&#8221;</li>
<li> Case (Error) 	 :	$result["error"]=1;</li>
</ol>
<p>This JSON encoded response will be then used by the ajax call back function defined and perform related action.</p>
<p>Here&#8217;s the <strong>_loginPostRedirect()</strong> function which I mentioned (Added Line #7).</p>
<pre class="brush: php; title: ; notranslate">
/**
	 * Define target URL and redirect customer after logging in
	 */
	protected function _loginPostRedirect()
	{
		$session = $this-&gt;_getSession();

		if (!$session-&gt;getBeforeAuthUrl() || $session-&gt;getBeforeAuthUrl() == Mage::getBaseUrl() ) {

			// Set default URL to redirect customer to
			$session-&gt;setBeforeAuthUrl(Mage::helper('customer')-&gt;getAccountUrl());

			// Redirect customer to the last page visited after logging in
			if ($session-&gt;isLoggedIn())
			{
				if (!Mage::getStoreConfigFlag('customer/startup/redirect_dashboard')) {
					if ($referer = $this-&gt;getRequest()-&gt;getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME)) {
						$referer = Mage::helper('core')-&gt;urlDecode($referer);
						if ($this-&gt;_isUrlInternal($referer)) {
							$session-&gt;setBeforeAuthUrl($referer);
						}
					}
				}
				else if ($session-&gt;getAfterAuthUrl()) {
					$session-&gt;setBeforeAuthUrl($session-&gt;getAfterAuthUrl(true));
				}
			} else {
				$session-&gt;setBeforeAuthUrl(Mage::helper('customer')-&gt;getLoginUrl());
			}
		} else if ($session-&gt;getBeforeAuthUrl() == Mage::helper('customer')-&gt;getLogoutUrl()) {
			$session-&gt;setBeforeAuthUrl(Mage::helper('customer')-&gt;getDashboardUrl());
		}
		else {
			if (!$session-&gt;getAfterAuthUrl()) {
				$session-&gt;setAfterAuthUrl($session-&gt;getBeforeAuthUrl());
			}
			if ($session-&gt;isLoggedIn()) {
				$session-&gt;setBeforeAuthUrl($session-&gt;getAfterAuthUrl(true));
			}
		}
		// Changed Here
		return $session-&gt;getBeforeAuthUrl(true);
	}
</pre>
<p>You can download the code From <a href="http://code.google.com/p/subeshexamples/downloads/detail?name=Ajax_Json_Magento_subesh.com.np.zip#makechanges">Here</a>.</p>
<p>Hope it helps! Happy Coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/08/working-ajax-json-objects-magento-case-ajax-powered-login-functionality/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Displaying Currency code after the price value in Magento</title>
		<link>http://subesh.com.np/2010/08/displaying-currency-code-after-the-price-value-in-magento/</link>
		<comments>http://subesh.com.np/2010/08/displaying-currency-code-after-the-price-value-in-magento/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 11:53:38 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=287</guid>
		<description><![CDATA[I had a time to research on Magento&#8217;s currency format and its display on Magento webshop. I then came across a block where I could change the format of currency display, in this case I am talking about moving the currency symbol to the right of the price value. In other words I found a [...]]]></description>
			<content:encoded><![CDATA[<p>I had a time to research on Magento&#8217;s currency format and its display  on Magento webshop. I then came across a block where I could change the  format of currency display, in this case I am talking about moving the  currency symbol to the right of the price value. In other words I found a  way to show $10.00 as 10.00$. Notice the <strong>$</strong> (Dollar) sign moving at the right of the price value.<br />
Here&#8217;s a description of how this can be achievable. The basic idea is to rewrite <strong>Mage_Core_Model_Locale</strong> class&#8217;s currency function and add additional code. First you must write a rewrite code in your module&#8217;s<strong> config.xml</strong>.</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;core&gt;
 &lt;rewrite&gt;
 &lt;locale&gt;Namespace_Module_Model_Locale&lt;/locale&gt;
 &lt;/rewrite&gt;
 &lt;/core&gt;
 </pre>
<p>Then in <strong>Namespace_Module_Model_Locale</strong> class you can add the following code.</p>
<pre class="brush: php; title: ; notranslate">
 class Namespace_Module_Model_Locale extends Mage_Core_Model_Locale{
 /*
 * Code: subesh.com.np
 */

public function currency($currency)
 {
 Varien_Profiler::start('locale/currency');
 if (!isset(self::$_currencyCache[$this-&gt;getLocaleCode()][$currency])) {
 try {
 $currencyObject = new Zend_Currency($currency, $this-&gt;getLocale());

// Additionally Added Code
 // The options array's position key has other values as well.

// 	Zend_Currency::STANDARD
 // 	Zend_Currency::RIGHT
 //	Zend_Currency::LEFT

$options = array(
 'position'	=&gt; Zend_Currency::RIGHT
 );

$currencyObject-&gt;setFormat($options);

// END Additionally Added Code

} catch (Exception $e) {
 $currencyObject = new Zend_Currency($this-&gt;getCurrency(), $this-&gt;getLocale());
 $options = array(
 'name'      =&gt; $currency,
 'currency'  =&gt; $currency,
 'symbol'    =&gt; $currency
 );
 $currencyObject-&gt;setFormat($options);
 }

self::$_currencyCache[$this-&gt;getLocaleCode()][$currency] = $currencyObject;
 }
 Varien_Profiler::stop('locale/currency');
 return self::$_currencyCache[$this-&gt;getLocaleCode()][$currency];
 }

}
</pre>
<p>You can see the comment of the code above for more detail understanding.</p>
<p><strong><em>P.S: Be informed that you need to change the Class Name you are about to create on the basis of your Namespace and Module name.</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/08/displaying-currency-code-after-the-price-value-in-magento/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento: Setting Up a Default Shipping Method on Cart Page</title>
		<link>http://subesh.com.np/2010/08/magento-setting-default-shipping-method-cart-page/</link>
		<comments>http://subesh.com.np/2010/08/magento-setting-default-shipping-method-cart-page/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 02:03:45 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=262</guid>
		<description><![CDATA[I recently came to a situation where I need to show a shipping price amount on cart before selecting the shipping address from the checkout page. Basically shipping price is shown after the user has added the shipping address and selected the shipping method. So to show shipping price on cart page load, I needed [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came to a situation where I need to show a shipping price amount on cart before selecting the shipping address from the checkout page. Basically shipping price is shown after the user has added the shipping address and selected the shipping method. So to show shipping price on cart page load, I needed to find out the following. Shipping Address (Actually only<strong> country_id</strong> will work) Shipping Method (Set to Flatrate in the code below) So what I did was first check if the user has already specified the shipping address (when user have added the shipping address in the checkout page and navigated back to cart page). If the shipping address is not present then I checked if the user is logged in and checked for default shipping address of the customer and used its country_id (if present), but if the user is not logged in or default shipping address is not present then I set the shipping address (<strong>country_id</strong>) to some country <strong>(NL).</strong>After setting the country I then set the shipping method and then saved the quote so that the prices are calculated.Here&#8217;s the snippet.</p>
<pre class="brush: php; title: ; notranslate">
/*** Setting Default Shipping Method
 * Checking If Quote Already Has Address Or Not
 * - If Yes then leave as it is
 * - Else check if Customer has default Shipping Address or Not
 * -- Yes then get Default Shipping Address and set Shipping Method
 * -- No Set Default Shipping address to NL*/
 if(!Mage::getSingleton('checkout/type_onepage')-&gt;getQuote()-&gt;getShippingAddress()-&gt;getCountryId()){
		$customerSession=Mage::getSingleton(&quot;customer/session&quot;);
		if($customerSession-&gt;isLoggedIn()){
		$customerAddress=$customerSession-&gt;getCustomer()-&gt;getDefaultShippingAddress();
			if($customerAddress-&gt;getId()){
			$customerCountry=$customerAddress-&gt;getCountryId();
				$shipping = Mage::getSingleton('checkout/type_onepage')-&gt;getQuote()-&gt;getShippingAddress()-&gt;setCountryId($customerCountry)-&gt;setShippingMethod('flatrate_flatrate')-&gt;save();
		}else{
			$shipping = Mage::getSingleton('checkout/type_onepage')-&gt;getQuote()-&gt;getShippingAddress()-&gt;setCountryId('NL')-&gt;setShippingMethod('flatrate_flatrate')-&gt;save();
			}
		}
	}
</pre>
<p>Cheers!</p>
<p>[UPDATE]<br />
The original solution seems to show some issue. Thanks to the great reader of this blog the &#8220;perfect&#8221; solution for this case can be found in comments. As always new and better solutions are always welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/08/magento-setting-default-shipping-method-cart-page/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

