<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Default Variants, revisited</title>
    <link>http://forums.shopify.com/categories/2/posts/30338</link>
    <language>en-us</language>
    <description>Feed for discussion topic Default Variants, revisited</description>
    <item>
      <title>Default Variants, revisited</title>
      <author>hana_nell</author>
      <pubDate>Sun, 18 Oct 2009 20:21:57 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/30338</link>
      <guid>http://forums.shopify.com/categories/2/posts/30338</guid>
      <description>&lt;p&gt;I really hope someone can help me with this, because I am absolutely&amp;nbsp;&lt;strong&gt;stuck&lt;/strong&gt; and have no other recourse. I am trying to do something fairly simple which has been discussed on the forums before, but the solutions are from several years ago and I suspect Shopify may have changed a bit in the meantime because I cannot get them to work for my store.&lt;/p&gt;
&lt;p&gt;I want to hide the 'default' variable drop-down for items that only have one variable. I have items with multiple variables as well, and those should not be affected (i.e. the drop-down should remain for those items.) I am using the prettify template.&lt;/p&gt;
&lt;p&gt;Here is the entire code for the product.liquid page:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&amp;lt;div id="product"&amp;gt;
  &amp;lt;div id="product-main"&amp;gt; {% for image in product.images %}
    {% if forloop.first %}
    &amp;lt;div id="prod-img"&amp;gt; &amp;lt;img src="{{ image | product_img_url: 'large'}}" alt="{{product.title}}" /&amp;gt; &amp;lt;/div&amp;gt;
    {% else %}
    &amp;lt;div class="prod-img-small fl"&amp;gt; &amp;lt;a href="{{ image | product_img_url: 'large' }}" rel="lightbox"&amp;gt; &amp;lt;img src="{{ image | product_img_url: 'small'}}" alt="{{product.title}}" /&amp;gt; &amp;lt;/a&amp;gt; &amp;lt;/div&amp;gt;
    {% endif %}
    {% endfor %} 
&amp;lt;/div&amp;gt;
&amp;lt;div id="variant-add"&amp;gt;
  &amp;lt;h2&amp;gt;{{ product.title }}&amp;lt;/h2&amp;gt;
&amp;lt;/div&amp;gt;
  &amp;lt;div id="description" class="textile"&amp;gt; {{ product.description }} &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

  &amp;lt;div id="variant-add"&amp;gt;
    &amp;lt;form action="/cart/add" method="post"&amp;gt;
    
      &amp;lt;select id="variants" name='id'&amp;gt;
        {% for variant in product.variants %}
          &amp;lt;option value="{{ variant.id }}"&amp;gt;{{ variant.title }} - {{ variant.price | money }}&amp;lt;/option&amp;gt;
        {% endfor %}
      &amp;lt;/select&amp;gt;{% if product.variants.size &amp;lt; 1 %} 
&amp;lt;input type="hidden" name="id" value="{{ product.variants.first.id }}" /&amp;gt;{% endif %}
      &amp;lt;div class="addtocart"&amp;gt;{% if product.available == false %} &amp;lt;a href="mailto:&lt;a href="mailto:email@web.org"&gt;email@web.org&lt;/a&gt;?subject={{ product.title }}"&amp;gt;&amp;lt;img src="{{ 'soldout.gif' | asset_url }}" /&amp;gt;&amp;lt;/a&amp;gt;{% else %}         &amp;lt;input type="submit" name="add" value="Add to Cart" id="add" class="button" style="width:100px" src="asset_url" /&amp;gt; {% endif %} &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
  &amp;lt;/div&amp;gt;

      &amp;lt;div id="price-field"&amp;gt;&amp;lt;/div&amp;gt;



&amp;lt;script type="text/javascript"&amp;gt;
// &amp;lt;![CDATA[  
  // prototype callback for multi variants dropdown selector
  var selectCallback = function(variant, selector) {
    if (variant &amp;amp;&amp;amp; variant.available == true) {
      // selected a valid variant
      $('add').removeClassName('disabled'); // remove unavailable class from add-to-cart button
      $('add').disabled = false;           // reenable add-to-cart button
      $('price-field').innerHTML = Shopify.formatMoney(variant.price, "{{shop.money_with_currency_format}}");  // update price field
    } else {
      // variant doesn't exist
      $('add').addClassName('disabled');      // set add-to-cart button to unavailable class
      $('add').disabled = true;              // disable add-to-cart button      
      $('price-field').innerHTML = (variant) ? "Sold Out" : "Unavailable"; // update price-field message
    }
  };

  // initialize multi selector for product
  Event.observe(document, 'dom:loaded', function() {  
    new Shopify.OptionSelectors("variants", { product: {{ product | json }}, onVariantSelected: selectCallback }); 
  });
