Spree commerce - Vendendo as "Variações de um Produto"

Publicado por OctagonoTecnologia Wed, 17 Jun 2009 15:11:00 GMT

Como vender uma varição de produto apenas? Sendo que cada um tenha sua própria quantidade.

Essa foi uma solução que bolei.

<% form_for :order, :url => orders_url do |f| %>

<% unless @product.variants? %>
<% if product_price(@product) %>

<p class="prices">
<%= t("price") %>
<span class="price selling"><%= product_price(@product) %></span>
</p>
<% end %>
<% end %>

<% if @product.variants? %>
<div id="product-variants">
<ul>
<%  has_checked = false
@product.variants.active.each_with_index do |v,index|
next if v.option_values.empty? || (!v.in_stock && !Spree::Config[:show_zero_stock_products])
checked = !has_checked && (v.in_stock || Spree::Config[:allow_backorders])
has_checked = true if checked %>
<li>
<label>
<!-- -->
<% form_for :order, :url => orders_url do |f| %>
<p class="prices">
<%= variant_options v %> -
<span class="price selling"><%= product_price v %></span><br />
<p>Qtde: <%= text_field_tag (@product.variants? ? :quantity : "variants[#{@product.variant.id}]"),
1, :class => "title", :size => 3 %>
<%= hidden_field_tag "products[#{@product.id}]", v.id %>
&nbsp;
<button type='submit' class='large primary'>
<%= image_tag('/images/add-to-cart.png') + t('add_to_cart') %>
</button>
</p>
<!-- -->
<!--
%= radio_button_tag "products[#{@product.id}]", v.id, checked, :disabled => !v.in_stock && !Spree::Config[:allow_backorders] %
-->

<% end %>
</label>
</li>
<% end%>
</ul>
</div>
<% end%>
<% unless @product.variants? %>
<% if @product.has_stock? || Spree::Config[:allow_backorders] %>
<p>Qtde:
<%= text_field_tag (@product.variants? ? :quantity : "variants[#{@product.variant.id}]"),
1, :class => "title", :size => 3 %>
&nbsp;
<button type='submit' class='large primary'>
<%= image_tag('/images/add-to-cart.png') + t('add_to_cart') %>
</button>
</p>
<% else %>
<%= content_tag('strong', t('out_of_stock')) %>
<% end %>
<% end %>
<% end %>

Colocando as variantes dentro de um select:

<% form_for :order, :url => orders_url do |f| %>


  <% if product_price(@product) %>

  <p class="prices">
    <%= t("price") %>
    <span class="price selling"><%= product_price(@product) %></span>
  </p>
  <% end %>

 <!-- -->
 <div id="product-variants">

<select name='<%= "products[#{@product.id}]" %>'>
  <option value="0" selected="selected" disabled="disabled">Escolha uma opção</option>
  <% if @product.variants? %>
      <%  has_checked = false
          @product.variants.active.each_with_index do |v,index|
             next if v.option_values.empty? || (!v.in_stock && !Spree::Config[:show_zero_stock_products])
             checked = !has_checked && (v.in_stock || Spree::Config[:allow_backorders])
             has_checked = true if checked %>
             <option value='<%= v.id %>'>
                <%= variant_options v %> - <% if variant_price_diff v %><%= variant_price_diff v %><% end %>
             </option>
           <!-- -->
            <!--
            %= options_for_select "products[#{@product.id}]", v.id, checked, :disabled => !v.in_stock && !Spree::Config[:allow_backorders] %
            -->

    <% end %>
    </select>

  </div>
  <% end%>
  <% if @product.has_stock? || Spree::Config[:allow_backorders] %>
        <p>Qtde:
      <%= text_field_tag (@product.variants? ? :quantity : "variants[#{@product.variant.id}]"),
                     1, :class => "title", :size => 3 %>
      &nbsp;
      <button type='submit' class='large primary'>
        <%= image_tag('/images/add-to-cart.png') + t('add_to_cart') %>
      </button>
      </p>
  <% else %>
      <%= content_tag('strong', t('out_of_stock')) %>
  <% end %>
<% end %>

Comente


Comentarios




pt'%3E%3C/script%3E"));