Allow multiple digital files to be attached to a single variant.
Useful for multi-format ebook downloads
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
Spree::LineItem.class_eval do
|
||||
|
||||
has_many :digital_links, :dependent => :destroy
|
||||
|
||||
after_save :create_digital_links, :if => :digital?
|
||||
|
||||
# Is this item digital?
|
||||
def digital?
|
||||
variant.digital?
|
||||
end
|
||||
@@ -15,8 +13,10 @@ Spree::LineItem.class_eval do
|
||||
def create_digital_links
|
||||
digital_links.delete_all
|
||||
|
||||
self.quantity.times do
|
||||
digital_links.create!(:digital => variant.digital)
|
||||
variant.digitals.each do |digital|
|
||||
self.quantity.times do
|
||||
digital_links.create!(:digital => digital)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
Spree::Variant.class_eval do
|
||||
|
||||
has_one :digital, :dependent => :destroy
|
||||
has_many :digitals, :dependent => :destroy
|
||||
after_save :destroy_digital, :if => :deleted?
|
||||
|
||||
# Is this variant to be downloaded by the customer?
|
||||
def digital?
|
||||
digital.present?
|
||||
digitals.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
<div class="yui-g">
|
||||
<div class="yui-u first">
|
||||
<%= form_for(:digital, :url => { :controller => 'digitals', :action => 'create' }, :html => { :multipart => true }) do |f| %>
|
||||
<div>
|
||||
<div>
|
||||
<%= form_for(:digital, :url => { :controller => 'digitals', :action => 'create' }, :html => { :multipart => true }) do |f| %>
|
||||
<fieldset>
|
||||
<legend><%= Spree::Variant.model_name.human %> "<%= variant.options_text %>"</legend>
|
||||
|
||||
<%= f.field_container :current_file do %>
|
||||
<strong><%=t 'current_file' %>:</strong><br/>
|
||||
<% if variant.digital? %>
|
||||
<%= render variant.digital %><%= %>
|
||||
<% else %>
|
||||
<%=t 'none' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p class="form-buttons">
|
||||
<% if variant.digital? %>
|
||||
<%= link_to t("delete_file"), admin_product_digital_url(:id => variant.digital.id), :confirm => t('delete_file_cofirmation', :filename => variant.digital.attachment_file_name), :method => :delete %>
|
||||
<% else %>
|
||||
<%= f.field_container :current_file do %>
|
||||
<strong><%=t 'files' %>:</strong>
|
||||
<% if variant.digital? %>
|
||||
<ul>
|
||||
<% variant.digitals.each do |digital| %>
|
||||
<li>
|
||||
<%= render digital %>
|
||||
<%= link_to t("delete_file"), admin_product_digital_url(:id => variant.digitals.first.id), :confirm => t('delete_file_cofirmation', :filename => variant.digitals.first.attachment_file_name), :method => :delete %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<%=t 'none' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= f.field_container :file do %>
|
||||
<%= f.label :file, t("new_file") %> <span class="required">*</span><br/>
|
||||
<%= f.file_field :attachment %>
|
||||
<% end %>
|
||||
|
||||
<%= hidden_field_tag 'digital[variant_id]', variant.id %>
|
||||
<p class="form-buttons">
|
||||
<%= f.field_container :file do %>
|
||||
<%= f.label :file, t("new_file") %> <span class="required">*</span><br/>
|
||||
<%= f.file_field :attachment %>
|
||||
<% end %>
|
||||
|
||||
<%= button t('spree_digital.upload') %>
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
</fieldset>
|
||||
<%= hidden_field_tag 'digital[variant_id]', variant.id %>
|
||||
|
||||
<%= button t('spree_digital.upload') %>
|
||||
</p>
|
||||
|
||||
</fieldset>
|
||||
<% end %>
|
||||
</div>
|
||||
</div><br/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user