Skip to content

Loading…

Fix the supplier_image_form rendering partial #6

Closed
wants to merge 14 commits into from

3 participants

@theCrab

It should render a partial template

@theCrab

Template engine mix is the problem /app/views/spree/admin/suppliers/_supplier_image_form.html.haml instead of html.erb

@theCrab theCrab closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 19, 2012
  1. @djkz
  2. @djkz

    updating to spree 1

    djkz committed
  3. @djkz

    added spree namespace to invoice

    djkz committed
  4. @djkz

    fixed override path for admin

    djkz committed
Commits on Feb 21, 2012
  1. updated gemspec and versionfile

    johndavid400 committed
Commits on Feb 22, 2012
  1. porting

    johndavid400 committed
  2. fix partial link

    johndavid400 committed
  3. testing

    johndavid400 committed
  4. testing

    johndavid400 committed
  5. testing

    johndavid400 committed
Commits on Mar 21, 2013
  1. removed admin orders controller decorator to get rid of metasearch an…

    committed
    …d added attr accessible for creating suppliers
  2. updated readme

    committed
Commits on Mar 26, 2013
  1. @theCrab

    Fix partial rendering bug

    theCrab committed
    Instead of rendering the partial its looking for a template
Showing with 145 additions and 330 deletions.
  1. +17 −25 README.md
  2. +1 −0 Versionfile
  3. +3 −3 app/controllers/{ → spree}/admin/supplier_taxons_controller.rb
  4. +23 −29 app/controllers/{ → spree}/admin/suppliers_controller.rb
  5. +1 −1 app/controllers/{ → spree}/admin/vendor_overview_controller.rb
  6. 0 app/controllers/{ → spree}/invoice_items_controller.rb
  7. 0 app/controllers/{ → spree}/supplier_invoices_controller.rb
  8. +3 −5 app/controllers/{ → spree}/suppliers_controller.rb
  9. +1 −1 app/models/{ → spree}/invoice_item.rb
  10. +9 −0 app/models/spree/supplier.rb
  11. +1 −1 app/models/{ → spree}/supplier_invoice.rb
  12. +0 −8 app/models/supplier.rb
  13. +1 −1 app/overrides/admin.rb
  14. +0 −114 app/views/admin/products/_form.html.erb
  15. 0 app/views/{ → spree}/admin/orders/show.html.erb
  16. 0 app/views/{ → spree}/admin/orders/user.html.erb
  17. 0 app/views/{ → spree}/admin/products/_suppliers_form.html.erb
  18. 0 app/views/{ → spree}/admin/shared/_order_tabs_decide.html.erb
  19. 0 app/views/{ → spree}/admin/shared/_vendor_order_tabs.html.erb
  20. 0 app/views/{ → spree}/admin/supplier_taxons/_form.html.erb
  21. 0 app/views/{ → spree}/admin/supplier_taxons/_taxon_table.html.erb
  22. 0 app/views/{ → spree}/admin/supplier_taxons/available.js.erb
  23. 0 app/views/{ → spree}/admin/supplier_taxons/edit.html.erb
  24. 0 app/views/{ → spree}/admin/supplier_taxons/remove.html.erb
  25. 0 app/views/{ → spree}/admin/supplier_taxons/select.js.erb
  26. 0 app/views/{ → spree}/admin/supplier_taxons/selected.html.erb
  27. 0 app/views/{ → spree}/admin/suppliers/_edit_form.html.erb
  28. 0 app/views/{ → spree}/admin/suppliers/_edit_hours_form.html.erb
  29. +1 −13 app/views/{ → spree}/admin/suppliers/_form.html.erb
  30. 0 app/views/{ → spree}/admin/suppliers/_hours_form.html.erb
  31. 0 app/views/{ → spree}/admin/suppliers/_image_form.html.erb
  32. 0 app/views/{ → spree}/admin/suppliers/_supplier.html.erb
  33. +3 −0 app/views/spree/admin/suppliers/_supplier_image_form.html.haml
  34. 0 app/views/{ → spree}/admin/suppliers/_supplier_tabs.html.erb
  35. 0 app/views/{ → spree}/admin/suppliers/_suppliers_table.html.erb
  36. 0 app/views/{ → spree}/admin/suppliers/_upload_image.html.erb
  37. 0 app/views/{ → spree}/admin/suppliers/available.js.erb
  38. +1 −1 app/views/{ → spree}/admin/suppliers/edit.html.erb
  39. +7 −7 app/views/{ → spree}/admin/suppliers/index.html.erb
  40. 0 app/views/{ → spree}/admin/suppliers/line_items.html.erb
  41. +1 −1 app/views/{ → spree}/admin/suppliers/new.html.erb
  42. 0 app/views/{ → spree}/admin/suppliers/remove.html.erb
  43. 0 app/views/{ → spree}/admin/suppliers/select.html.erb
  44. +1 −1 app/views/{ → spree}/admin/suppliers/selected.html.erb
  45. 0 app/views/{ → spree}/admin/suppliers/show.html.erb
  46. 0 app/views/{ → spree}/admin/vendor_overview/index.html.erb
  47. 0 app/views/{ → spree}/shared/_supplier_invoices.html.erb
  48. 0 app/views/{ → spree}/suppliers/_supplier.html.erb
  49. +10 −0 app/views/spree/suppliers/_supplier_list.html.haml
  50. +2 −0 app/views/spree/suppliers/index.html.haml
  51. 0 app/views/{ → spree}/suppliers/show.html.erb
  52. 0 app/views/{ → spree}/suppliers/supplier_list.erb
  53. +0 −13 app/views/suppliers/_supplier_list.erb
  54. +0 −13 app/views/suppliers/index.html.erb
  55. +1 −1 config/routes.rb
  56. +1 −1 db/migrate/20120131160039_create_suppliers.rb
  57. +12 −12 db/migrate/20120131160855_add_fields_to_suppliers.rb
  58. +3 −3 db/migrate/20120131161247_create_supplier_invoices.rb
  59. +4 −4 db/migrate/20120131161610_create_invoice_items.rb
  60. +8 −8 db/migrate/20120201160616_create_suppliers_taxons.rb
  61. +1 −1 db/migrate/20120201170705_add_supplier_id_to_products.rb
  62. +27 −61 lib/spree_suppliers.rb
  63. +2 −2 spree_suppliers.gemspec
