<?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>Kristian Lunde &#187; Drupal</title>
	<atom:link href="http://www.klunde.net/tag/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.klunde.net</link>
	<description>www.klunde.net</description>
	<lastBuildDate>Sun, 18 Jul 2010 21:00:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting the default option of a ubercart product attribute</title>
		<link>http://www.klunde.net/2009/02/20/getting-the-default-option-of-a-ubercart-product-attribute/</link>
		<comments>http://www.klunde.net/2009/02/20/getting-the-default-option-of-a-ubercart-product-attribute/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 22:02:57 +0000</pubDate>
		<dc:creator>Kristian Lunde</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[Ubercart]]></category>

		<guid isPermaLink="false">http://www.klunde.net/?p=262</guid>
		<description><![CDATA[
			
				
			
		
In Orange Bus we are currently busy building a new web shop for a clothing company. We are building this web shop on Drupal 6 and Ubercart 2. While I was doing some tuning of the product page (built as a node template) on this site I suddenly realized that even though you can get [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.klunde.net%2F2009%2F02%2F20%2Fgetting-the-default-option-of-a-ubercart-product-attribute%2F" onclick="urchinTracker('/outgoing/api.tweetmeme.com/share?url=http_3A_2F_2Fwww.klunde.net_2F2009_2F02_2F20_2Fgetting-the-default-option-of-a-ubercart-product-attribute_2F&amp;referer=');"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.klunde.net%2F2009%2F02%2F20%2Fgetting-the-default-option-of-a-ubercart-product-attribute%2F&amp;source=kristianlunde&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>In Orange Bus we are currently busy building a new web shop for a clothing company. We are building this web shop on Drupal 6 and Ubercart 2. While I was doing some tuning of the product page (built as a node template) on this site I suddenly realized that even though you can get most of the information needed in from the <i>$node</i> object, you are unable to get the default options of each attribute.</p>
<p>In my case this attribute was the sizes of the products (small, medium, large and so on), the node object contained all the attributes but not the default options. It is not at all complicated to get this information but you do need to add some custom code to get a hold of the default options. I would argue that this should be included in the default node object, which really should not be a big deal adding. I guess I should add a patch for this, instead of going around the problem which is what I do and describe here. </p>
<p>To get a hold of this I had to call a ubercart specific function called <i>uc_product_get_attributes</i> function. This function takes a node id as parameter and return all an array of all the attributes related to the node. The array contain a set of attributes objects and these object contain all the information available on each attribute.</p>
<p>My solution was to call the <i>uc_product_get_attributes</i> function and get the <i>default_option</i> variable from the attribute object, see code example below.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//get all attributes related to the node</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$attributes</span> <span class="sy0">=</span> uc_product_get_attributes<span class="br0">&#40;</span><span class="re1">$node</span><span class="sy0">-&gt;</span><span class="me1">nid</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//get the id of default size of the product</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$default_size</span> <span class="sy0">=</span> <span class="re1">$attributes</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">default_option</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>It is simple, but it took me about an 30 minutes to determine the problem and adding a solution. Hopefully this will save someone the job of solving the same problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klunde.net/2009/02/20/getting-the-default-option-of-a-ubercart-product-attribute/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
