<?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; Export</title>
	<atom:link href="http://subesh.com.np/tag/export/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>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[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>
<pre class="brush: sql; title: ; notranslate">
/**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; title: ; notranslate">
/**
	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; title: ; notranslate">
    &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>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/moving-magento-shop-development-enviornment-production-enviornment-production-local/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>General Workflow of Magento&#039;s Import/Export &#8211; Dataflow</title>
		<link>http://subesh.com.np/2009/12/general-workflow-of-magentos-importexport-dataflow/</link>
		<comments>http://subesh.com.np/2009/12/general-workflow-of-magentos-importexport-dataflow/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 13:05:11 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Import/Export]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Dataflow]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[Import]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=113</guid>
		<description><![CDATA[Magento&#8217;s Dataflow (Inport/Export) is one of distinguishing feature that makes Magento the leader in eCommerce Software. But for a programmer to understand how it workes in Magento can be quite nasty. I tried to understand how it workes and came up with following understanding. General Work Flow (Profile) During Import/Export there are normally two &#8220;Actors&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Magento&#8217;s Dataflow (Inport/Export)</strong> is one of distinguishing feature that makes Magento the leader in eCommerce Software. But for a programmer to understand how it workes in Magento can be quite nasty. I tried to understand how it workes and came up with following understanding.</p>
<h2><strong>General Work Flow (Profile)</strong></h2>
<p>During Import/Export there are normally two &#8220;<strong>Actors</strong>&#8221; involved. Actors may be the data source (<strong>Actor: Source</strong>) and the final destination of the data (<strong>Actor:Destination</strong>). While you are importing data into your Magento Sytem, the Source is the CSV or XML file while exporting it is the other way round. In any case (Import or Export) you need to first fetch the data from the source and process it and then save to its destination.</p>
<p>So Basically there are three stages in product import. But the processing part has been split into two. Processing part has been divided into two processes namely Mapper and Parser. I&#8217;ll come to the detailed description later. So along with the extended processes, lets call there are four &#8220;Actions&#8221; occuring during Import or Export.For every &#8220;Action&#8221; to run there are seperate individual Models. And the defination of all these individual Models for each Action during the Import/Export Process (Dataflow) is called &#8220;<strong>Profile</strong>&#8220;.</p>
<p>Here&#8217;s the basic workflow for Dataflow.</p>
<div id="attachment_124" class="wp-caption aligncenter" style="width: 483px"><img class="size-full wp-image-124" title="General Workflow" src="http://subesh.com.np/wp-content/uploads/2009/12/workflow.png" alt="General Workflow" width="473" height="355" /><p class="wp-caption-text">General Workflow</p></div>
<p>That was the laymen description of Dataflow, lets see what are the Jargons used in Magento to call all the Models used in Dataflow. The Models used for all actions are listed below according to how the Dataflow works.</p>
<ol>
<li> Adapter</li>
<li> Parser</li>
<li> Mapper</li>
<li> Adapter (Yes twice)</li>
<li> Validator (Not Implemented yet in Magento, left for future implemention)</li>
</ol>
<h2><strong>Adapter</strong></h2>
<p>To understand what is Adapter, lets see Magento as a System and all the resources it uses during Import/Export as external source. So external source in Most of the cases can be either File or your Database (DB). Other external source include Webservice. I&#8217;ven&#8217;t came across other yet. <img src='http://subesh.com.np/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  So what Adapter does is it provides the channel through which the data actually flows in/out of the Magento System. As you can see in the images below is that there is always two Adapter involved. One that reads data from the file external resource and another that saves the data into the DB external resource. Now you should be clear why I wrote Adapter twice. If you are still wondering..then you can comment below.</p>
<div id="attachment_114" class="wp-caption aligncenter" style="width: 484px"><img class="size-full wp-image-114" title="Case: Export" src="http://subesh.com.np/wp-content/uploads/2009/12/adapter1.png" alt="Adapter: Export" width="474" height="358" /><p class="wp-caption-text">Case: Export</p></div>
<div id="attachment_121" class="wp-caption aligncenter" style="width: 489px"><img class="size-full wp-image-121" title="Import" src="http://subesh.com.np/wp-content/uploads/2009/12/adapter2.png" alt="Case: Import" width="479" height="357" /><p class="wp-caption-text">Case: Import</p></div>
<p>Magento has provides us some Default Adapter to read/write from/to external resources. Here are the Adapters listed.</p>
<p><strong>Adapter For Files 			: 	Mage_Dataflow_Model_Convert_Adapter_Io</strong></p>
<p><strong> Adapter For Customer(DB)	: 	Mage_Customer_Model_Convert_Adapter_Customer</strong></p>
<p><strong> Adapter For Product (DB)	:	Mage_Catalog_Model_Convert_Adapter_Product </strong></p>
<p>Since the work of Adapter is to just Read or Write it has basically two Methods load() and save().</p>
<h2><strong>Parser</strong></h2>
<p>What parser does is that it just converts the raw data (Human Readable) from the source into Magento&#8217;s Format (Arrays and Setting Values of Magento&#8217;s Model) or from Magento&#8217;s Format into Human readable Format. Just to understand you can think of the CSV files seperated by comma changed into Arrays. After conversion is over it then saves the data to the Batch.Batch, what is Batch? if this is what you are thinking, here is your answer. Every row in CSV,XML or Row of the DB during the dataflow are saved as different rows in a table dataflow_batch_import or dataflow_batch_export. So if there are 100 rows in your CSV file you are importing into Magento, the batch will have 100 rows of parsed data in the table dataflow_batch_import. During the final stage of the Dataflow&#8217;s run this data is referred.</p>
<p>Magento provides some default Parses as well.</p>
<p><strong>Parser for CSV files	:	Mage_Dataflow_Model_Convert_Parser_Csv</strong></p>
<p><strong> Parser for XML files	: 	Mage_Dataflow_Model_Convert_Parser_Xml_Excel</strong></p>
<p><strong> Parser for Product		:	Mage_Catalog_Model_Convert_Parser_Product</strong></p>
<p><strong> Parser for Customer		:	Mage_Customer_Model_Convert_Parser_Customer</strong></p>
<pre><strong>
</strong></pre>
<p>In all these classes there are two main Methods which deservers to be stated here. parse() and unparse(). If you are Importing then parse() should be defined in your profile, because you are parsing the data that is required by the System. In case of Exporting, you already have the parsed data of the system as source, you will then need to unparse() the data into Human readable format. You can refer to images above to understand more clearly.</p>
<p>So by the end of this during the profile run you will have Parsed/Unparsed data saved in the batch table, in you hand.</p>
<h2><strong>Mapper</strong></h2>
<p>Magento&#8217;s Dataflow is so flexible that you can set the header of the CSV or XML files that can mapped to the Magento&#8217;s default attributes. Let&#8217;s take an example if you want to export the product&#8217;s name into CSV with the CSV header as &#8220;Product Name&#8221;, you can specify that mapping in your profile where the Mapper will act. And in this the Magento&#8217;s attribute code &#8220;name&#8221; will be mapped to your specified &#8220;Product Name&#8221;. To do all this mapping rules, Mapper is there.</p>
<p>It retrives the Parsed/Unparsed Data from the batch table, we got at the end of Parser&#8217;s work, Maps to the rule we defined and then again saves back to the same table. Easy!</p>
<p>There is one default Mapper for all</p>
<p><strong>Mapper	: Mage_Dataflow_Model_Convert_Mapper_Column </strong></p>
<p>With one obvious method map().</p>
<p>At the end of this stage you will have your Parsed/Unparsed &#8211; Mapped Data in your dataflow table.</p>
<h2><strong>Adapter (Again)</strong></h2>
<p>At last the Adapter will use the dataflow&#8217;s batch data to save(). And after all the rows of the batch table for one batch is acted upon the profile is complete.</p>
<p>I guess this is the general way of explaining it, please comment if I am mistake, coz I am also new to this! LOL.</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/general-workflow-of-magentos-importexport-dataflow/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Product Import In Magento Alongwith Updating The Attribute&#039;s Options</title>
		<link>http://subesh.com.np/2009/11/product-import-in-magento-alongwith-updating-the-attributes-options/</link>
		<comments>http://subesh.com.np/2009/11/product-import-in-magento-alongwith-updating-the-attributes-options/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:50:34 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Import/Export]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Dataflow]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[Import]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=97</guid>
		<description><![CDATA[As you may know or not ! Magento is the fastest growing eCommerce plateform, nowonder because Magento has a lots of flexibility in it. You can feel that too if you are a just a user and as for me as Programmer I just Love it. One of the salient feature that makes Magento a [...]]]></description>
			<content:encoded><![CDATA[<p>As you may know or not ! Magento is the fastest growing eCommerce plateform, nowonder because Magento has a lots of flexibility in it. You can feel that too if you are a just a user and as for me as Programmer I just Love it. One of the salient feature that makes Magento a leader in eCommerce software is its ability to Import and Export data to an from the system.</p>
<p>Magento gives you a default interface to import or export data, but you will need the specific format of your data.It is easy to customize that as well, but today lets be interested in standard import, but with one small (Yet important) modification. The important modification in the standard code is this code will be able to options to the attribute of <strong>Select/Multiselect/Radio/Checkbox</strong> input type, while the product is being imported.</p>
<p>By default Magento only imports the values of the option, of any attribute, which are already avaliable. But this code can be used to create option at run time if it does not exits and assign to the product, during import. For doing this we need to first set up an Advanced Profile of Export/Import. Go to <strong>System&#8211;>Import/Export&#8211;>Advanced Profile</strong> and create new Profile. Then in the Action XML paste this.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;!--
Path=Path of the file relative to ROOT
filename= File name of the XML(MS EXCEL 2003) where import data is saved in Magento's Format
format	= XML
You can use CSV as well.
--&gt;
&lt;action type=&quot;dataflow/convert_adapter_io&quot; method=&quot;load&quot;&gt;
    &lt;var name=&quot;type&quot;&gt;file&lt;/var&gt;
    &lt;var name=&quot;path&quot;&gt;var/import&lt;/var&gt;
    &lt;var name=&quot;filename&quot;&gt;&lt;![CDATA[products.xml]]&gt;&lt;/var&gt;
    &lt;var name=&quot;format&quot;&gt;&lt;![CDATA1]&gt;&lt;/var&gt;
&lt;/action&gt;

&lt;!--
adapter= Your Model path
--&gt;
&lt;action type=&quot;dataflow/convert_parser_xml_excel&quot; method=&quot;parse&quot;&gt;
    &lt;var name=&quot;single_sheet&quot;&gt;&lt;![CDATA[]]&gt;&lt;/var&gt;
    &lt;var name=&quot;fieldnames&quot;&gt;true&lt;/var&gt;
    &lt;var name=&quot;store&quot;&gt;&lt;![CDATA[0]]&gt;&lt;/var&gt;
    &lt;var name=&quot;number_of_records&quot;&gt;1&lt;/var&gt;
    &lt;var name=&quot;decimal_separator&quot;&gt;&lt;![CDATA[.]]&gt;&lt;/var&gt;
    &lt;var name=&quot;adapter&quot;&gt;yourmodel/import&lt;/var&gt;
    &lt;var name=&quot;method&quot;&gt;save&lt;/var&gt;
&lt;/action&gt;
</pre>
<p>The Model defined in the adapter should be like this. You can create a new module for this.</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php
class Namespace_Module_Model_Import extends Mage_Catalog_Model_Convert_Adapter_Product {

	/**
	 * Save product (import)
	 * @param array $importData
	 * @throws Mage_Core_Exception
	 * @return bool
	 */
	public function saveRow(array $importData)
	{
		$product = $this-&gt;getProductModel()
		-&gt;reset();

		if (empty($importData['store'])) {
			if (!is_null($this-&gt;getBatchParams('store'))) {
				$store = $this-&gt;getStoreById($this-&gt;getBatchParams('store'));
			} else {
				$message = Mage::helper('catalog')-&gt;__('Skip import row, required field &quot;%s&quot; not defined', 'store');
				Mage::throwException($message);
			}
		}
		else {
			$store = $this-&gt;getStoreByCode($importData['store']);
		}

		if ($store === false) {
			$message = Mage::helper('catalog')-&gt;__('Skip import row, store &quot;%s&quot; field not exists', $importData['store']);
			Mage::throwException($message);
		}

		if (empty($importData['sku'])) {
			$message = Mage::helper('catalog')-&gt;__('Skip import row, required field &quot;%s&quot; not defined', 'sku');
			Mage::throwException($message);
		}
		$product-&gt;setStoreId($store-&gt;getId());
		$productId = $product-&gt;getIdBySku($importData['sku']);

		if ($productId) {
			$product-&gt;load($productId);
		}
		else {
			$productTypes = $this-&gt;getProductTypes();
			$productAttributeSets = $this-&gt;getProductAttributeSets();

			/**
			 * Check product define type
			 */
			if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) {
				$value = isset($importData['type']) ? $importData['type'] : '';
				$message = Mage::helper('catalog')-&gt;__('Skip import row, is not valid value &quot;%s&quot; for field &quot;%s&quot;', $value, 'type');
				Mage::throwException($message);
			}
			$product-&gt;setTypeId($productTypes[strtolower($importData['type'])]);
			/**
			 * Check product define attribute set
			 */
			if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) {
				$value = isset($importData['attribute_set']) ? $importData['attribute_set'] : '';
				$message = Mage::helper('catalog')-&gt;__('Skip import row, is not valid value &quot;%s&quot; for field &quot;%s&quot;', $value, 'attribute_set');
				Mage::throwException($message);
			}
			$product-&gt;setAttributeSetId($productAttributeSets[$importData['attribute_set']]);

			foreach ($this-&gt;_requiredFields as $field) {
				$attribute = $this-&gt;getAttribute($field);
				if (!isset($importData[$field]) &amp;amp;amp;amp;&amp;amp;amp;amp; $attribute &amp;amp;amp;amp;&amp;amp;amp;amp; $attribute-&gt;getIsRequired()) {
					$message = Mage::helper('catalog')-&gt;__('Skip import row, required field &quot;%s&quot; for new products not defined', $field);
					Mage::throwException($message);
				}
			}
		}

		$this-&gt;setProductTypeInstance($product);

		if (isset($importData['category_ids'])) {
			$product-&gt;setCategoryIds($importData['category_ids']);
		}

		foreach ($this-&gt;_ignoreFields as $field) {
			if (isset($importData[$field])) {
				unset($importData[$field]);
			}
		}

		if ($store-&gt;getId() != 0) {
			$websiteIds = $product-&gt;getWebsiteIds();
			if (!is_array($websiteIds)) {
				$websiteIds = array();
			}
			if (!in_array($store-&gt;getWebsiteId(), $websiteIds)) {
				$websiteIds[] = $store-&gt;getWebsiteId();
			}
			$product-&gt;setWebsiteIds($websiteIds);
		}

		if (isset($importData['websites'])) {
			$websiteIds = $product-&gt;getWebsiteIds();
			if (!is_array($websiteIds)) {
				$websiteIds = array();
			}
			$websiteCodes = split(',', $importData['websites']);
			foreach ($websiteCodes as $websiteCode) {
				try {
					$website = Mage::app()-&gt;getWebsite(trim($websiteCode));
					if (!in_array($website-&gt;getId(), $websiteIds)) {
						$websiteIds[] = $website-&gt;getId();
					}
				}
				catch (Exception $e) {}
			}
			$product-&gt;setWebsiteIds($websiteIds);
			unset($websiteIds);
		}

		foreach ($importData as $field =&gt; $value) {
			if (in_array($field, $this-&gt;_inventoryFields)) {
				continue;
			}
			if (in_array($field, $this-&gt;_imageFields)) {
				continue;
			}

			$attribute = $this-&gt;getAttribute($field);

			if (!$attribute) {
				continue;
			}

			$isArray = false;
			$setValue = $value;

			if ($attribute-&gt;getFrontendInput() == 'multiselect') {
				$value = split(self::MULTI_DELIMITER, $value);
				$isArray = true;
				$setValue = array();
			}

			if ($value &amp;amp;amp;amp;&amp;amp;amp;amp; $attribute-&gt;getBackendType() == 'decimal') {
				$setValue = $this-&gt;getNumber($value);
			}

			/**CODE MODIFICATION STARTS HERE*/

			$optionLabelArray=array();
			if ($attribute-&gt;usesSource()) {
			 $options = $attribute-&gt;getSource()-&gt;getAllOptions(false);

			 /**
			  * Update the Source of the attribute when source has no options.
			  */
			 if(count($options)&lt;1){
			 	if($isArray){
			 		foreach($value as $key=&gt;$subvalue){
			 			if(!in_array($subvalue,$newOptionLabelArray)){
			 				$setValue[]=$this-&gt;updateSourceAndReturnId($field,$subvalue);
			 				array_push($newOptionLabelArray,$subvalue);
			 			}
			 		}
			 	}
			 	else{
			 		if(!in_array($value,$newOptionLabelArray)){
			 			$setValue=$this-&gt;updateSourceAndReturnId($field,$value);
			 			array_push($newOptionLabelArray,$value);
			 		}
			 	}
			 }

			 /**
			  * Work on the source when it has options
			  */
			 else{
			 	/**
			 	 * This is the case of Multi-Select
			 	 */
			 	if ($isArray) {
			 		foreach ($options as $item) {
			 			/** Setting the option's ID if Label matches with the current value of XML column.*/
			 			if (in_array($item['label'], $value)) {
			 				$setValue[] = trim($item['value']);
			 				array_push($optionLabelArray,$item['label']); /**Adding Reference to worked attribute option**/
			 			}
			 		}

			 		/**
			 		 *  Checking in the current XML column value if all values were used in the above loop or not
			 		 *  If not used then they are new options value, then new option is created and then assigned.
			 		 **/

			 		foreach($value as $key=&gt;$subvalue){
			 			if(!in_array($subvalue,$optionLabelArray)){
			 				$setValue[]=$this-&gt;updateSourceAndReturnId($field,$subvalue);
			 			}
			 		}

			 	}
			 	/**This is the case of single select**/

			 	else {
			 		$setValue = null;
			 		$newOptionLabelArray=array();
			 		foreach ($options as $item) {
			 			if ($item['label'] == $value) {
			 				$setValue = $item['value'];
			 				array_push($optionLabelArray,$item['label']); /**Adding Reference to worked attribute option**/
			 			}
			 		}
			 		/**
			 		 *  Checking in the current XML column value if all values were used in the above loop or not
			 		 *  If not used then they are new options value, then new option is created and then assigned.
			 		 **/
			 		if(!in_array($value,$optionLabelArray)){
			 			$setValue=$this-&gt;updateSourceAndReturnId($field,$value);
			 		}
			 	}
			 }
			}

			/**CODE MODIFICATION ENDS HERE*/

			$product-&gt;setData($field, $setValue);
		}

		if (!$product-&gt;getVisibility()) {
			$product-&gt;setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
		}

		$stockData = array();
		$inventoryFields = isset($this-&gt;_inventoryFieldsProductTypes[$product-&gt;getTypeId()])
		? $this-&gt;_inventoryFieldsProductTypes[$product-&gt;getTypeId()]
		: array();
		foreach ($inventoryFields as $field) {
			if (isset($importData[$field])) {
				if (in_array($field, $this-&gt;_toNumber)) {
					$stockData[$field] = $this-&gt;getNumber($importData[$field]);
				}
				else {
					$stockData[$field] = $importData[$field];
				}
			}
		}
		$product-&gt;setStockData($stockData);

		$imageData = array();
		foreach ($this-&gt;_imageFields as $field) {
			if (!empty($importData[$field]) &amp;amp;amp;amp;&amp;amp;amp;amp; $importData[$field] != 'no_selection') {
				if (!isset($imageData[$importData[$field]])) {
					$imageData[$importData[$field]] = array();
				}
				$imageData[$importData[$field]][] = $field;
			}
		}

		foreach ($imageData as $file =&gt; $fields) {
			try {
				$product-&gt;addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $file, $fields);
			}
			catch (Exception $e) {}
		}

		$product-&gt;setIsMassupdate(true);
		$product-&gt;setExcludeUrlRewrite(true);
		$product-&gt;save();

		return true;
	}

	/**
	 * Updates the source of the attribute by the current new value in the XML column, and returns
	 * the id of the newly created option.
	 *
	 * @param string $attribute_code
	 * @param string $newOption
	 * @return int|string New Option Id
	 */
	public function updateSourceAndReturnId($attribute_code,$newOption){
		$attribute_model        = Mage::getModel('eav/entity_attribute');
		$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;

		$attribute_code         = $attribute_model-&gt;getIdByCode('catalog_product', $attribute_code);
		$attribute              = $attribute_model-&gt;load($attribute_code);
		$attribute_table        = $attribute_options_model-&gt;setAttribute($attribute);
		try{
			$value['option'] = array(trim($newOption),trim($newOption));
			$result = array('value' =&gt; $value);
			$attribute-&gt;setData('option',$result);
			$attribute-&gt;save();
		}
		catch(Exception $e){}
		$options = $attribute_options_model-&gt;getAllOptions(false);
		foreach($options as $option)
		{
			if ($option['label'] == $newOption)
			{
				return $option['value'];
			}
		}
		return &quot;&quot;;
	}

}

?&gt;
</pre>
<p>Please note the /**CODE MODIFICATION ENDS HERE*/ block. Most of the description is on the code. I got it working, feel free to ask if you got any problem. I am also working on importing custom option. I&#8217;ll soon make a post in it as well.</p>
<p><a href="http://subeshexamples.googlecode.com/files/productimport.rar">Download Source[Updated]</a></p>
<p>Here&#8217;s the sample import sheet with request from the reader</p>
<p><a href="http://spreadsheets.google.com/ccc?key=0Aji4wlRfG_gjdFEzRF9nVWFvZTRlMEZ5WGcxUWV4ZGc&#038;hl=en">Sample Sheet</a></p>
<p><iframe width='500' height='300' frameborder='0' src='http://spreadsheets.google.com/pub?key=tQ3D_gUaoe4e0FyXg1Qexdg&#038;single=true&#038;gid=0&#038;output=html&#038;widget=true'></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/11/product-import-in-magento-alongwith-updating-the-attributes-options/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>

