<?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; Import</title>
	<atom:link href="http://subesh.com.np/tag/import/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>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 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[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>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; title: ; notranslate">
&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; title: ; notranslate">
&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; title: ; notranslate">
&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>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2010/01/creating-custom-sourced-multiselect-product-attribute/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Creating Block From the Code in Magento</title>
		<link>http://subesh.com.np/2009/12/creating-block-code-magento/</link>
		<comments>http://subesh.com.np/2009/12/creating-block-code-magento/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 13:15:43 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Block]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[Map Type]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=164</guid>
		<description><![CDATA[Here are some methods of creating block by code in Magento. This type of code can be used directly in template, not need to create a layout file or add a child node inside already existing layout file. You can use this to echo a different type of block inside already loading block and template. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some methods of creating block by code in Magento. This type of code can be used directly in template, not need to create a layout file or add a child node inside already existing layout file. You can use this to echo a different type of block inside already loading block and template.</p>
<pre class="brush: php; title: ; notranslate">
// Directly in the PHTML where you want to show the block
&lt;?php
echo $this-&gt;getLayout()-&gt;createBlock(&quot;module/block&quot;)-&gt;setTemplate(&quot;module/page.phtml&quot;)-&gt;toHtml();
?&gt;
</pre>
<p>What we have actually done is just load the layout and create an instance of a block class defined inside its paramerter, then assigned a template to the block and finally echoed as html. Simple! The code above will be equivalent to what we do as following in layout and in template file.</p>
<pre class="brush: xml; title: ; notranslate">
// In layout
&lt;block type=&quot;module/block&quot; name=&quot;module.name&quot; template=&quot;module/page.html&quot;/&gt;
</pre>
<pre class="brush: php; title: ; notranslate">
&lt;?php
// In parent PHTML
$this-&gt;getChildHtml(&quot;module.name&quot;);
?&gt;
</pre>
<p>May be helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/creating-block-code-magento/feed/</wfw:commentRss>
		<slash:comments>2</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>

