Skip to content

Commit

Permalink
Added a mechanism for adding/editing and removing volume prices for v…
Browse files Browse the repository at this point in the history
…ariants.
  • Loading branch information
schof committed Nov 21, 2008
1 parent c123cbb commit 7d34699
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/models/volume_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class VolumePrice < ActiveRecord::Base
belongs_to :variant
acts_as_list :scope => :variant
validates_presence_of :variant
validates_presence_of :amount

OPEN_ENDED = /\([0-9]+\+\)/

Expand Down
14 changes: 14 additions & 0 deletions app/views/admin/variants/_volume_price.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<tr class="volume_price">
<td valign="top"><%=@variant.sku %></td>
<td valign="top"><%=@variant.product.name %></td>
<td valign="top"><%=variant_options @variant %></td>
<td valign="top">
<%= f.error_message_on(:range) %>
<%=f.text_field(:range, :size => 10)%>
</td>
<td valign="top">
<%= f.error_message_on(:amount) %>
<%=f.text_field(:amount, :size => 10)%>
</td>
<td valign="top"><%= f.remove_link t("Delete") %></td>
</tr>
27 changes: 27 additions & 0 deletions app/views/admin/variants/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render :partial => 'shared/product_sub_menu' %>
<h1><%= t("Editing Product") %></h1>
<%= render :partial => 'shared/product_tabs', :locals => {:current => "Variants"} %>
<%= error_messages_for :variant %>

<% form_for(:variant, :url => object_url, :html => { :method => :put }) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<h3><%= t("Volume Prices") %></h3>
<table class="admin-report" width="545">
<thead>
<tr>
<th><%=t("SKU")%></th>
<th width="150"><%=t("Product")%></th>
<th><%=t("Variant")%></th>
<th><%=t("Range")%></th>
<th><%=t("Amount")%></th>
<th><%=t("Actiion")%></th>
</tr>
</thead>
<tbody id="volume_prices">
<%= f.render_associated_form(@variant.volume_prices) %>
</tbody>
</table>
<%= f.add_associated_link(t("Add Volume Price"), @variant.volume_prices.build) %>
<br/><br/>
<%= render :partial => 'shared/edit_resource_links' %>
<% end %>
4 changes: 4 additions & 0 deletions lang/en-US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
volume_prices: Volume Prices
new_volume_price: New Volume Price
edit_volume_price: Edit Volume Price
range: Range
20 changes: 14 additions & 6 deletions volume_pricing_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ class VolumePricingExtension < Spree::Extension
description "Describe your extension here"
url "http://yourwebsite.com/volume_pricing"

# define_routes do |map|
# map.namespace :admin do |admin|
# admin.resources :whatever
# end
# end
define_routes do |map|
map.namespace :admin do |admin|
admin.resources :volume_prices, :collection => {:variants => :get}
end
map.namespace :admin do |admin|
admin.resources :variants, :has_many => :volume_prices, :dependent => :destroy, :attributes => true
end
end

def activate
Variant.class_eval do
has_many :volume_prices, :order => :position
has_many :volume_prices, :attributes => true, :order => :position, :dependent => :destroy
end

Order.class_eval do
Expand Down Expand Up @@ -54,6 +57,11 @@ def to_range
end
end

Admin::VariantsController.class_eval do
update.before do
params[:variant][:volume_price_attributes] ||= {}
end
end
end

end

0 comments on commit 7d34699

Please sign in to comment.