<?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 &#187; Block</title>
	<atom:link href="http://subesh.com.np/tag/block/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>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>Solution: Error Message Not Showing up in Frontend in Magento</title>
		<link>http://subesh.com.np/2010/05/solution-error-message-showing-frontends-magento/</link>
		<comments>http://subesh.com.np/2010/05/solution-error-message-showing-frontends-magento/#comments</comments>
		<pubDate>Tue, 04 May 2010 12:22:40 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=238</guid>
		<description><![CDATA[I recently got to a situation where I needed to add a new frontend template for some module and after some action show the error or success message. Not the first time though . Interesting thing was even if I added this code in the PHTML file. It did not work. Yes, after adding this [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got to a situation where I needed to add a new frontend template for some module and after some action show the error or success message. Not the first time though <img src='http://subesh.com.np/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . Interesting thing was even if I added this code in the PHTML file.</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php echo $this-&gt;getMessagesBlock()-&gt;getGroupedHtml() ?&gt;
</pre>
<p>It did not work. Yes, after adding this block it had worked before. In my case, the probable case might be that I had called the module&#8217;s template from CMS page. In other case it should work. So, I looked for work around and the following did the trick.</p>
<pre class="brush: php; title: ; notranslate">
// Getting Messages from Session
$messages=Mage::getSingleton(&quot;customer/session&quot;)-&gt;getMessages();

// Creating Block Mage_Core_Block_Messages
// Setting Message
// echoing the Message's HTML
echo $this-&gt;getLayout()-&gt;createBlock(&quot;core/messages&quot;)-&gt;setMessages($messages)-&gt;getGroupedHtml();
</pre>
<p>The Error/Success or Notice messages are set on session. So what I did was take those message/s from the session and create a new block, same as what <strong>$this->getMessagesBlock()</strong> might have called, and set those message to the created block and echoed its HTML.</p>
<p>Clever? or not?</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/05/solution-error-message-showing-frontends-magento/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Block From the Code in Magento</title>
		<link>http://subesh.com.np/2009/12/creating-block-code-magento/</link>
		<comments>http://subesh.com.np/2009/12/creating-block-code-magento/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 13:15:43 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Map Type]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=164</guid>
		<description><![CDATA[Here are some methods of creating block by code in Magento. This type of code can be used directly in template, not need to create a layout file or add a child node inside already existing layout file. You can use this to echo a different type of block inside already loading block and template. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some methods of creating block by code in Magento. This type of code can be used directly in template, not need to create a layout file or add a child node inside already existing layout file. You can use this to echo a different type of block inside already loading block and template.</p>
<pre class="brush: php; title: ; notranslate">
// Directly in the PHTML where you want to show the block
&lt;?php
echo $this-&gt;getLayout()-&gt;createBlock(&quot;module/block&quot;)-&gt;setTemplate(&quot;module/page.phtml&quot;)-&gt;toHtml();
?&gt;
</pre>
<p>What we have actually done is just load the layout and create an instance of a block class defined inside its paramerter, then assigned a template to the block and finally echoed as html. Simple! The code above will be equivalent to what we do as following in layout and in template file.</p>
<pre class="brush: xml; title: ; notranslate">
// In layout
&lt;block type=&quot;module/block&quot; name=&quot;module.name&quot; template=&quot;module/page.html&quot;/&gt;
</pre>
<pre class="brush: php; title: ; notranslate">
&lt;?php
// In parent PHTML
$this-&gt;getChildHtml(&quot;module.name&quot;);
?&gt;
</pre>
<p>May be helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/creating-block-code-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Rescent Rating Summary of a product in Magento</title>
		<link>http://subesh.com.np/2009/12/rescent-rating-summary-product-magento/</link>
		<comments>http://subesh.com.np/2009/12/rescent-rating-summary-product-magento/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 13:05:43 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=162</guid>
		<description><![CDATA[Magento has a default option to show the overall rating&#8217;s summary of the product, which is shown in the product view page. This summary is based on all the review posted and approved for the particular product. In the summary the stars are shown accordingly, by taking the sum of all reviews and calculating the [...]]]></description>
			<content:encoded><![CDATA[<p>Magento has a default option to show the overall rating&#8217;s summary of the product, which is shown in the product view page. This summary is based on all the review posted and approved for the particular product. In the summary the stars are shown accordingly, by taking the sum of all reviews and calculating the average rating. But I had a case where I needed to show those star ratings, only based on the last approved user ratings. What I did was just a small tweak in the Magento&#8217;s default working!</p>
<p>Magento gets all the reviews and processes it accordingly, so what I did was just added limit filter to get the rescent rating only, and left the Magento default working do the rest. Tricky! huh&#8230;.</p>
<p>Here the block that can achieve the same.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class Namespace_Comment_Block_Comment extends Mage_Review_Block_Product_View
{
	/**
	 * Get only Latest review.
	 * Only adding PageSize filter to the collection sent by the parent::getReviewsCollection(), since parent already
	 * sorts it by date.
	 */
	public function getRescentReview ()
	{
		$collection = $this-&gt;getReviewsCollection()-&gt;setPageSize(1);
		return $collection;
	}
	/**
	 * Getting Current Product's name
	 */
	public function getProductName ()
	{
		return Mage::registry(&quot;product&quot;)-&gt;getName();
	}
	/**
	 * Getting Rating summary only for the one Review (latest one)
	 */
	public function getRatingSummary ()
	{
		return Mage::getModel('rating/rating')-&gt;getReviewSummary($this-&gt;getReviewId());
	}
}
</pre>
<p>And here is the phtml file.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?php
// Retreiving rescent comment collection's Item
$_items = $this-&gt;getRescentReview()-&gt;getItems();
?&gt;
&lt;?php if (count($_items)):
// Loading review with the latest comment's id
$_review=Mage::getModel(&quot;review/review&quot;)-&gt;load(array_keys($_items));
$curRat=$_review-&gt;getData('review_id');

// Setting the current Review Id to the block's Object, used in Namespace_Comment_Block_Comment line #26
$this-&gt;setReviewId($curRat);
if($curRat!=1):
?&gt;
&lt;div &gt;
    &lt;div&gt;
        &lt;h2&gt;&lt;?php echo $this-&gt;__('Recente Reviews') ?&gt;&lt;/h2&gt;
    &lt;/div&gt;
    &lt;h3&gt;&lt;?php echo $this-&gt;getProductName()?&gt;&lt;/h3&gt;
    &lt;div class=&quot;rating-box&quot;&gt;
        &lt;div class=&quot;rating&quot; style=&quot;width:&lt;?php echo ceil($this-&gt;getRatingSummary()-&gt;getSum() / ($this-&gt;getRatingSummary()-&gt;getCount())) ?&gt;%;&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;?php echo $_review-&gt;getDetail()?&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;?php
endif;
endif;
?&gt;
</pre>
<p>You must call this in product detail page.</p>
<pre class="brush: xml; title: ; notranslate">
--
&lt;block type =&quot;comment/comment&quot; name=&quot;rescent.comment&quot; template=&quot;comment/rescent.phtml&quot;/&gt;
--
</pre>
<p>By the end of this you will get the Rescent rating summary on your product detail page.</p>
<p>Happy Coding in Magento!!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/rescent-rating-summary-product-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Showing Breadcrumbs Anywhere in Magento</title>
		<link>http://subesh.com.np/2009/12/showing-breadcrumbs-magento/</link>
		<comments>http://subesh.com.np/2009/12/showing-breadcrumbs-magento/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 12:52:28 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[breadcrumbs]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=144</guid>
		<description><![CDATA[In Magento, by default there is a reference place where breadcrumbs get showed, that is just above the content reference! But, sometimes you need to show the breadcrumbs twice! above and below the content. Or sometimes you just need to show the breadcrumbs inside the content, due to some designing issue! I&#8217;ve gone through these [...]]]></description>
			<content:encoded><![CDATA[<p>In Magento, by default there is a reference place where breadcrumbs get showed, that is just above the content reference! But, sometimes you need to show the breadcrumbs twice! above and below the content. Or sometimes you just need to show the breadcrumbs inside the content, due to some designing issue! I&#8217;ve gone through these situation a lot, and thought why not post a solution in my blog? <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Here&#8217;s the &#8220;magic code&#8221; for breadcrumbs to show anywhere in Magento</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php  echo $this-&gt;getLayout()-&gt;getBlock(&quot;breadcrumbs&quot;)-&gt;toHtml()?&gt;
</pre>
<p>Its very simple, it just gets the block breadcrumbs defined in page.xml and echoes it as html.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/showing-breadcrumbs-magento/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Debugging Technique in Magento &#8211; Chapter 1 :: Debugging Layout</title>
		<link>http://subesh.com.np/2009/12/debugging-technique-magento-chapter-1-debugging-layout/</link>
		<comments>http://subesh.com.np/2009/12/debugging-technique-magento-chapter-1-debugging-layout/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 07:46:05 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/2009/12/debugging-technique-magento-chapter-1-debugging-layout/</guid>
		<description><![CDATA[I&#8217;ve been working in Magento, for 1 year now! During this whole year I have learnt a lot, and have been sharing my learnings through this Blog. One of the thing that strikes me a lot is the debugging technique. My collegue ask me a lot regarding Debugging Modules Functionalities, Debugging Module&#8217;s Layout and its [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working in Magento, for 1 year now! During this whole year I have learnt a lot, and have been sharing my learnings through this Blog. One of the thing that strikes me a lot is the debugging technique. My collegue ask me a lot regarding Debugging Modules Functionalities, Debugging Module&#8217;s Layout and its template not showing in frontend and backend, Some products and category attribute not showing in the frontend, Installation of Magento Custom Module and its setup not working and many more. And guess what in most of the cases I&#8217;ve developed a procedure or debugging steps, which I follow time and again, to get to the core of the situation. Actually now, I thought of writting down these debugging technique&#8217;s procedure , so that I can tell, please do the following, before you call for my help!</p>
<p>This is the first part of series of post. I&#8217;ll discuss here how to debug layout errors. I&#8217;ll come across other technique as well, later on.</p>
<p><strong>Case: If you have just added your Layout/Template and wondering why it is not working ?</strong></p>
<p>First and foremost, If you have installed a new Module or Changed Layout and is not working where/how it is supposed to work, clear the cache from Admin, even if you say i have disabled the cache.</p>
<p>To test if your layout file say, example.xml, is actually being looked up while the page loads, first open your example.xml file and make some error on that file. The error may be invalid tag closing of XML. And then refresh your page. If XML load error is displayed then you are sure that your layout file is being referred.</p>
<p>If not then first see what package/theme you are using in Design and confirm if the layout is uploaded or placed in correct path.</p>
<p>After you are sure that layout is placed okai, then its now time to see whether your layout file is registed in config.xml of your Custom Module or not. Your layout file&#8217;s name should be set in config.xml of any module inside <frontend>. Please check if your tags are correct and under correct parents. Normally layout are inside Frontend&#8211;>Layout&#8211;>Updates.</p>
<p>If you are through to this point, then your problem may lie in the Block defined. But before that see if you have defined correct reference name.</p>
<p>Later on debugging Block. The post may be listed below. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/debugging-technique-magento-chapter-1-debugging-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Tabs in Product View Page Through Layout In Magento</title>
		<link>http://subesh.com.np/2009/12/adding-tabs-product-view-page-layout-magento/</link>
		<comments>http://subesh.com.np/2009/12/adding-tabs-product-view-page-layout-magento/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 17:49:09 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=141</guid>
		<description><![CDATA[One of my new colleague, today asked me how to add tabs in product view page in Magento. He told me earlier he had used his own tabs CSS and Javascript to do, but now he found out that Magento gives default Tab Javascript to do the same. Then, I thought why not share with [...]]]></description>
			<content:encoded><![CDATA[<p>One of my new colleague, today asked me how to add tabs in product view page in Magento. He told me earlier he had used his own tabs CSS and Javascript to do, but now he found out that Magento gives default Tab Javascript to do the same. Then, I thought why not share with everyone else! Here it goes&#8230;</p>
<p>It is extremely easy to add a tab and its Javascript, but comparatively difficult to make its CSS, and I won&#8217;t talk about that here <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . You can manage tabs in product page of Magento just through layout files. No need to work on Javascript. Just use the following xml tags inside your catalog_product_view layout.</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;additional&lt;/alias&gt;&lt;title&gt;General Info&lt;/title&gt;&lt;block&gt;catalog/product_view_attributes&lt;/block&gt;&lt;template&gt;catalog/product/view/attributes.phtml&lt;/template&gt;&lt;/action&gt;
                    &lt;action method=&quot;addTab&quot; translate=&quot;title&quot; module=&quot;catalog&quot;&gt;&lt;alias&gt;deliverytime&lt;/alias&gt;&lt;title&gt;Delivery Time&lt;/title&gt;&lt;block&gt;    catalog/product_view&lt;/block&gt;&lt;template&gt;catalog/product/view/delivery.phtml&lt;/template&gt;&lt;/action&gt;
                    &lt;action method=&quot;addTab&quot; translate=&quot;title&quot; module=&quot;catalog&quot;&gt;&lt;alias&gt;printinginfo&lt;/alias&gt;&lt;title&gt;Printing Info&lt;/title&gt;&lt;block&gt;    catalog/product_view&lt;/block&gt;&lt;template&gt;catalog/product/view/printing_info.phtml&lt;/template&gt;&lt;/action&gt;
&lt;!--  4th tab --&gt;
&lt;action method=&quot;addTab&quot; translate=&quot;title&quot; module=&quot;catalog&quot;&gt;&lt;alias&gt;notes&lt;/alias&gt;&lt;title&gt;Notes&lt;/title&gt;&lt;block&gt;catalog/product_view&lt;/block&gt;&lt;template&gt;catalog/product/view/notes.phtml&lt;/template&gt;&lt;/action&gt;
                &lt;/block&gt;
</pre>
<p>In the code above the fourth tab, we have called <strong>addTab </strong>method of <strong>catalog/product_view_tabs</strong> block, with the parameters <strong>alias </strong>as <strong><em>notes</em></strong>, <strong>title </strong>as <strong><em>Notes</em></strong>, <strong>block </strong>as <strong><em>catalog/product_view</em></strong> and <strong>template </strong>as <strong><em>catalog/product/view/notes.phtml</em></strong>.</p>
<p>After adding this in your layout, echo the following in your view.phtml file.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
 echo $this-&gt;getChildHtml('product.info.tabs');
?&gt;
</pre>
<p>After that you will see four tabbed navigation in your product view page. Easy isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/adding-tabs-product-view-page-layout-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with AJAX in Magento</title>
		<link>http://subesh.com.np/2009/11/working-with-ajax-in-magento/</link>
		<comments>http://subesh.com.np/2009/11/working-with-ajax-in-magento/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 13:50:14 +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[Controllers]]></category>
		<category><![CDATA[Layout]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=82</guid>
		<description><![CDATA[Ajax in Magento can be pretty troublesome.Because you will need to take controllers and layout into account.And I almost used up a whole day trying to make ajax work. Here are some of the steps I&#8217;d like to share so that you will not waste lots of your time, before making this work . Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Ajax in Magento can be pretty troublesome.Because you will need to take controllers and layout into account.And I almost used up a whole day trying to make ajax work. Here are some of the steps I&#8217;d like to share so that you will not waste lots of your time, before making this work <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .<br />
Let&#8217;s first know in Magento terms what we need.</p>
<p><strong>Controller:</strong> The url on which Ajax will work on, or the request URL. You will have to set up the controller with its frontend router set in config.xml and its corresponding controller class.<br />
<strong>Layout:</strong> Layout to handle the requested URL and return HTML if required.<br />
<strong>Block:</strong> The block to call through layout for the above controller.</p>
<p>Now lets be descriptive.</p>
<p>If you want to show a loader while request is being processed just add the following whereever you like in the phtml page.First fetch the Javascript.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script src=&quot;&lt;?php echo $this-&gt;getJsUrl() ?&gt;mage/adminhtml/loader.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>Then echo the loader which pops up. This loader will be similar to that of the admin.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;loadingmask&quot; style=&quot;display: none;&quot;&gt;
&lt;div class=&quot;loader&quot; id=&quot;loading-mask-loader&quot;&gt;&lt;img src=&quot;&lt;?php echo str_replace(&quot;index.php/&quot;,&quot;&quot;,$this-&gt;getUrl()) ?&gt;skin/adminhtml/default/default/images/ajax-loader-tr.gif&quot; alt=&quot;&lt;?php echo $this-&gt;__('Loading...') ?&gt;&quot;/&gt;&lt;?php echo $this-&gt;__('Loading...') ?&gt;&lt;/div&gt;
&lt;div id=&quot;loading-mask&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Now to Call Ajax, use the following lines</p>
<pre class="brush: jscript; title: ; notranslate">

/*Please note that the URL is created in reloadurl. Also see that the response text will be echoed in div with id=output-div*/

var reloadurl = '&lt;?php echo $this-&gt;getUrl('router/controller/action') ?&gt;';
Element.show('loadingmask');
new Ajax.Request(reloadurl, {
method: 'post',
parameters: &quot;Params_Here&quot;,
onComplete: function(transport) {
Element.hide('loadingmask');
$('output-div').innerHTML = &quot;&quot;;
$('output-div').innerHTML = transport.responseText;

}
});
</pre>
<p>After the Ajax Request is made it goes to your controller&#8217;s action, which in turn sees to your layout as follows:</p>
<pre class="brush: php; title: ; notranslate">
class Namespace_module_frontendController extends Mage_Core_Controller_Front_Action
{
public function actionAction(){
$this-&gt;loadLayout()-&gt;renderLayout();
}
}
</pre>
<p>And here is the main part in layout where I spent most of my time in. Since in layout we will have to define reference where the html will echo (Most of the times), i got stuck here, because i need to echo the output on the div with id output-div not in any reference.And the trick is to name the layout as root and output as html. Like the following:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;module_controller_action&gt;
&lt;block type=&quot;module/block&quot;  name=&quot;root&quot; output=&quot;toHtml&quot;  template=&quot;module/template.phtml&quot;/&gt;
&lt;/module_controller_action&gt;
</pre>
<p>You are done now! What ever you write or echo in phtml file you will see populated in the DIV. Now you can treat block as normally as you do before.</p>
<p>Happy Coding!!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/11/working-with-ajax-in-magento/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
	</channel>
</rss>

