<?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; custom options</title>
	<atom:link href="http://subesh.com.np/tag/custom-options/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>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>Adding custom options to a product in Magento</title>
		<link>http://subesh.com.np/2009/12/adding-custom-options-product-magento/</link>
		<comments>http://subesh.com.np/2009/12/adding-custom-options-product-magento/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 10:25:20 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[custom options]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=155</guid>
		<description><![CDATA[Adding custom option in Magento is pretty easy! You just need to know the format of an array, which is taken by catalog/product_option Model to set the custom option. I&#8217;ve deviced a simple function (setCustomOption) that just does that. The function, according to the input type and values assigned creates an array, which is then [...]]]></description>
			<content:encoded><![CDATA[<p>Adding custom option in Magento is pretty easy! You just need to know the format of an array, which is taken by catalog/product_option Model to set the custom option. I&#8217;ve deviced a simple function (<strong>setCustomOption</strong>) that just does that. The function, according to the input type and values assigned creates an array, which is then used by the <strong>catalog/product_option</strong> Model to save the option to the product.</p>
<p>Here is the function.</p>
<pre class="brush: php; title: ; notranslate">
/**
	 * @param $value - Must be comma seperated options.
	 * @param $title - Title of the custom option.
	 * @param $type - Type of custom option - drop_down,radio,checkbox,multiple,area,field.
	 * @param $noOption - Specifies if the custom options has options or not.
	 */
	function setCustomOption ($value, $title, $type, $noOption = false)
	{
		$custom_options = array();
		if ($type &amp;&amp; $value != &quot;&quot; &amp;&amp; $value) {
			$values = explode(',', $value);
			if (count($values)) {
				/**If the custom option has options*/
				if (! $noOption) {
					$is_required = 0;
					$sort_order = 0;
					$custom_options[] = array(
						'is_delete' =&gt; 0 , 'title' =&gt; $title , 'previous_group' =&gt; '' , 'previous_type' =&gt; '' , 'type' =&gt; $type , 'is_require' =&gt; $is_required , 'sort_order' =&gt; $sort_order , 'values' =&gt; array()
					);
					foreach ($values as $v) {
						$titleopt = ucfirst(trim($v));
						switch ($type) {
							case 'drop_down':
							case 'radio':
							case 'checkbox':
							case 'multiple':
							default:
								$title = ucfirst(trim($v));
								$custom_options[count($custom_options) - 1]['values'][] = array(
									'is_delete' =&gt; 0 , 'title' =&gt; $titleopt , 'option_type_id' =&gt; - 1 , 'price_type' =&gt; '' , 'price' =&gt; '' , 'sku' =&gt; '' , 'sort_order' =&gt; ''
								);
							break;
						}
					}
					return $custom_options;
				}
				/**If the custom option doesn't have options | Case: area and field*/
				else {
					$is_required = 0;
					$sort_order = '';
					$custom_options[] = array(
						&quot;is_delete&quot; =&gt; 0 , &quot;title&quot; =&gt; $title , &quot;previous_group&quot; =&gt; &quot;text&quot; , &quot;price_type&quot; =&gt; 'fixed' , &quot;price&quot; =&gt; '' , &quot;type&quot; =&gt; $type , &quot;is_required&quot; =&gt; $is_required
					);
					return $custom_options;
				}
			}
		}
		return false;
	}
</pre>
<p>And to save the custom option, first get the array built by the above function and pass it to the <strong>catalog/product_option</strong> Model&#8217;s function to save. Here&#8217;s how you do it.</p>
<pre class="brush: php; title: ; notranslate">

$arrayOption = array();
	/**
	 * For Creating dropdown,select,multiselect,radio type of custom option
	 */
	$arrayOption[] = setCustomOption(&quot;OPT1,OPT2&quot;, &quot;Select Option&quot;, &quot;drop_down&quot;);
	/**
	 * For Creating textfield and textarea type of custom option
	 */
	$arrayOption[] = setCustomOption(&quot;Anyvalue&quot;, &quot;Area&quot;, &quot;area&quot;, true);
	/**
	 * Load the product you want to assign custom option to
	 */
	$product = Mage::getModel(&quot;catalog/product&quot;)-&gt;load(167);
	foreach ($arrayOption as $options) {
		foreach ($options as $option) {
			$opt = Mage::getModel('catalog/product_option');
			$opt-&gt;setProduct($product);
			$opt-&gt;addOption($option);
			$opt-&gt;saveOptions();
		}
	}
</pre>
<p>After running the code you will get something like this.</p>
<div id="attachment_156" class="wp-caption alignnone" style="width: 357px"><img src="http://subesh.com.np/wp-content/uploads/2009/12/opt.png" alt="Custom Option added to a Product" title="Custom Option added to a Product" width="347" height="374" class="size-full wp-image-156" /><p class="wp-caption-text">Custom Option added to a Product</p></div>
<p>Hope you like this post!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/adding-custom-options-product-magento/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Getting all custom options of a product in Magento</title>
		<link>http://subesh.com.np/2009/12/custom-options-product-magento/</link>
		<comments>http://subesh.com.np/2009/12/custom-options-product-magento/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 09:44:03 +0000</pubDate>
		<dc:creator>Subesh Pokhrel</dc:creator>
				<category><![CDATA[Custom Module]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[custom options]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://subesh.com.np/?p=153</guid>
		<description><![CDATA[Custom options are the options that can be added to any product, which gives an option for the user of the site to select what type of product they actually want. Here is a scenario where custom option can be helpful. If you have a product say ball and your stores sells plastic,rubber,glass balls. So [...]]]></description>
			<content:encoded><![CDATA[<p>Custom options are the options that can be added to any product, which gives an option for the user of the site to select what type of product they actually want. Here is a scenario where custom option can be helpful. If you have a product say ball and your stores sells plastic,rubber,glass balls. So you need to give the user to select what type of ball they actually want. Yes, you can do this by using configurable product as well, but why create an attribute for one product only! In this case custom option might be very helpful.</p>
<p>Here&#8217;s the code to get the all the custom options of a product. Please see that you need to specify the id of the product for which you are retriving custom option for. I&#8217;ve echoed some text as well to give you an idea what exactly you are getting in each loop.</p>
<pre class="brush: php; title: ; notranslate">
$product = Mage::getModel(&quot;catalog/product&quot;)-&gt;load(167);
	$i = 1;

	echo &quot;&lt;pre&gt;&quot;;

	foreach ($product-&gt;getOptions() as $o) {

		echo &quot;&lt;strong&gt;Custom Option:&quot; . $i . &quot;&lt;/strong&gt;&lt;br/&gt;&quot;;
		echo &quot;Custom Option TYPE: &quot; . $o-&gt;getType() . &quot;&lt;br/&gt;&quot;;
		echo &quot;Custom Option TITLE: &quot; . $o-&gt;getTitle() . &quot;&lt;br/&gt;&quot;;
		echo &quot;Custom Option Values: &lt;br/&gt;&quot;;

		// Getting Values if it has option values, case of select,dropdown,radio,multiselect

		$values = $o-&gt;getValues();
		foreach ($values as $v) {

				print_r($v-&gt;getData());
		}

		$i++;

		echo &quot;----------------------------------&lt;br/&gt;&quot;;
	}
</pre>
<p>Happy coding in Magento!</p>
]]></content:encoded>
			<wfw:commentRss>http://subesh.com.np/2009/12/custom-options-product-magento/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