// ]]&amp;gt;
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;p&gt;Many thanks in advance!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Sun, 18 Oct 2009 21:44:09 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/30338#comment-30339</link>
      <guid>http://forums.shopify.com/categories/2/posts/30338#comment-30339</guid>
      <description>&lt;p&gt;Hello Hana,&lt;/p&gt;
&lt;p&gt;You are very close.&lt;/p&gt;
&lt;p&gt;Starting with the div with id 'variant-add'...&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&amp;lt;div id="variant-add"&amp;gt;
    &amp;lt;form action="/cart/add" method="post"&amp;gt;

    {% if product.variants.size == 1 %}

    &amp;lt;input name="id" value="{{ product.variants.first.id }}" type="hidden" /&amp;gt;

    {% else %}
    
      &amp;lt;select id="variants" name='id'&amp;gt;
        {% for variant in product.variants %}
          &amp;lt;option value="{{ variant.id }}"&amp;gt;{{ variant.title }} - {{ variant.price | money }}&amp;lt;/option&amp;gt;
        {% endfor %}
      &amp;lt;/select&amp;gt;

    {% endif %}

      &amp;lt;div class="addtocart"&amp;gt;{% if product.available == false %} &amp;lt;a href="mailto:&lt;a href="mailto:email@web.org"&gt;email@web.org&lt;/a&gt;?subject={{ product.title }}"&amp;gt;&amp;lt;img src="{{ 'soldout.gif' | asset_url }}" /&amp;gt;&amp;lt;/a&amp;gt;{% else %}         &amp;lt;input type="submit" name="add" value="Add to Cart" id="add" class="button" style="width:100px" src="asset_url" /&amp;gt; {% endif %} &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
  &amp;lt;/div&amp;gt;

      {% if product.variants.size == 1 %}

    &amp;lt;div id="price-field"&amp;gt;{{ product.price | money_with_currency }}&amp;lt;/div&amp;gt;

      {% else %}

   &amp;lt;div id="price-field"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
// &amp;lt;![CDATA[  
  // prototype callback for multi variants dropdown selector
  var selectCallback = function(variant, selector) {
    if (variant &amp;amp;&amp;amp; variant.available == true) {
      // selected a valid variant
      $('add').removeClassName('disabled'); // remove unavailable class from add-to-cart button
      $('add').disabled = false;           // reenable add-to-cart button
      $('price-field').innerHTML = Shopify.formatMoney(variant.price, "{{shop.money_with_currency_format}}");  // update price field
    } else {
      // variant doesn't exist
      $('add').addClassName('disabled');      // set add-to-cart button to unavailable class
      $('add').disabled = true;              // disable add-to-cart button      
      $('price-field').innerHTML = (variant) ? "Sold Out" : "Unavailable"; // update price-field message
    }
  };

  // initialize multi selector for product
  Event.observe(document, 'dom:loaded', function() {  
    new Shopify.OptionSelectors("variants", { product: {{ product | json }}, onVariantSelected: selectCallback }); 
  });
// ]]&amp;gt;
&amp;lt;/script&amp;gt;

     {% endif %}&lt;/pre&gt;
&lt;p&gt;Not tested!&lt;/p&gt;</description>
    </item>
    <item>
      <title>hana_nell commented</title>
      <author>hana_nell</author>
      <pubDate>Tue, 20 Oct 2009 13:28:35 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/30338#comment-30375</link>
      <guid>http://forums.shopify.com/categories/2/posts/30338#comment-30375</guid>
      <description>&lt;p&gt;It works! This calls for celebration.&amp;nbsp;Thank you so, so much!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Caroline Schnapp commented</title>
      <author>Caroline Schnapp</author>
      <pubDate>Tue, 20 Oct 2009 14:20:23 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/30338#comment-30377</link>
      <guid>http://forums.shopify.com/categories/2/posts/30338#comment-30377</guid>
      <description>&lt;p&gt;Coool. You're welcome!&lt;/p&gt;</description>
    </item>
    <item>
      <title>PeterM commented</title>
      <author>PeterM</author>
      <pubDate>Sat, 31 Oct 2009 14:39:57 +0000</pubDate>
      <link>http://forums.shopify.com/categories/2/posts/30338#comment-30682</link>
      <guid>http://forums.shopify.com/categories/2/posts/30338#comment-30682</guid>
      <description>&lt;p&gt;Most excellent! I also had the same mind-bending issue. This is a superb solution.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
