<?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,PHP,Google Maps</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 &#38; Tutorials</description>
	<lastBuildDate>Thu, 11 Mar 2010 11:58:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Collection of Objects in Magento using a &#8220;Magical Class&#8221;: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[Tips]]></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><span id="more-215"></span></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;">
$collection=new Varien_Data_Colllection();
$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>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F03%2Fcreating-collection-objects-magento-magical-classvarien_data_collection%2F&amp;linkname=Creating%20Collection%20of%20Objects%20in%20Magento%20using%20a%20%26%238220%3BMagical%20Class%26%238221%3B%3AVarien_Data_Collection"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/creating-collection-objects-magento-magical-classvarien_data_collection/feed/</wfw:commentRss>
		<slash:comments>0</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[Tips]]></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>
<p><span id="more-213"></span></p>
<pre class="brush: php;">
$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>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F03%2Fordered-items-detail-order-id-magento%2F&amp;linkname=Getting%20Ordered%20Items%20and%20their%20Detail%20from%20Order%20ID%20in%20Magento"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create and Download XLS Report file using Magento&#8217;s Core</title>
		<link>http://subesh.com.np/2010/03/create-download-xls-report-file-magentos-core/</link>
		<comments>http://subesh.com.np/2010/03/create-download-xls-report-file-magentos-core/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 08:03:47 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Reports]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=210</guid>
		<description><![CDATA[Reporting can be a very important part of the Module you might be developing for Mageneto. If you are showing your data in Grid that&#8217;s good, but it will be better if you add XLS file generation action on that grid, so that the site administrator can see the report in paper. And if you [...]]]></description>
			<content:encoded><![CDATA[<p>Reporting can be a very important part of the Module you might be developing for Mageneto. If you are showing your data in Grid that&#8217;s good, but it will be better if you add XLS file generation action on that grid, so that the site administrator can see the report in paper. And if you have in paper you can visualize more clearly than on screen.</p>
<p><span id="more-210"></span></p>
<p>I came this condition recently, and found out that Magento has functions to chanage your Grid (in Admin) to XLS files and if you dig more than you can change your data Array to XLS file using Magento&#8217;s function.</p>
<p>First let me say you about exporing data from the Admin Grid you have already populated. You need do the following in your grid Block&#8217;s _prepareColumn function.</p>
<pre class="brush: php;">
$this-&gt;addExportType('router/controller/action', Mage::helper('reports')-&gt;__('Excel'));
</pre>
<p>And in your controller you will have to do this.</p>
<pre class="brush: php;">
/**
     * Export grid to Excel XML format in Controller
	 * @class Mynamespace_Mymodule_Adminhtml_controllerController
     */
    public function actionAction()
    {
        $fileName   = 'grid.xls';

		/**
		* This is the part where Grid Columns and Data are created as Excel XML and returned as stream.
		* The implementation of this code is done in the parent class of Grid Mynamespace_Mymodule_Block_Adminhtml_Grid
		* And that class should be Mage_Adminhtml_Block_Widget_Grid
		*/

        $content    = $this-&gt;getLayout()-&gt;createBlock('mymodule_adminhtml/mygrid_grid')
            -&gt;getExcel($fileName);

    /**
	* This is for Force Download implemented below
	*/
	$this-&gt;_prepareDownloadResponse($fileName, $content);
    }

	/**
	 * Force Download Code block in your controller
     * Declare headers and content file in responce for file download
     *
     * @param string $fileName
     * @param string $content set to null to avoid starting output, $contentLength should be set explicitly in that case
     * @param string $contentType
     * @param int $contentLength explicit content length, if strlen($content) isn't applicable
     * @return Mage_Adminhtml_Controller_Action
     */
    protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
    {
        $session = Mage::getSingleton('admin/session');
        if ($session-&gt;isFirstPageAfterLogin()) {
            $this-&gt;_redirect($session-&gt;getUser()-&gt;getStartupPageUrl());
            return $this;
        }
        $this-&gt;getResponse()
            -&gt;setHttpResponseCode(200)
            -&gt;setHeader('Pragma', 'public', true)
            -&gt;setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
            -&gt;setHeader('Content-type', $contentType, true)
            -&gt;setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength)
            -&gt;setHeader('Content-Disposition', 'attachment; filename=' . $fileName)
            -&gt;setHeader('Last-Modified', date('r'));
        if (!is_null($content)) {
            $this-&gt;getResponse()-&gt;setBody($content);
        }
        return $this;
    }
</pre>
<p>Now you can export your Grid data to XLS sheet. But what about your array you are not displaying in the grid? This should be fun too.. for you now.. because it was not fun for me to find out in the first hand <img src='http://subesh.com.np/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .</p>
<p>Lets take the same controller now. </p>
<pre class="brush: php;">
 /**
     * Export Array to Excel XML format in Controller
	 * @class Mynamespace_Mymodule_Adminhtml_controllerController
     */
    public function actionAction()
    {
		$filename   = 'array.xls';
		$exportData=Mage::getSingleton(&quot;adminhtml/session&quot;)-&gt;getMyData();

		/**
		* Example Data Format
		* $data[0]['product_id']=10
		* $data[0]['product_name']=HTC Diamond
		* $data[0]['vendor_name']=HTC JMKYZY
		* $data[1]['product_id']=11
		* $data[1]['product_name']=HTC Ruby
		* $data[1]['vendor_name']=HTC JMKYZY
		*
		*/

		// Setting headers columns
			$data[0]=array($this-&gt;__(&quot;Product ID&quot;),$this-&gt;__(&quot;Product Name&quot;),$this-&gt;__(&quot;Vendors&quot;));

		// Setting Column Data
			$i=1;
			foreach($exportData as $key=&gt;$value){
				$data[$i]=array($value['product_id'],$value['product_name'],$value['vendor_name']);
				$i++;
			}

		// Unparsing in Excel Format
			$xmlObj = new Varien_Convert_Parser_Xml_Excel();
			$xmlObj-&gt;setVar('single_sheet', $filename);
			$xmlObj-&gt;setData($data);
			$xmlObj-&gt;unparse();
			$content=$xmlObj-&gt;getData();

			// Force Download
			$this-&gt;_prepareDownloadResponse($filename,$content);
	}
</pre>
<p>So by comparing the two export controller methods, you can see that the Admin Grid&#8217;s Parent already has the functionality to get data from Grid and set that data to Varien_Convert_Parser_Xml_Excel Object and unparse its. As I said we need to dig further to know what going on inside Magento.</p>
<p>Happy Coding.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F03%2Fcreate-download-xls-report-file-magentos-core%2F&amp;linkname=Create%20and%20Download%20XLS%20Report%20file%20using%20Magento%26%238217%3Bs%20Core"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/03/create-download-xls-report-file-magentos-core/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Magento Using Eclipse PDT &amp; Zend Debugger</title>
		<link>http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger/</link>
		<comments>http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 12:37:29 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=187</guid>
		<description><![CDATA[I had always thought of using Eclipse to debug Magento&#8217;s complex code flow, and tried number of times before. But without any success I had to abandon it, and thought was not applicable for Magento, remember the fox and the sour grapes   I also tried using Trial Version of Zend Studio, but with [...]]]></description>
			<content:encoded><![CDATA[<p>I had always thought of using Eclipse to debug Magento&#8217;s complex code flow, and tried number of times before. But without any success I had to abandon it, and thought was not applicable for Magento, remember the fox and the sour grapes <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  I also tried using Trial Version of Zend Studio, but with no sucess.</p>
<p><span id="more-187"></span></p>
<p>But today I was looking at fontis&#8217;s blog <a href="http://www.fontis.com.au/blog/magento/debugging-with-xdebug">http://www.fontis.com.au/blog/magento/debugging-with-xdebug</a> and they had indeed used XDebugger and are debugging Magento through command line. So, I thought why not give it a try once again! And as you have already expected i was successfull today!! Wasn&#8217;t easy though <img src='http://subesh.com.np/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Here&#8217;s what I&#8217;ve done to get it working on WAMP. Before getting this done I assume you have created a new PHP Project and imported all files, beforehand in Eclipse.</p>
<p><strong>Step 1</strong>. A very good explanation of downloading Eclipse PDT with Zend Debugger can be found here <a href="http://www.thierryb.net/pdtwiki/index.php?title=Using_PDT_:_Installation_:_Installing_the_Zend_Debugger">Installing_the_Zend_Debugger</a></p>
<p><strong>Step 2</strong>. Configuring the Zend Debugger can also be found on same location but I would like to emphasize on its setting here, coz I missed myself on first run <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Use these settings for For Zend debugger in <strong>php.ini</strong></p>
<p>[Zend]<br />
zend_extension_ts=D:/wamp/bin/php/php5.2.5/ext/ZendDebugger.dll<br />
zend_debugger.allow_hosts=127.0.0.1<br />
zend_debugger.expose_remotely=always</p>
<p>You should not forget to enable <strong>Zend Debugger</strong> extension on WAMP. Now restart Wamp. You are now well set with Eclipse PDT and Zend Debugger. Next thing you need to do is make debugging settings in your Eclipse.</p>
<p><strong>Step 3</strong>. In you Eclipse Go to <strong>Windows&#8211;&gt;Preference&#8211;&gt;Debug</strong> and set as follows</p>
<p><img class="alignnone size-full wp-image-194" title="debugsettings" src="http://subesh.com.np/wp-content/uploads/2010/01/debugsettings.jpg" alt="debugsettings" width="500" height="497" /></p>
<p><strong>Step 4</strong>. Then <strong>Windows&#8211;&gt;Preference&#8211;&gt;Server</strong> and set as follows</p>
<p><img class="alignnone size-full wp-image-198" title="Debug Server" src="http://subesh.com.np/wp-content/uploads/2010/01/debugserver.jpg" alt="Debug Server" width="500" height="497" /></p>
<p>While setting Server configuration you will be prompt to add server path in path mapping, place that relative to your www root Example: <strong>/mysite</strong> (which will open as localhost/mysite) and select the files in your workspace.</p>
<p><strong>Step 5</strong>. Now all your settings are done. Now let me tell you about debugging a Block Class of Magento, say <strong>Mage_Catalog_Block_Product_List</strong>. Go to the class file and add a breakpoint anywhere inside <strong>_getProductCollection </strong> function.</p>
<p><strong>Step 6</strong>. Go to <strong>Run&#8211;&gt;Open Run Dialog</strong> and configure as following</p>
<p><a class="aligncenter" href="http://subesh.com.np/wp-content/uploads/2010/01/Profile1.png" target="_blank"><img class="alignnone size-full wp-image-200" title="Run Profile1" src="http://subesh.com.np/wp-content/uploads/2010/01/Profile1.png" alt="Run Profile1" width="500" height="369" /></a></p>
<p><a class="aligncenter" href="http://subesh.com.np/wp-content/uploads/2010/01/profile2.png" target="_blank"><img class="alignnone size-full wp-image-202" title="Profile 2" src="http://subesh.com.np/wp-content/uploads/2010/01/profile2.png" alt="Profile 2" width="502" height="367" /></a></p>
<p><strong>Step 7</strong>. All set to go now, Run profile as web page Run&#8211;&gt;Debug As&#8211;&gt;PHP Webpage.</p>
<p>You can now see PHP Debug perspective, and use Step Over or Step Into to debug your values. Here is what I got.</p>
<p><a class="aligncenter" href="http://subesh.com.np/wp-content/uploads/2010/01/debugging.png" target="_blank"><img class="alignnone size-full wp-image-204" title="debugging" src="http://subesh.com.np/wp-content/uploads/2010/01/debugging.png" alt="debugging" width="501" height="263" /></a></p>
<p>Hope this might be a life changer.. at least it is for me!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F01%2Fdebugging-magento-eclipse-pdt-zend-debugger%2F&amp;linkname=Debugging%20Magento%20Using%20Eclipse%20PDT%20%26%23038%3B%20Zend%20Debugger"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/01/debugging-magento-eclipse-pdt-zend-debugger/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Getting Customer&#8217;s Info Using Single Query Including Billing and Shipping Addresses</title>
		<link>http://subesh.com.np/2010/01/customers-info-single-query-including-billing-shipping-addresses/</link>
		<comments>http://subesh.com.np/2010/01/customers-info-single-query-including-billing-shipping-addresses/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 08:49:45 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></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=184</guid>
		<description><![CDATA[Query in Magento can be quite troublesome, if you are a starter..or non-starter. So I&#8217;ve tried to share some of the difficult queries using collection in Magento, so that it will be helpful to my blog readers and also a place where I can later refer to. Here is one of them, may not be [...]]]></description>
			<content:encoded><![CDATA[<p>Query in Magento can be quite troublesome, if you are a starter..or non-starter. So I&#8217;ve tried to share some of the difficult queries using collection in Magento, so that it will be helpful to my blog readers and also a place where I can later refer to. Here is one of them, may not be dificult to all, but for me I had a very bad time initially, when I first started on Magento about a year ago. I had always thought to post on my blog, but when one of my collegue asked me about this I remembered and here&#8217;s the query.</p>
<p><span id="more-184"></span></p>
<pre class="brush: php;">
$collection = Mage::getResourceModel('customer/customer_collection')
				-&gt;addNameToSelect()
				-&gt;addAttributeToSelect('email')
				-&gt;addAttributeToSelect('created_at')
				-&gt;addAttributeToSelect('group_id')
				-&gt;joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
				-&gt;joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
				-&gt;joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
				-&gt;joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
				-&gt;joinAttribute('billing_fax', 'customer_address/fax', 'default_billing', null, 'left')
				-&gt;joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
				-&gt;joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')

				-&gt;joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
				-&gt;joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
				-&gt;joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
				-&gt;joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
				-&gt;joinAttribute('shipping_fax', 'customer_address/fax', 'default_shipping', null, 'left')
				-&gt;joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
				-&gt;joinAttribute('shipping_country_code', 'customer_address/country_id', 'default_shipping', null, 'left')
				-&gt;joinAttribute('taxvat', 'customer/taxvat', 'entity_id', null, 'left');
</pre>
<p>Hope this helps somebody!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F01%2Fcustomers-info-single-query-including-billing-shipping-addresses%2F&amp;linkname=Getting%20Customer%26%238217%3Bs%20Info%20Using%20Single%20Query%20Including%20Billing%20and%20Shipping%20Addresses"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/01/customers-info-single-query-including-billing-shipping-addresses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting Configurable Attributes (Super Attributes) of a Configurable Product</title>
		<link>http://subesh.com.np/2010/01/configurable-attributes-super-attributes-configurable-product/</link>
		<comments>http://subesh.com.np/2010/01/configurable-attributes-super-attributes-configurable-product/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 12:14:27 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=182</guid>
		<description><![CDATA[In one of those time when you need to know what attributes of a product is used to make the current configurable product &#8220;configurable&#8221;, then here it goes   Those configurable attributes are called as &#8220;Super Attributes&#8221;. Looking into the lower level at the Database level the attributes id are saved in the table [...]]]></description>
			<content:encoded><![CDATA[<p>In one of those time when you need to know what attributes of a product is used to make the current configurable product &#8220;configurable&#8221;, then here it goes <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Those configurable attributes are called as &#8220;Super Attributes&#8221;. Looking into the lower level at the Database level the attributes id are saved in the table &#8220;catalog_product_super_attribute&#8221;. In this configurable product&#8217;s Id and the attribute are saved. To get the attribute&#8217;s id you can directly write a custom query and fetch it. But to get its attribute code, attribute level you will then have to create an object attribute using the fetched id. But there is one shot option as well to do the same, in a managed Magento Way!</p>
<p><span id="more-182"></span></p>
<p>Here is the way. The code comments are self explanatory I guess!!</p>
<pre class="brush: php;">
/**
	 * Load Product you want to get Super attributes of
	 */
	$product=Mage::getModel(&quot;catalog/product&quot;)-&gt;load(52520); 

	/**
	 * Get Configurable Type Product Instace and get Configurable attributes collection
	 */
	$configurableAttributeCollection=$product-&gt;getTypeInstance()-&gt;getConfigurableAttributes();

	/**
	 * Use the collection to get the desired values of attribute
	 */
	foreach($configurableAttributeCollection as $attribute){
		echo &quot;Attr-Code:&quot;.$attribute-&gt;getProductAttribute()-&gt;getAttributeCode().&quot;&lt;br/&gt;&quot;;
		echo &quot;Attr-Label:&quot;.$attribute-&gt;getProductAttribute()-&gt;getFrontend()-&gt;getLabel().&quot;&lt;br/&gt;&quot;;
		echo &quot;Attr-Id:&quot;.$attribute-&gt;getProductAttribute()-&gt;getId().&quot;&lt;br/&gt;&quot;;
	}
</pre>
<p>Happy Codding!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F01%2Fconfigurable-attributes-super-attributes-configurable-product%2F&amp;linkname=Getting%20Configurable%20Attributes%20%28Super%20Attributes%29%20of%20a%20Configurable%20Product"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/01/configurable-attributes-super-attributes-configurable-product/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Creating Custom Sourced Multiselect Product Attribute</title>
		<link>http://subesh.com.np/2010/01/creating-custom-sourced-multiselect-product-attribute/</link>
		<comments>http://subesh.com.np/2010/01/creating-custom-sourced-multiselect-product-attribute/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 10:34:50 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=179</guid>
		<description><![CDATA[Creating Multiselect type of product attribute whose source will be the Magento&#8217;s core tables is pretty simple. Just go to Manage Attributes and create a new one. But if you want the attribute&#8217;s source table be a custom table, then you need to think. Some times a case pops up that the store admin wants [...]]]></description>
			<content:encoded><![CDATA[<p>Creating Multiselect type of product attribute whose source will be the Magento&#8217;s core tables is pretty simple. Just go to Manage Attributes and create a new one. But if you want the attribute&#8217;s source table be a custom table, then you need to think. Some times a case pops up that the store admin wants to save custom type of data for attribute&#8217;s option and you need to manage an image according to the attribute&#8217;s option. So for each option of the multiselect attribute option there is an image associated with it. In this case one of the method to sort out the things is to create a module that gives you an GUI to save option&#8217;s data in custom table and give option to upload the image along with it. Later, use this tables data as source of the attribute for product. The first part, saving the data in custom option is not our concern. You can go through <a href="http://subesh.com.np/2010/01/custom-table-custom-module-magento/">this</a> for doing those. But the main point of this article is to use the custom source as source of the muliselect attributes. </p>
<p><span id="more-179"></span></p>
<p>Assumming that first part, i.e. the saving of options are already done, you will now need to create a product attributes through SQL Setup</p>
<pre class="brush: php;">
&lt;?php
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer-&gt;startSetup();
$setup-&gt;addAttribute('catalog_product', 'my_attribute', array(
    'input'         =&gt; 'multiselect',
	'required'		=&gt; false,
    'type'          =&gt; 'text',
    'label'         =&gt; 'My Attribute Label',
    'source'        =&gt; 'mymodule/source_option',
    'backend'       =&gt; 'mymodule/backend_option',
    'global'        =&gt; Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'       =&gt; 1,
));
$installer-&gt;startSetup();
$installer-&gt;endSetup();
</pre>
<p>The source of the attribute is set to some Model, Ynamespace_Mymodule_Model_Source_Option. This file should look like this.</p>
<pre class="brush: php;">
&lt;?php
class Ynamespace_Module_Model_Source_Option
extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
	public function getAllOptions()
	{
		return $this-&gt;getOptionFromTable();
	}

	private function getOptionFromTable(){
		$return=array();
		$col=Mage::getModel(&quot;modules/model&quot;)-&gt;getCollection();
		/**
		* Given that table has column as id,title,image_name
		*
		*/
		foreach($col as $row){
			array_push($return,array('label'=&gt;$row-&gt;getTitle(),'value'=&gt;$row-&gt;getId()));
		}
		return $return;

	}

	public function getOptionText($value)
	{
		$options = $this-&gt;getAllOptions();
		foreach ($options as $option) {
			if(is_array($value)){
				if (in_array($option['value'],$value)) {
					return $option['label'];
				}
			}
			else{
				if ($option['value']==$value) {
					return $option['label'];
				}
			}

		}
		return false;
	}
}
</pre>
<p>As you can see that the option are retrieved from the custom table in label and value pair. Remember that  getAllOptions is called during product export/import as well.</p>
<p>Next important thing you must know is the backend model. Backend model comes into play when you save and load the product. Let me explain. Let us consider a case when you are saving product. The option of this multiselect attribute is sent in post variables as array, but the values cannot be saved as array, either you have to serialize it or implode it into string to save. So to do this change, backend model is there. Similarly, on load you need to explode or unserialize the data from the database to array. So the major functions of backend model are beforeSave() and afterLoad(), which are triggerd as product is saved or loaded. The backend model should look like this:</p>
<pre class="brush: php;">
&lt;?php
class Ynamespace_Modules_Model_Backend_Option
    extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
    /**
     * Before Attribute Save Process
     *
     * @param Varien_Object $object
     * @return Mage_Catalog_Model_Category_Attribute_Backend_Sortby
     */
    public function beforeSave($object) {
        $attributeCode = $this-&gt;getAttribute()-&gt;getName();
        if ($attributeCode == 'my_attribute') {
            $data = $object-&gt;getData($attributeCode);
            if (!is_array($data)) {
                $data = array();
            }
            $object-&gt;setData($attributeCode, join(',', $data));
        }
        return $this;
    }

    public function afterLoad($object) {
        $attributeCode = $this-&gt;getAttribute()-&gt;getName();
        if ($attributeCode == 'my_attribute') {
            $data = $object-&gt;getData($attributeCode);
            if ($data) {
                $object-&gt;setData($attributeCode, split(',', $data));
            }
        }
        return $this;
    }
}
</pre>
<p>Now you are all set, you should have the values of the multiselect attribute saved in database joined by comma seperated values and while on load those values will be exploded as array. Last thing you can do is export the product data using default profile and check if the error shows up or not regarding this attributes. Must not! I think I&#8217;ve checked its integrity with import and export as well. If it shows any, feel free to contact me.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F01%2Fcreating-custom-sourced-multiselect-product-attribute%2F&amp;linkname=Creating%20Custom%20Sourced%20Multiselect%20Product%20Attribute"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/01/creating-custom-sourced-multiselect-product-attribute/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Custom Table for Custom Module in Magento</title>
		<link>http://subesh.com.np/2010/01/custom-table-custom-module-magento/</link>
		<comments>http://subesh.com.np/2010/01/custom-table-custom-module-magento/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 12:44:47 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=177</guid>
		<description><![CDATA[If you want to create a custom module in Magento that has something to do with storing data into a custom table and using that later, then this is just the right post you have bumped into! I will presume that you already know about Models in Magento, what are they and how you can [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create a custom module in Magento that has something to do with storing data into a custom table and using that later, then this is just the right post you have bumped into! I will presume that you already know about Models in Magento, what are they and how you can create them. Also I will presume that you will also know the basic module structure in Magento.<br />
You will have to place this in your config.xml</p>
<pre class="brush: xml;">
&lt;global&gt;
     &lt;ymodel&gt;
            &lt;class&gt;YNamespace_YModule_Model&lt;/class&gt;
	     &lt;resourceModel&gt;quotes_mysql4&lt;/resourceModel&gt;
     &lt;/ymodel&gt;
&lt;quotes_mysql4&gt;
                &lt;class&gt;YNamespace_Ymodule_Model_Mymodel&lt;/class&gt;
                &lt;entities&gt;
			&lt;mymodel&gt;
				&lt;table&gt;ymodel_ytable&lt;/table&gt;
			&lt;/mymodel&gt;
		&lt;/entities&gt;
      &lt;/quotes_mysql4&gt;
&lt;/global&gt;
</pre>
<p><span id="more-177"></span></p>
<p>Then Create a Model</p>
<pre class="brush: php;">
&lt;?php
class YNamespace_Ymodule_Model_Mymodel extends Mage_Core_Model_Abstract
{
	public function _construct()
	{
		parent::_construct();
		$this-&gt;_init('ymodel/mymodel');
	}
}
</pre>
<p>As you can see in constructor of this class it inits the model (tag) defined in the config file. As model uses Resources, you now need to create a resource the module uses.</p>
<pre class="brush: php;">
&lt;?php

class Ynamespace_Ymodel_Model_Mysql4_Ymodel extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {
        $this-&gt;_init('ymodel/mymodel', 'id');
    }
}	
</pre>
<p>So using this resource you now can access Table and add/alter. But you must not explicitly create a object of this class to do that. Creating a model of class above will make this resource usable.</p>
<pre class="brush: php;">
$model=Mage::getModel(&quot;ymodel/mymodel&quot;)
	-&gt;setName(&quot;Subesh&quot;)
	-&gt;setLastname(&quot;Pokhrel&quot;)
      -&gt;save();
</pre>
<p>This will create a new row in table now given that name and lastname is the columns of the table. To edit row of a table do the following</p>
<pre class="brush: php;">
$model=Mage::getModel(&quot;ymodel/mymodel&quot;)-&gt;load($id)
	-&gt;setName(&quot;Subesh&quot;)
	-&gt;setLastname(&quot;Pokharel&quot;)
      -&gt;save();
</pre>
<p>Now to select, there is another procedure. Before that let me tell about collection. Think collections as the array of objects.When you Query in database you get result as collections in Magento and every row resulting from the query is a different Object.To create a collection</p>
<pre class="brush: php;">
&lt;?php

class Ynamespace_Ymodel_Model_Mysql4_Mymodel_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this-&gt;_init('ymodel/mymodel');
    }
}
</pre>
<p>To Select All the row of Table</p>
<pre class="brush: php;">
$allCollection=Mage::getModel(&quot;ymodel/mymodel&quot;)-&gt;getCollection();
</pre>
<p>You can add filters in the above query as required.<br />
To get individual Row you can just loop through the collection <img src='http://subesh.com.np/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: php;">
foreach($allCollection as $objRow){
	print_r($objRow);
}
</pre>
<p>Hope this helps if any one is in need&#8230; and @inchoo..please don&#8217;t twitt this as any other..link&#8230;you find in a weekend&#8230; <img src='http://subesh.com.np/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2010%2F01%2Fcustom-table-custom-module-magento%2F&amp;linkname=Using%20Custom%20Table%20for%20Custom%20Module%20in%20Magento"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/01/custom-table-custom-module-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Moving Magento Shop from Development Enviornment to Production Enviornment or Production to Local</title>
		<link>http://subesh.com.np/2009/12/moving-magento-shop-development-enviornment-production-enviornment-production-local/</link>
		<comments>http://subesh.com.np/2009/12/moving-magento-shop-development-enviornment-production-enviornment-production-local/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 12:38:33 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[custom options]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=170</guid>
		<description><![CDATA[Today, I had really a good chance to move Magento Shop from Development Enviournment to Product Enviornment. On that course I faced some big difficulty in moving the database. I already had the files and DB of the development enviornment, imporing DB was a PIA. I uploaded all the files, which was easy. And next [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I had really a good chance to move Magento Shop from Development Enviournment to Product Enviornment. On that course I faced some big difficulty in moving the database. I already had the files and DB of the development enviornment, imporing DB was a PIA. I uploaded all the files, which was easy. And next thing I did was uploaded DB dumpped files to root of Magento. Then I logged into SSH and logged into MYSQL. Then Used the following commands to import the dumpped DB files. But first made the database say &#8220;magento&#8221;.</p>
<p><span id="more-170"></span></p>
<pre class="brush: sql;">
/**Using the Previously created DB**/
mysql&gt; use magento

/**Import the Dumpped SQL**/
mysql&gt;source pathToMagentoRoot/mySql.sql
</pre>
<p>So after the command is executed I had the whole DB on production enviornment. Similarly we can also import dumpped data of Production on Local database running on WAMP server.<br />
To import Dumpped SQL data on WAMP, first create a database, say magento and then use the following commands</p>
<pre class="brush: sql;">
/**
	Using the Previously created DB.
	-p password part is optional if you have not configured password for MYSQL locally
	-u Username (root by default)
**/

mysql&gt; C:\wamp\bin\mysql\mysql5.0.51b\bin&gt;mysql.exe -use magento -u root -p password 

/**Import the Dumpped SQL**/
mysql&gt;source pathToSQLSource/mySql.sql
</pre>
<p>By Now we have the database synced between Local and Production. Next is configuring the database name used by Magento. Browse to app/etc/local.xml and change in the following part.</p>
<pre class="brush: xml;">
    &lt;connection&gt;
                    &lt;host&gt;&lt;![CDATA[localhost]]&gt;&lt;/host&gt;
                    &lt;username&gt;&lt;![CDATA[username_here]]&gt;&lt;/username&gt;
                    &lt;password&gt;&lt;![CDATA[password_here]]&gt;&lt;/password&gt;
                    &lt;dbname&gt;&lt;![CDATA[databasename_here]]&gt;&lt;/dbname&gt;
                    &lt;active&gt;1&lt;/active&gt;
    &lt;/connection&gt;
</pre>
<p>Finally, browsed through table core_config_data and find value of path: web/unsecure/base_url and path: web/secure/base_url and change their values accordingly.</p>
<p>Now I had my Shop enviorment switched. Most work for you as well. LOL.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2009%2F12%2Fmoving-magento-shop-development-enviornment-production-enviornment-production-local%2F&amp;linkname=Moving%20Magento%20Shop%20from%20Development%20Enviornment%20to%20Production%20Enviornment%20or%20Production%20to%20Local"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/moving-magento-shop-development-enviornment-production-enviornment-production-local/feed/</wfw:commentRss>
		<slash:comments>4</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[Tips]]></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>
<p><span id="more-164"></span></p>
<pre class="brush: php;">
// 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;">
// 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;">
&lt;?php
// In parent PHTML
$this-&gt;getChildHtml(&quot;module.name&quot;);
?&gt;
</pre>
<p>May be helpful!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsubesh.com.np%2F2009%2F12%2Fcreating-block-code-magento%2F&amp;linkname=Creating%20Block%20From%20the%20Code%20in%20Magento"><img src="http://subesh.com.np/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/creating-block-code-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
