<?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; how-to</title>
	<atom:link href="http://subesh.com.np/tag/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://subesh.com.np</link>
	<description>PHP &#38; Magento Tips and Tutorials</description>
	<lastBuildDate>Tue, 20 Mar 2012 18:15:10 +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>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>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>3</slash:comments>
		</item>
		<item>
		<title>Magento: Creating Ajax Updated Tabs In Frontend, Like Product Management Tabs of Backend</title>
		<link>http://subesh.com.np/2010/06/magento-creating-ajax-updated-tabs-frontend-product-management-tabs-backend/</link>
		<comments>http://subesh.com.np/2010/06/magento-creating-ajax-updated-tabs-frontend-product-management-tabs-backend/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 13:00:42 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=254</guid>
		<description><![CDATA[Magento&#8217;s Product Management GUI in back-end has Tabbed Navigation. There are two types of Tabs implemented there. One type of Tab is normal tab, loading content on page load while other type of tab has its content loaded by &#8220;Ajax&#8221;. Another interesting thing to note is that once the Ajax loaded tab&#8217;s content is loaded [...]]]></description>
			<content:encoded><![CDATA[<p>Magento&#8217;s Product Management GUI in back-end has Tabbed Navigation. There are two types of Tabs implemented there. One type of Tab is normal tab, loading content on page load while other type of tab has its content loaded by &#8220;Ajax&#8221;. Another interesting thing to note is that once the Ajax loaded tab&#8217;s content is loaded it will not &#8220;recall&#8221; Ajax to load its content, rather earlier loaded tab content is show. If are &#8220;confused&#8221; then just see how the &#8220;Categories&#8221; tab of the Product Management works.</p>
<p>I successfully used the same &#8220;behavior&#8221; of tabbed navigation in &#8220;front-end&#8221;, was easy at the end (always with Magento, when you get it), but I was struggling at the start. So, like my other posts, to share here&#8217;s how I used the same type of tab in Magento&#8217;s Front-end.</p>
<p>First thing is add the Tab&#8217;s Java-script file. You can either include by layout or in PHTML file. If you want to do from layout then,</p>
<pre class="brush: xml; title: ; notranslate">
&lt;reference name=&quot;head&quot;&gt;
        	 &lt;action method=&quot;addJs&quot;&gt;&lt;script&gt;mage/adminhtml/tabs.js&lt;/script&gt;&lt;/action&gt;
&lt;/reference&gt;
</pre>
<p>Next thing is to create Tab&#8217;s Menu inside UL &#038; LI. Here&#8217;s the structure. (Self Explanatory)</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- TAB MENU STRUCTURE --&gt;

&lt;ul id=&quot;page_tabs&quot;&gt;
	&lt;!-- NORMAL TAB --&gt;
	&lt;li&gt;
		&lt;a id=&quot;normaltab&quot; name=&quot;normaltab&quot; class=&quot;tab-item-link&quot; href=&quot;#&quot;&gt; NORMAL TAB &lt;/a&gt;
		&lt;!-- NOTE: class has to be tab-item-link--&gt;

		&lt;div id=&quot;normaltab_content&quot;&gt; Normal Tab HTML&lt;/div&gt;
		&lt;!-- NOTE: See the id of this div content it has id equal to its anchor's (&lt;a&gt;) id + Underscore + content --&gt;
	&lt;/li&gt;
	&lt;!-- NORMAL TAB END--&gt;

	&lt;!-- AJAX LOADED TAB --&gt;
	&lt;li&gt;
		&lt;a id=&quot;ajaxtab&quot; name=&quot;ajaxtab&quot; class=&quot;tab-item-link ajax notloaded&quot; href=&quot;http://example.com/magento/module/controller/action&quot;&gt; AJAX TAB &lt;/a&gt;
		&lt;!-- NOTE 1: class has to be tab-item-link ajax notloaded --&gt;
		&lt;!-- NOTE 2: Since this is Ajax Loaded Tab its Anchor should have href value = SOME URL --&gt;

		&lt;div id=&quot;ajaxtab_content&quot;&gt;&lt;/div&gt;
		&lt;!-- NOTE 1: See the id of this div content it has id equal to its anchor's (&lt;a&gt;) id + Underscore + content --&gt;
		&lt;!-- NOTE 2: Since its innerHTML will be loaded by by Ajax you can set its innerHTML &quot;blank&quot; --&gt;

	&lt;/li&gt;
	&lt;!-- AJAX LOADED TAB END --&gt;
&lt;/ul&gt;
&lt;!-- TAB MENU STRUCTURE END --&gt;

&lt;!-- TAB CONTENT CONTAINER DIV--&gt;
&lt;div id=&quot;tabcontainer&quot;&gt;&lt;/div&gt;
&lt;!-- TAB CONTENT CONTAINER DIV--&gt;
</pre>
<p>Now its the time to use the Tabs JS included, like below.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script&gt;
	// Form Key Required for POST AJAX Method
	var FORM_KEY=&quot;&lt;?php echo Mage::getSingleton('core/session')-&gt;getFormKey() ?&gt;&quot;;

	// Set this to false, Guess used for some other purpose in backend, not really required in frontend.
	var varienGlobalEvents=false;

	// Initiallizing Varien Tabs
	/**
	* @param 1 : UL Menu ID
	* @param 2 : Target Tab Content ID
	* @param 3 : Initially Loading Tab's Id
	* @param 4 : Don't know yet, just use as it is (LOL)
	*/

	frontend_tabsJsTabs = new varienTabs('page_tabs', 'tabcontainer', 'normaltab',[]);

&lt;/script&gt;
</pre>
<p>Done! You must now have a functioning Tab loading by Ajax and Normal, but yes tab would look good if you add CSS to your Tabs. <img src='http://subesh.com.np/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  Here is how it works.</p>
<ol>
<li>
On load it first copies the tab_content div inside the Target Tab Content ID div.
</li>
<li>
On tabbed menu clicked it checks its class name and if it class name does not have &#8220;ajax&#8221; it simply shows the its_content div.
</li>
<li>
If the menu clicked has &#8220;ajax&#8221; then it checks for another class name &#8220;notloaded&#8221;. So if its ajax and notloaded it then makes an Ajax request and updates the responseText to itsid_content div and then removes the &#8220;notloaded&#8221; class name for the menu. After that it then displays the itsid_content div, hiding previous ones.
</li>
<li>
If you re-click the &#8220;Ajax&#8221; typed menu, it will not find &#8220;notloaded&#8221; class in its menu, then it just shows its_content div.
</li>
</ol>
<p>A good trick, I thought while doing this, using class name to restrict the Ajax call.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/06/magento-creating-ajax-updated-tabs-frontend-product-management-tabs-backend/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Magento eCommerce: How To Reset All Test Order Information and Set Unique Prefix For Orders, Invoices, Shipments, and Credit Memos</title>
		<link>http://subesh.com.np/2010/05/magento-ecommerce-how-to-reset-all-test-order-information-and-set-unique-prefix-for-orders-invoices-shipments-and-credit-memos/</link>
		<comments>http://subesh.com.np/2010/05/magento-ecommerce-how-to-reset-all-test-order-information-and-set-unique-prefix-for-orders-invoices-shipments-and-credit-memos/#comments</comments>
		<pubDate>Thu, 06 May 2010 09:54:02 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=242</guid>
		<description><![CDATA[Nice Post I stumbled upon.. from www.eliasinteractive.com. This is a very helpful hack Lee has posted to reset order information while moving from development stage to production stage. I&#8217;d tried this in Enterprise Edition as well and it worked! Just a Re-Post Magento eCommerce: How To Reset All Test Order Information and Set Unique Prefix [...]]]></description>
			<content:encoded><![CDATA[<p>Nice Post I stumbled upon.. from www.eliasinteractive.com. This is a very helpful hack Lee has posted to reset order information while moving from development stage to production stage. I&#8217;d tried this in Enterprise Edition as well and it worked!</p>
<p>Just a Re-Post <img src='http://subesh.com.np/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><a href="http://www.eliasinteractive.com/blog/magento-ecommerce-how-to-reset-all-test-order-information-and-set-unique-prefix-for-orders-invoices-shipments-and-credit-memos">Magento eCommerce: How To Reset All Test Order Information and Set Unique Prefix For Orders, Invoices, Shipments, and Credit Memos</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/05/magento-ecommerce-how-to-reset-all-test-order-information-and-set-unique-prefix-for-orders-invoices-shipments-and-credit-memos/feed/</wfw:commentRss>
		<slash:comments>0</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>4</slash:comments>
		</item>
		<item>
		<title>Redirect to some other location from Model or Observer in Magento</title>
		<link>http://subesh.com.np/2010/03/redirect-location-model-observer-magento/</link>
		<comments>http://subesh.com.np/2010/03/redirect-location-model-observer-magento/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 12:45:02 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Controllers]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=236</guid>
		<description><![CDATA[Redirection in Magento&#8217;s controller is simple. You just need to call a _redirect() or _forward() function and provide appropriate router/controller/action parameter. But if you want to redirect to some other page from Model or from Observer, then this can be tricky. Lets take an example, for explaining what I am referring to, Suppose you are [...]]]></description>
			<content:encoded><![CDATA[<p>Redirection in Magento&#8217;s controller is simple. You just need to call a <strong>_redirect() </strong>or <strong>_forward() </strong>function and provide appropriate router/controller/action parameter. But if you want to redirect to some other page from Model or from Observer, then this can be tricky. Lets take an example, for explaining what I am referring to, Suppose you are building a module that will only allow user of certain group to view a product in frontend. Then, you will have options like:</p>
<ul>
<ol>
Rewrite you catalog/product/view controller and add that logic.
</ol>
<ol>
Rewrite Block of that page and show error message accordingly.
</ol>
<ol>
Any other..?
</ol>
</ul>
<p>Yeha, I do have another option as well. The Event-Observer Method. You can observe an event <strong>controller_action_predispatch_catalog_product_view</strong> and set up an observer where you can write your own logic there and redirect accordingly.</p>
<p>You can observe that event by setting up your config something like this.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;controller_action_predispatch_catalog_product_view&gt;
	&lt;observers&gt;
		&lt;mymodel&gt;
			&lt;type&gt;singleton&lt;/type&gt;
			&lt;class&gt;mymodel/controller_observer&lt;/class&gt;
			&lt;method&gt;controller_action_predispatch_catalog_product_view&lt;/method&gt;
		&lt;/mymodel&gt;
	&lt;/observers&gt;
&lt;/controller_action_predispatch_catalog_product_view&gt;
</pre>
<p>And on the observer&#8217;s <strong>controller_action_predispatch_catalog_product_view</strong> method, you can check your logic for visibiliy of that product to the logged in user group and redirect if not visible.</p>
<p>Here&#8217;s the main point of this post (Did I take a lot of your time ?), in that same method you can directly redirect using the following snippet of code.</p>
<pre class="brush: php; title: ; notranslate">

Mage::app()-&gt;getResponse()-&gt;setRedirect(Mage::getUrl(&quot;myrouter/mycontroller/noview&quot;));
</pre>
<p>Adding an error message to the session would be a good idea, for user to understand what is happening. Else you can directly call a template in the redirected controller&#8217;s action with appropriate message.</p>
<p>I think this sums up the post for now..and as always hoping it helps somebody and waiting for the response.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/redirect-location-model-observer-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating Backend-Admin URL with Key and Parameters in Magento</title>
		<link>http://subesh.com.np/2010/03/generating-backend-admin-url-key-parameters-magento/</link>
		<comments>http://subesh.com.np/2010/03/generating-backend-admin-url-key-parameters-magento/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 12:52:57 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=228</guid>
		<description><![CDATA[When you log into adminstrator part of the Magento webshop, and look into the url you may see something like this. The part in &#8220;RED&#8221; are module controller(router)/action. And the part in &#8220;GREEN&#8221; is what we call as &#8220;Paramerters&#8221; and the &#8220;BLUE&#8221; part is the &#8220;Key&#8220;. The Key (which is also a URL parameter) in [...]]]></description>
			<content:encoded><![CDATA[<p>When you log into adminstrator part of the Magento webshop, and look into the url you may see something like this.<br />
<div id="attachment_230" class="wp-caption alignnone" style="width: 429px"><img src="http://subesh.com.np/wp-content/uploads/2010/03/adminurl.png" alt="Admin URL with Keys and Parameters" title="Admin URL with Keys and Parameters" width="419" height="42" class="size-full wp-image-230" /><p class="wp-caption-text">Admin URL with Keys and Parameters</p></div></p>
<p>The part in &#8220;RED&#8221; are module controller(router)/action. And the part in &#8220;GREEN&#8221; is what we call as &#8220;<strong>Paramerters</strong>&#8221; and the &#8220;BLUE&#8221; part is the &#8220;<strong>Key</strong>&#8220;. The Key (which is also a URL parameter) in the URL has been added for security reasons and is checked against the session&#8217;s values for every action. If store owner does not want to use the key in admin url, then it can be set off from administrator settings.</p>
<p>My point in this post is, if you are a developer and creating a module that has Admin controller and you are simply calling some action of your controller lets say,<strong> <em>mymodule/adminhtml_mycontroller/myaction/param1/1/param2/2</em> </strong>the it does not redirect you to your intended page, but will redirect to dashboard, IF key is enabled. You will have to add the key parameter to the URL to go to your page. So here is a simple snippet of code that will help you to build your URL with valid keys.</p>
<pre class="brush: php; title: ; notranslate">
echo Mage::helper(&quot;adminhtml&quot;)-&gt;getUrl(&quot;mymodule/adminhtml_mycontroller/myaction/&quot;,array(&quot;param1&quot;=&gt;1,&quot;param2&quot;=&gt;2));
</pre>
<p>The &#8220;adminhtml&#8221; helper will automatically create url with keys attached to the URL.</p>
<p>Next thing, if you see the key of various pages in admin you will see that those keys are not same, there is a different logic behind creating those key values. The keys generated depends upon the controller and action you are about to execute. Keys can be seperatly generated as follows.</p>
<pre class="brush: php; title: ; notranslate">
Mage::getSingleton('adminhtml/url')-&gt;getSecretKey(&quot;adminhtml_mycontroller&quot;,&quot;myaction&quot;);
</pre>
<p>Hope this helps, and this can be particularly helpful when you are using templates in admin modules and adding buttons to redirect to some other location. At least that was my case!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/generating-backend-admin-url-key-parameters-magento/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Creating Product Links in Magento Using Custom Query</title>
		<link>http://subesh.com.np/2010/03/creating-product-links-magento-custom-query/</link>
		<comments>http://subesh.com.np/2010/03/creating-product-links-magento-custom-query/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 06:28:27 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Import/Export]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=220</guid>
		<description><![CDATA[I&#8217;ve already made a post in this blog about Adding Related Product and other links to Product in Magento . But when I used the method to creating links among product&#8217;s, while importing very large number of products and creating large number of product links, it took a lot of time and resource. So I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve already made a post in this blog about <a href="http://subesh.com.np/2009/11/adding-related-product-and-other-links-to-product-in-magento/">Adding Related Product and other links to Product in Magento </a>. But when I used the method to creating links among product&#8217;s, while importing very large number of products and creating large number of product links, it took a lot of time and resource. So I thought why not give it a try by direclty creating a link using SQL? And YES! it worked.</p>
<p>Below is the code how I created those links using Custom SQL. But I have to tell you that the former methods looks organized, this is just a work around to a situation. You might know what I am trying to say!</p>
<pre class="brush: php; title: ; notranslate">
$resource 	= Mage :: getSingleton( 'core/resource' );
$read= $resource -&gt; getConnection( 'core_read' );
$write= $resource-&gt;getConnection('core_write');
$linkTable=$resource-&gt;getTableName('catalog/product_link');

// Creating Upsell Product link

$write-&gt;query(&quot;INSERT into $linkTable SET
							product_id='&quot;.$productId.&quot;',
							linked_product_id='&quot;.$linkProduct.&quot;',
							link_type_id='&quot;.Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL.&quot;'
			&quot;);

// Creating Related Product link

$write-&gt;query(&quot;INSERT into $linkTable SET
							product_id='&quot;.$productId.&quot;',
							linked_product_id='&quot;.$linkProduct.&quot;',
							link_type_id='&quot;.Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED.&quot;'
			&quot;);

// Creating Crosssell Product Link
$write-&gt;query(&quot;INSERT into $linkTable SET
							product_id='&quot;.$productId.&quot;',
							linked_product_id='&quot;.$linkProduct.&quot;',
							link_type_id='&quot;.Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL.&quot;'
			&quot;);
</pre>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/creating-product-links-magento-custom-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Collection of Objects in Magento using a &quot;Magical Class&quot;:Varien_Data_Collection</title>
		<link>http://subesh.com.np/2010/03/creating-collection-objects-magento-magical-classvarien_data_collection/</link>
		<comments>http://subesh.com.np/2010/03/creating-collection-objects-magento-magical-classvarien_data_collection/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 11:58:04 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=215</guid>
		<description><![CDATA[Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important data structure (if I am right) used in Magento. Most of the queries in Magento will result into collection, and then you will apply a foreach loop to access individual [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important data structure (if I am right) used in Magento. Most of the queries in Magento will result into collection, and then you will apply a foreach loop to access individual Entity Objects and their values. Today I came into a different situation where I had individual objects but needed to create a collection of those objects, so that I could return the collection from a function.</p>
<p>I have not drilled down to the details of collection, untill today when I really need it! Do you think its very late? because I have been into Magento for more than a year now!. Better late than never! So, I got the way of working out my situation. Here is how I created a collection from Magento&#8217;s &#8220;Magical Class&#8221; Varien_Data_Collection. I call this &#8220;Magical Class&#8221;, because it worked like a Magic to me <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<pre class="brush: php; title: ; notranslate">
$collection=new Varien_Data_Collection();
$collection-&gt;addItem($objProduct);
</pre>
<p>There are various other functions in this class you might need to &#8220;work around&#8221; a problem. So, have a look and certainly do comment if you also think this class to be a Magical Class!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/creating-collection-objects-magento-magical-classvarien_data_collection/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Getting Ordered Items and their Detail from Order ID in Magento</title>
		<link>http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/</link>
		<comments>http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 12:00:21 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=213</guid>
		<description><![CDATA[Here is a small snippet of code, yet useful, to get ordered items and its details. I&#8217;ve deviced this code a lot before and posted in Magento Commerce&#8217;s Forum as well. But felt like writting it again, so that I can have a quick refrence to it as well. Next thing, I&#8217;ve tried a lot [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small snippet of code, yet useful, to get ordered items and its details. I&#8217;ve deviced this code a lot before and posted in Magento Commerce&#8217;s Forum as well. But felt like writting it again, so that I can have a quick refrence to it as well. Next thing, I&#8217;ve tried a lot to get all orders and their items details by single query, but have not yet come up with a solution. If you have any method of finding order and its details by a single query, then please do response. The code below first needs an order ID as it parameters to give order details.</p>
<pre class="brush: php; title: ; notranslate">
$order = Mage::getModel('sales/order')-&gt;load($order_id);
$items = $order-&gt;getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId =&gt; $item)
{
	$name[] = $item-&gt;getName();
	$unitPrice[]=$item-&gt;getPrice();
	$sku[]=$item-&gt;getSku();
	$ids[]=$item-&gt;getProductId();
	$qty[]=$item-&gt;getQtyToInvoice();
}
</pre>
<p>Hope this might &#8220;just&#8221; help somebody in need.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