View
42 README.md
@@ -1,6 +1,6 @@
# Spree Suppliers Extension
-This is an extension to run on top of Spree 0.70.3 rails ecommerce engine.
+This is an extension to run on top of Spree 1.3.2 rails ecommerce engine.
This gem (spree extension) provides support for multiple suppliers in one store, each selling their own products. Products should be assigned to the supplier that they belong to, which allows the customer to select a supplier and view only their products. Suppliers can be associated with Taxons, which allows the customer to search for supplier's products by taxon.
@@ -12,49 +12,41 @@ ______________________________
### you must first have a running rails app:
-- rails new spree_suppliers_test
-- cd spree_suppliers_test
+ gem install rails, "~> 3.2.13"
+ gem install spree, "~> 1.3.2"
+ rails new spree_suppliers_test
+ spree install spree_suppliers_test
+ cd spree_suppliers_test
### Now set up your Gemfile and install:
#### Add to Gemfile:
-- gem 'rails', '3.1.3'
-- gem 'sqlite3'
-- gem 'spree'
-- gem 'spree_suppliers'
+ gem 'spree_suppliers', :git => 'git://github.com/johndavid400/spree_suppliers.git', :branch '1.3.2'
#### then run the following:
-- bundle install
-- rails g spree:site
-- rails g spree_suppliers:install
-- rake db:migrate
-- rake db:seed
-- rake db:admin:create
+ bundle install
+ rails g spree_suppliers:install
+ rake db:migrate
+ rake db:seed
+ rake db:admin:create
- (If you would like some sample seed data for suppliers, copy the seeds.rb file and seeds folder from the gem to your project home db/)
### That's it for installation!
-- rails s
+ rails s
+
- visit localhost:3000
______________________________
-### Alternatively,
-To get the latest updates, you can install the spree_suppliers extension from github instead of rubygems:
-
-
-#### Add to Gemfile:
-
-- gem 'spree_suppliers', :git => 'git://github.com/johndavid400/spree_suppliers.git'
-
#### run the following:
-- bundle install
-- rake spree_suppliers:install
-- rake db:migrate
+ bundle install
+ rake spree_suppliers:install
+ rake db:migrate
______________________________
View
1 Versionfile
@@ -3,6 +3,7 @@
# Examples
#
+"1.0.x" => { :branch => "1.0"}
"0.70.x" => { :branch => "master"}
"0.60.x" => { :branch => "0-60" }
View
6 ...llers/admin/supplier_taxons_controller.rb → ...spree/admin/supplier_taxons_controller.rb
@@ -1,6 +1,6 @@
-class Admin::SupplierTaxonsController < Admin::BaseController
- include Railslove::Plugins::FindByParam::SingletonMethods
- helper "admin/taxons"
+class Spree::Admin::SupplierTaxonsController < Spree::Admin::BaseController
+# include Railslove::Plugins::FindByParam::SingletonMethods
+# helper "spree/admin/taxons"
respond_to :html, :json, :js
View
52 ...controllers/admin/suppliers_controller.rb → ...llers/spree/admin/suppliers_controller.rb
@@ -1,44 +1,46 @@
-class Admin::SuppliersController < Admin::BaseController
- resource_controller
+class Spree::Admin::SuppliersController < Spree::Admin::ResourceController
respond_to :html, :js
+ update.after :expire_cache
+ create.after :expire_cache
def index
if current_user.has_role?("admin")
- @suppliers = Supplier.all
+ @suppliers = Spree::Supplier.all
else
@supplier = current_user.supplier
end
end
def new
- @supplier = Supplier.new()
+ @supplier = Spree::Supplier.new()
@supplier.images.build
@status = true
end
def create
- @supplier = Supplier.new(params[:supplier])
+ @supplier = Spree::Supplier.new(params[:supplier])
if @supplier.save
- redirect_to admin_suppliers_path, :notice => "New supplier created"
+ image = @supplier.images.create(:attachment => params[:image].tempfile)
+ redirect_to spree.admin_suppliers_path, :notice => "New supplier created"
else
render "new"
end
end
def show
- @supplier = Supplier.find(params[:id])
+ @supplier = Spree::Supplier.find(params[:id])
end
def edit
- @supplier = Supplier.find(params[:id])
+ @supplier = Spree::Supplier.find(params[:id])
@supplier.images.build
end
def destroy
- @supplier = Supplier.find(params[:id])
+ @supplier = Spree::Supplier.find(params[:id])
@supplier.destroy
flash[:notice] = "Supplier Successfully deleted."
- respond_with(@product) do |format|
+ respond_with(@supplier) do |format|
format.html { redirect_to collection_url }
format.js do
render :update do |page|
@@ -49,17 +51,17 @@ def destroy
end
def update
- @supplier = Supplier.find(params[:id])
+ @supplier = Spree::Supplier.find(params[:id])
@status = false
if @supplier.update_attributes(params[:supplier])
- redirect_to edit_admin_supplier_path, :notice => "Supplier updated"
+ redirect_to spree.edit_admin_supplier_path, :notice => "Supplier updated"
else
render "edit"
end
end
def feature
- @supplier = Supplier.find(params[:supplier_id])
+ @supplier = Spree::Supplier.find(params[:supplier_id])
if @supplier.featured == true
@supplier.featured = false
else
@@ -67,7 +69,7 @@ def feature
end
@supplier.save
flash[:notice] = "change #{@supplier.title}'s feature status to #{@supplier.featured}"
- redirect_to admin_suppliers_path
+ redirect_to spree.admin_suppliers_path
end
def line_items
@@ -82,7 +84,7 @@ def available
if params[:q].blank?
@available_suppliers = []
else
- @available_suppliers = Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"])
+ @available_suppliers = Spree::Supplier.find(:all, :conditions => ['lower(name) LIKE ?', "%#{params[:q].downcase}%"])
end
@available_suppliers.delete_if { |supplier| @product.supplier == supplier }
respond_to do |format|
@@ -100,28 +102,20 @@ def remove
end
def select
- @supplier = Supplier.find_by_param!(params[:id])
+ @supplier = Spree::Supplier.find_by_param!(params[:id])
@product.supplier = @supplier
@product.save
@supplier = @product.supplier
render :layout => false
end
+ respond_override :update => { :html => { :success => lambda { redirect_to collection_url } } }
+ respond_override :create => { :html => { :success => lambda { redirect_to collection_url } } }
- update.response do |wants|
- wants.html { redirect_to collection_url }
+ private
+ def expire_cache
+ expire_page :controller => '/spree/suppliers', :action => 'show', :path => @object.slug
end
- update.after do
- Rails.cache.delete('suppliers')
- end
-
- create.response do |wants|
- wants.html { redirect_to collection_url }
- end
-
- create.after do
- Rails.cache.delete('suppliers')
- end
end
View
2 ...llers/admin/vendor_overview_controller.rb → ...spree/admin/vendor_overview_controller.rb
@@ -1,4 +1,4 @@
-class Admin::VendorOverviewController < Spree::BaseController
+class Spree::Admin::VendorOverviewController < Spree::BaseController
ssl_required
helper :search
View
0 app/controllers/invoice_items_controller.rb → ...rollers/spree/invoice_items_controller.rb
File renamed without changes.
View
0 ...ntrollers/supplier_invoices_controller.rb → ...ers/spree/supplier_invoices_controller.rb
File renamed without changes.
View
8 app/controllers/suppliers_controller.rb → ...controllers/spree/suppliers_controller.rb
@@ -1,11 +1,9 @@
-class SuppliersController < Spree::BaseController
- helper :products
+class Spree::SuppliersController < Spree::BaseController
+ helper 'spree/products'
respond_to :html
def index
- @search = Supplier.search(params[:search])
- @suppliers = @search.all
- respond_with(@suppliers)
+ @suppliers = Spree::Supplier.all
end
def show
View
2 app/models/invoice_item.rb → app/models/spree/invoice_item.rb
@@ -1,4 +1,4 @@
-class InvoiceItem < ActiveRecord::Base
+class Spree::InvoiceItem < ActiveRecord::Base
belongs_to :supplier_invoice
belongs_to :line_item
end
View
9 app/models/spree/supplier.rb
@@ -0,0 +1,9 @@
+class Spree::Supplier < ActiveRecord::Base
+ attr_accessible :title, :notes, :phone, :fax, :email, :facebook, :twitter, :website, :name, :image, :image_file_name
+ has_many :images, :class_name=> 'Spree::Image', :as => :viewable, :order => :position, :dependent => :destroy
+ accepts_nested_attributes_for :images
+ belongs_to :user
+ has_many :supplier_invoices
+ has_and_belongs_to_many :taxons
+ has_many :products
+end
View
2 app/models/supplier_invoice.rb → app/models/spree/supplier_invoice.rb
@@ -1,4 +1,4 @@
-class SupplierInvoice < ActiveRecord::Base
+class Spree::SupplierInvoice < ActiveRecord::Base
belongs_to :supplier
has_many :invoice_items
end
View
8 app/models/supplier.rb
@@ -1,8 +0,0 @@
-class Supplier < ActiveRecord::Base
- has_many :images, :as => :viewable, :order => :position, :dependent => :destroy
- accepts_nested_attributes_for :images
- belongs_to :user
- has_many :supplier_invoices
- has_and_belongs_to_many :taxons
- has_many :products
-end
View
2 app/overrides/admin.rb
@@ -1,4 +1,4 @@
-Deface::Override.new(:virtual_path => "layouts/admin",
+Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "suppliers_tabs",
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= tab(:suppliers) %>",
View
114 app/views/admin/products/_form.html.erb
@@ -1,114 +0,0 @@
-<div class="clearfix">
- <div class="left" data-hook="admin_product_form_left">
- <%= f.field_container :name do %>
- <%= f.label :name, t(:name) %> <span class="required">*</span><br />
- <%= f.text_field :name, :class => 'fullwidth title' %>
- <%= f.error_message_on :name %>
- <% end %>
-
- <%= f.field_container :permalink do %>
- <%= f.label :permalink, t(:permalink) %> <span class="required">*</span><br />
- <%= f.text_field :permalink, :class => 'fullwidth title' %>
- <%= f.error_message_on :permalink %>
- <% end %>
-
- <%= f.field_container :description do %>
- <%= f.label :description, t(:description)%><br />
- <%= f.text_area :description, {:cols => 60, :rows => 4, :class => 'fullwidth'} %>
- <%= f.error_message_on :description %>
- <% end %>
- </div>
- <div class="right" data-hook="admin_product_form_right">
- <%= f.field_container :price do %>
- <%= f.label :price, t(:master_price) %> <span class="required">*</span><br />
- <%= f.text_field :price, :value => number_with_precision(@product.price, :precision => 2) %>
- <%= f.error_message_on :price %>
- <% end %>
-
- <%if Spree::Config[:show_price_inc_vat] %>
- <%= label_tag :price_includes_vat , I18n.t(:price_with_vat_included, :price => I18n.t(:price)) %><br />
- <%= text_field_tag :price_including_vat, product_price(@product, :show_vat_text => false), :size => 30 %>
- <%= javascript_tag do -%>
- var effective_tax_rate = <%= @product.effective_tax_rate %>;
- <% end -%>
- <% end %>
-
- <%= f.field_container :cost_price do %>
- <%= f.label :cost_price, t(:cost_price) %><br />
- <%= f.text_field :cost_price, :value => number_with_precision(@product.cost_price, :precision => 2) %>
- <%= f.error_message_on :cost_price %>
- <% end %>
-
- <p>
- <%= f.label :available_on, t(:available_on) %><br />
- <%= f.error_message_on :available_on %>
- <%= f.text_field :available_on, :class => 'datepicker' %>
- </p>
-
- <p>
- <%= render :partial => 'admin/products/suppliers_form', :locals => {:f => f} %>
- </p>
-
-
- <p>
- <%= f.label :sku, t(:sku) %><br />
- <%= f.text_field :sku, :size => 16 %>
- </p>
- <% unless @product.has_variants? %>
- <% if Spree::Config[:track_inventory_levels] %>
- <p>
- <%= f.label :on_hand, t(:on_hand) %><br />
- <%= f.text_field :on_hand, :size => 4 %>
- </p>
- <% end %>
- <ul id="shipping-specs">
- <li>
- <%= f.label :weight, t(:weight) %>
- <%= f.text_field :weight, :size => 4 %>
- </li>
- <li>
- <%= f.label :height, t(:height) %>
- <%= f.text_field :height, :size => 4 %>
- </li>
- <li>
- <%= f.label :width, t(:width) %>
- <%= f.text_field :width, :size => 4 %>
- </li>
- <li>
- <%= f.label :depth, t(:depth) %>
- <%= f.text_field :depth, :size => 4 %>
- </li>
- </ul>
- <% end %>
- <p>
- <%= f.label :shipping_category_id, t(:shipping_categories) %><br />
- <%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, {:include_blank => true}, {'style' => 'width:200px'}) %>
- <%= f.error_message_on :shipping_category %>
- </p>
-
- <p>
- <%= f.label :tax_category_id, t(:tax_category) %><br />
- <%= f.collection_select(:tax_category_id, @tax_categories, :id, :name, {:include_blank => true}, {'style' => 'width:200px'}) %>
- <%= f.error_message_on :tax_category %>
- </p>
- </div>
-</div>
-
-<h2><%= t(:metadata) %></h2>
-<div data-hook="admin_product_form_meta">
- <p>
- <%= f.label :meta_keywords, t(:meta_keywords) %><br />
- <%= f.text_field :meta_keywords, :class => 'fullwidth' %>
- </p>
- <p>
- <%= f.label :meta_description, t(:meta_description) %><br />
- <%= f.text_field :meta_description, :class => 'fullwidth' %>
- </p>
-</div>
-
-
-<div data-hook="admin_product_form_additional_fields">
- <% Variant.additional_fields.select{|af| af[:only].nil? || af[:only].include?(:product) }.each do |field| %>
- <%= render :partial => 'admin/shared/additional_field', :locals => {:field => field, :f => f} %>
- <% end %>
-</div>
View
0 app/views/admin/orders/show.html.erb → app/views/spree/admin/orders/show.html.erb
File renamed without changes.
View
0 app/views/admin/orders/user.html.erb → app/views/spree/admin/orders/user.html.erb
File renamed without changes.
View
0 ...s/admin/products/_suppliers_form.html.erb → ...e/admin/products/_suppliers_form.html.erb
File renamed without changes.
View
0 .../admin/shared/_order_tabs_decide.html.erb → .../admin/shared/_order_tabs_decide.html.erb
File renamed without changes.
View
0 .../admin/shared/_vendor_order_tabs.html.erb → .../admin/shared/_vendor_order_tabs.html.erb
File renamed without changes.
View
0 ...iews/admin/supplier_taxons/_form.html.erb → ...pree/admin/supplier_taxons/_form.html.erb
File renamed without changes.
View
0 ...min/supplier_taxons/_taxon_table.html.erb → ...min/supplier_taxons/_taxon_table.html.erb
File renamed without changes.
View
0 ...ws/admin/supplier_taxons/available.js.erb → ...ee/admin/supplier_taxons/available.js.erb
File renamed without changes.
View
0 ...views/admin/supplier_taxons/edit.html.erb → ...spree/admin/supplier_taxons/edit.html.erb
File renamed without changes.
View
0 ...ews/admin/supplier_taxons/remove.html.erb → ...ree/admin/supplier_taxons/remove.html.erb
File renamed without changes.
View
0 ...views/admin/supplier_taxons/select.js.erb → ...spree/admin/supplier_taxons/select.js.erb
File renamed without changes.
View
0 ...s/admin/supplier_taxons/selected.html.erb → ...e/admin/supplier_taxons/selected.html.erb
File renamed without changes.
View
0 ...views/admin/suppliers/_edit_form.html.erb → ...spree/admin/suppliers/_edit_form.html.erb
File renamed without changes.
View
0 ...admin/suppliers/_edit_hours_form.html.erb → ...admin/suppliers/_edit_hours_form.html.erb
File renamed without changes.
View
14 app/views/admin/suppliers/_form.html.erb → ...iews/spree/admin/suppliers/_form.html.erb
@@ -45,16 +45,4 @@
</tr>
</table>
- <h3>Supplier Images</h3>
- <%= f.fields_for :images do |image| %>
- <% if !image.object.attachment_file_name.nil? %>
- <span class="supplier_image">
- <%= image_tag(image.object.attachment.url) %>
- </span>
- <% else %>
- <p />
- <h4><%= "Upload New Image" %></h4>
- <%= image.file_field :attachment if image.object.attachment_file_name.nil? %>
- <% end %>
- <% end %>
-
+<%= render :partial => 'supplier_image_form' %>
View
0 ...iews/admin/suppliers/_hours_form.html.erb → ...pree/admin/suppliers/_hours_form.html.erb
File renamed without changes.
View
0 ...iews/admin/suppliers/_image_form.html.erb → ...pree/admin/suppliers/_image_form.html.erb
File renamed without changes.
View
0 app/views/admin/suppliers/_supplier.html.erb → .../spree/admin/suppliers/_supplier.html.erb
File renamed without changes.
View
3 app/views/spree/admin/suppliers/_supplier_image_form.html.haml
@@ -0,0 +1,3 @@
+%h3 Supplier Images
+%h4= "Upload Image"
+= file_field_tag "image"
View
0 ...s/admin/suppliers/_supplier_tabs.html.erb → ...e/admin/suppliers/_supplier_tabs.html.erb
File renamed without changes.
View
0 ...admin/suppliers/_suppliers_table.html.erb → ...admin/suppliers/_suppliers_table.html.erb
File renamed without changes.
View
0 ...ws/admin/suppliers/_upload_image.html.erb → ...ee/admin/suppliers/_upload_image.html.erb
File renamed without changes.
View
0 app/views/admin/suppliers/available.js.erb → ...ws/spree/admin/suppliers/available.js.erb
File renamed without changes.
View
2 app/views/admin/suppliers/edit.html.erb → ...views/spree/admin/suppliers/edit.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/suppliers/supplier_tabs', :locals => {:current => "Supplier Details"} %>
+<%= render :partial => 'supplier_tabs', :locals => {:current => "Supplier Details"} %>
<h1>Edit Supplier</h1>
View
14 app/views/admin/suppliers/index.html.erb → ...iews/spree/admin/suppliers/index.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<h1>
<%= t("suppliers") %>
</h1>
@@ -6,7 +6,7 @@
<div class='toolbar'>
<ul class='actions'>
<li id="new_product_link">
- <%= button_link_to "New Supplier", new_admin_supplier_path %>
+ <%= button_link_to "New Supplier", spree.new_admin_supplier_path %>
</li>
</ul>
<br class='clear' />
@@ -32,7 +32,7 @@
<% @suppliers.each do |supplier| %>
<tr class="<%= cycle('even', 'odd') %>">
<td>
- <%= link_to supplier.title, edit_admin_supplier_path(supplier) %>
+ <%= link_to supplier.title, spree.edit_admin_supplier_path(supplier) %>
</td>
<td>
<%= truncate(supplier.notes, :length => 50) %>
@@ -44,9 +44,9 @@
</td>
<td>
<% if supplier.featured %>
- <%= link_to "Yes", admin_supplier_feature_path(supplier) %>
+ <%= link_to "Yes", spree.admin_supplier_feature_path(supplier) %>
<% else %>
- <%= link_to "No", admin_supplier_feature_path(supplier) %>
+ <%= link_to "No", spree.admin_supplier_feature_path(supplier) %>
<% end %>
</td>
</tr><% end %>
@@ -73,7 +73,7 @@
<tbody>
<tr>
<td>
- <%= link_to @supplier.title, edit_admin_supplier_path(@supplier) %>
+ <%= link_to @supplier.title, spree.edit_admin_supplier_path(@supplier) %>
</td>
<td>
<%= truncate(@supplier.notes, :length => 50) %>
@@ -93,5 +93,5 @@
</table>
<% end %>
<% if current_user.has_role?("admin") %>
- <%= link_to t("new_supplier"), new_object_url %>
+ <%= link_to t("new_supplier"), spree.new_admin_supplier_url %>
<% end %>
View
0 ...views/admin/suppliers/line_items.html.erb → ...spree/admin/suppliers/line_items.html.erb
File renamed without changes.
View
2 app/views/admin/suppliers/new.html.erb → app/views/spree/admin/suppliers/new.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/shared/configuration_menu' %>
+<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<h1><%= t("new_supplier") %></h1>
View
0 app/views/admin/suppliers/remove.html.erb → ...ews/spree/admin/suppliers/remove.html.erb
File renamed without changes.
View
0 app/views/admin/suppliers/select.html.erb → ...ews/spree/admin/suppliers/select.html.erb
File renamed without changes.
View
2 app/views/admin/suppliers/selected.html.erb → ...s/spree/admin/suppliers/selected.html.erb
@@ -1,4 +1,4 @@
-<%= render :partial => 'admin/suppliers/supplier_tabs', :locals => {:current => "Taxons"} %>
+<%= render :partial => 'spree/admin/suppliers/supplier_tabs', :locals => {:current => "Taxons"} %>
<div id="selected-taxons">
<%= render :partial => "taxon_table", :locals => {:taxons => @taxons} %>
View
0 app/views/admin/suppliers/show.html.erb → ...views/spree/admin/suppliers/show.html.erb
File renamed without changes.
View
0 ...iews/admin/vendor_overview/index.html.erb → ...pree/admin/vendor_overview/index.html.erb
File renamed without changes.
View
0 app/views/shared/_supplier_invoices.html.erb → .../spree/shared/_supplier_invoices.html.erb
File renamed without changes.
View
0 app/views/suppliers/_supplier.html.erb → app/views/spree/suppliers/_supplier.html.erb
File renamed without changes.
View
10 app/views/spree/suppliers/_supplier_list.html.haml
@@ -0,0 +1,10 @@
+%li.suppliers
+ .vendor-image
+ = link_to supplier.images.first, supplier_path(supplier)
+ .article-content
+ - if supplier.title
+ = link_to supplier.title, supplier_path(supplier)
+ - else
+ = link_to supplier.name, supplier_path(supplier)
+
+
View
2 app/views/spree/suppliers/index.html.haml
@@ -0,0 +1,2 @@
+.search-list
+ = render :partial => "supplier_list", :collection => @suppliers, :as => :supplier
View
0 app/views/suppliers/show.html.erb → app/views/spree/suppliers/show.html.erb
File renamed without changes.
View
0 app/views/suppliers/supplier_list.erb → app/views/spree/suppliers/supplier_list.erb
File renamed without changes.
View
13 app/views/suppliers/_supplier_list.erb
@@ -1,13 +0,0 @@
-<li class="suppliers">
-<div class="vendor-image">
- <%= link_to supplier.images.first, supplier_path(supplier) %>
-</div>
-<div class="article-content">
- <% if supplier.title %>
- <h4><%= link_to supplier.title, supplier_path(supplier) %> </h4>
- <% else %>
- <h4><%= link_to supplier.name, supplier_path(supplier) %> </h4>
- <% end %>
- </p>
-</div>
-</li>
View
13 app/views/suppliers/index.html.erb
@@ -1,13 +0,0 @@
-<div class="search-sidebar">
- <%= form_for @search do |f| %>
- <p>
- <%= f.label :search_vendors %>
- <%= f.text_field :name_or_title_contains %>
- </p>
- <p class = "button"><%= f.submit "Search" %></p>
- <% end %>
-</div>
-<div class="search-list">
- <%= render :partial => "suppliers/supplier_list", :collection => @suppliers, :as => :supplier %>
-</div>
-<div class="clear"></div>
View
2 config/routes.rb
@@ -1,4 +1,4 @@
-Rails.application.routes.draw do
+Spree::Core::Engine.routes.append do
# Add your extension routes here
resources :suppliers
resources :supplier_invoices
View
2 db/migrate/20120131160039_create_suppliers.rb
@@ -1,6 +1,6 @@
class CreateSuppliers < ActiveRecord::Migration
def change
- create_table :suppliers do |t|
+ create_table :spree_suppliers do |t|
t.timestamps
end
View
24 db/migrate/20120131160855_add_fields_to_suppliers.rb
@@ -1,16 +1,16 @@
class AddFieldsToSuppliers < ActiveRecord::Migration
def change
- add_column :suppliers, :name, :string
- add_column :suppliers, :title, :string
- add_column :suppliers, :phone, :string
- add_column :suppliers, :fax, :string
- add_column :suppliers, :email, :string
- add_column :suppliers, :website, :string
- add_column :suppliers, :notes, :text
- add_column :suppliers, :featured, :boolean
- add_column :suppliers, :twitter, :string
- add_column :suppliers, :facebook, :string
- add_column :suppliers, :description, :text
- add_column :suppliers, :user_id, :integer
+ add_column :spree_suppliers, :name, :string
+ add_column :spree_suppliers, :title, :string
+ add_column :spree_suppliers, :phone, :string
+ add_column :spree_suppliers, :fax, :string
+ add_column :spree_suppliers, :email, :string
+ add_column :spree_suppliers, :website, :string
+ add_column :spree_suppliers, :notes, :text
+ add_column :spree_suppliers, :featured, :boolean
+ add_column :spree_suppliers, :twitter, :string
+ add_column :spree_suppliers, :facebook, :string
+ add_column :spree_suppliers, :description, :text
+ add_column :spree_suppliers, :spree_user_id, :integer
end
end
View
6 db/migrate/20120131161247_create_supplier_invoices.rb
@@ -1,10 +1,10 @@
class CreateSupplierInvoices < ActiveRecord::Migration
def change
- create_table :supplier_invoices do |t|
- t.integer :order_id
+ create_table :spree_supplier_invoices do |t|
+ t.integer :spree_order_id
t.integer :item_count
t.decimal :invoice_total
- t.integer :supplier_id
+ t.integer :spree_supplier_id
t.timestamps
end
View
8 db/migrate/20120131161610_create_invoice_items.rb
@@ -1,10 +1,10 @@
class CreateInvoiceItems < ActiveRecord::Migration
def change
- create_table :invoice_items do |t|
- t.integer :product_id
+ create_table :spree_invoice_items do |t|
+ t.integer :spree_product_id
t.integer :quantity
- t.integer :supplier_invoice_id
- t.integer :line_item_id
+ t.integer :spree_supplier_invoice_id
+ t.integer :spree_line_item_id
t.timestamps
end
View
16 db/migrate/20120201160616_create_suppliers_taxons.rb
@@ -1,16 +1,16 @@
class CreateSuppliersTaxons < ActiveRecord::Migration
def self.up
- create_table :suppliers_taxons, :id => false do |t|
- t.integer :supplier_id
- t.integer :taxon_id
+ create_table :spree_suppliers_taxons, :id => false do |t|
+ t.integer :spree_supplier_id
+ t.integer :spree_taxon_id
end
- add_index :suppliers_taxons, :supplier_id
- add_index :suppliers_taxons, :taxon_id
+ add_index :spree_suppliers_taxons, :spree_supplier_id
+ add_index :spree_suppliers_taxons, :spree_taxon_id
end
def self.down
- remove_index :suppliers_taxons, :column => :taxon_id
- remove_index :suppliers_taxons, :column => :supplier_id
- drop_table :suppliers_taxons
+ remove_index :spree_suppliers_taxons, :column => :spree_taxon_id
+ remove_index :spree_suppliers_taxons, :column => :spree_supplier_id
+ drop_table :spree_suppliers_taxons
end
end
View
2 db/migrate/20120201170705_add_supplier_id_to_products.rb
@@ -1,5 +1,5 @@
class AddSupplierIdToProducts < ActiveRecord::Migration
def change
- add_column :products, :supplier_id, :integer
+ add_column :spree_products, :spree_supplier_id, :integer
end
end
View
88 lib/spree_suppliers.rb
@@ -6,20 +6,26 @@ class Engine < Rails::Engine
config.autoload_paths += %W(#{config.root}/lib)
def self.activate
- LineItem.class_eval do
+ Spree::User.class_eval do
+ def has_role?(role)
+ self.spree_roles.include?(Spree::Role.find_by_name(role))
+ end
+ end
+
+ Spree::LineItem.class_eval do
has_many :invoice_items
end
- Image.class_eval do
+ Spree::Image.class_eval do
belongs_to :supplier
end
- Admin::OrdersController.class_eval do
+ Spree::Admin::OrdersController.class_eval do
def show
load_order
# optional fee that admin can charge to sell suppliers products for them
@fee = 0.10
- if current_user.has_role?("vendor")
+ if current_user.has_role?(Spree::Role.find_by_name("vendor"))
@invoices = @order.supplier_invoices
@invoices.select! {|s| s.supplier_id == current_user.supplier.id}
else
@@ -28,37 +34,9 @@ def show
respond_with(@order)
end
- def index
- params[:search] ||= {}
- params[:search][:completed_at_is_not_null] ||= '1' if Spree::Config[:show_only_complete_orders_by_default]
- @show_only_completed = params[:search][:completed_at_is_not_null].present?
- params[:search][:meta_sort] ||= @show_only_completed ? 'completed_at.desc' : 'created_at.desc'
-
- @search = Order.metasearch(params[:search])
-
- if !params[:search][:created_at_greater_than].blank?
- params[:search][:created_at_greater_than] = Time.zone.parse(params[:search][:created_at_greater_than]).beginning_of_day rescue ""
- end
-
- if !params[:search][:created_at_less_than].blank?
- params[:search][:created_at_less_than] = Time.zone.parse(params[:search][:created_at_less_than]).end_of_day rescue ""
- end
-
- if @show_only_completed
- params[:search][:completed_at_greater_than] = params[:search].delete(:created_at_greater_than)
- params[:search][:completed_at_less_than] = params[:search].delete(:created_at_less_than)
- end
-
- @orders = Order.metasearch(params[:search]).includes([:user, :shipments, :payments]).page(params[:page]).per(Spree::Config[:orders_per_page])
-
- if current_user.has_role?("vendor")
- @orders.select! {|o| o.supplier_invoices.select {|s| s.supplier_id == current_user.supplier.id}.size > 0}
- end
- respond_with(@orders)
- end
end
- Order.class_eval do
+ Spree::Order.class_eval do
has_many :supplier_invoices
def generate_invoices(order)
@order = order
@@ -69,7 +47,7 @@ def generate_invoices(order)
for i in 0..@invoices - 1
@supplier_products = @order_products.select{|x| x.product.supplier_id == @suppliers[i]}
@product_count = @supplier_products.count
- invoice = SupplierInvoice.create(:order_id => @order.id, :supplier_id => @suppliers[i], :item_count => @product_count)
+ invoice = Spree::SupplierInvoice.create(:order_id => @order.id, :supplier_id => @suppliers[i], :item_count => @product_count)
@supplier_products.each do |item|
invoice.invoice_items.create(:product_id => item.product.id, :quantity => item.quantity, :line_item_id => item.id)
@@ -87,7 +65,7 @@ def generate_invoices(order)
def finalize!
update_attribute(:completed_at, Time.now)
- InventoryUnit.assign_opening_inventory(self)
+ Spree::InventoryUnit.assign_opening_inventory(self)
# lock any optional adjustments (coupon promotions, etc.)
adjustments.optional.each { |adjustment| adjustment.update_attribute('locked', true) }
# generate the invoices for each supplier
@@ -104,84 +82,72 @@ def finalize!
end
- Admin::ProductsController.class_eval do
+ Spree::Admin::ProductsController.class_eval do
before_filter :load
before_filter :load_index, :only => [:index]
before_filter :edit_before, :only => [:edit]
create.before :create_before
- create.fails :reset
- update.before :update_taxons
def load
- @suppliers = Supplier.find(:all, :order => "name")
- @options = Taxon.all
+ @suppliers = Spree::Supplier.find(:all, :order => "name")
+ @options = Spree::Taxon.all
end
def load_index
- if current_user.roles.member?(Role.find_by_name("vendor"))
+ if current_user.has_role?(Spree::Role.find_by_name("vendor"))
@collection.select! {|c| c.supplier_id == current_user.supplier.id}
end
end
#indicate that we want to create a new product
def new
- @object = Product.new()
+ @object = Spree::Product.new()
@status = true
- @suppliers = Supplier.all
+ @suppliers = Spree::Supplier.all
end
def edit_before
- @suppliers = Supplier.all
+ @suppliers = Spree::Supplier.all
@status = false
end
- def taxon_push object
- object.taxons = []
- Taxon.all.map {|m| object.taxons.push(Taxon.find_by_id(params[m.name])) if params.member?(m.name)}
- return object
- end
-
- def reset
- @status = true
- end
-
def update_taxons
@object = taxon_push(@object)
end
def create_before
- if current_user.has_role?("vendor")
+ if current_user.has_role?(Spree::Role.find_by_name("vendor"))
@object = current_user.supplier.products.build(params[:product])
else
- @object = Product.new(params[:product])
+ @object = Spree::Product.new(params[:product])
end
@object = taxon_push(@object)
end
def publish
- p = Product.find_by_name(params[:id])
+ p = Spree::Product.find_by_name(params[:id])
p.available_on = Date.today
p.save
redirect_to edit_admin_product_path(p)
end
def unpublish
- p = Product.find_by_name(params[:id])
+ p = Spree::Product.find_by_name(params[:id])
p.available_on = nil
p.save
redirect_to edit_admin_product_path(p)
end
end
- Product.class_eval do
+ Spree::Product.class_eval do
belongs_to :supplier
end
- Taxon.class_eval do
+ Spree::Taxon.class_eval do
has_and_belongs_to_many :suppliers
end
- User.class_eval do
+ Spree::User.class_eval do
has_one :supplier
end
View
4 spree_suppliers.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_suppliers'
- s.version = '1.0.3'
+ s.version = '1.0.5'
s.summary = 'This gem adds multiple suppliers to spree, with the ability to associate products with suppliers. Suppliers can be managed from the Admin interface.'
s.description = 'This gem (spree extension) provides support for multiple suppliers in one store. Products should be assigned to the supplier that they belong to, which allows you to select a supplier and view only their products. Suppliers can be associated with Taxons that allow the customer to search for suppliers by taxon. Orders are also broken up into supplier invoices (one for each different supplier in the order), which list only the products that were purchased from that supplier. A mailer is in place to send each supplier their unique invoice descrbing what products they have sold and to who. The spree order mailer has also been modified to show all of the supplier invoices to the customer, along with the standard spree order number and info. The checkout process is combined so the customer only makes one transaction - the transaction can then be divided up amongst the suppliers involved in the transaction, according to the supplier_invoices. There is also an option for the site administrator to charge a percentage fee on each transaction to suppliers (this is currently set to 0%, but can be changed).'
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'
- s.add_dependency 'spree_core', '>= 0.70.3'
+ s.add_dependency 'spree_core', '>= 1.0.0'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'cucumber-rails'
s.add_development_dependency 'capybara'
Something went wrong with that request. Please try again.