spree_suppliers 0.1.0 → 0.60.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +46 -0
- data/Rakefile +137 -0
- data/app/controllers/admin/pickup_locations_controller.rb +52 -0
- data/app/controllers/admin/pickups_controller.rb +84 -0
- data/app/controllers/admin/shipping_options_controller.rb +32 -0
- data/app/controllers/admin/supplier_taxons_controller.rb +65 -0
- data/app/controllers/admin/suppliers_controller.rb +203 -0
- data/app/controllers/admin/vendor_overview_controller.rb +18 -0
- data/app/controllers/dash/base_controller.rb +10 -0
- data/app/controllers/dash/overview_controller.rb +6 -0
- data/app/controllers/dash/pickup_locations_controller.rb +27 -0
- data/app/controllers/dash/pickups_controller.rb +40 -0
- data/app/controllers/dash/products_controller.rb +15 -0
- data/app/controllers/messages_controller.rb +17 -0
- data/app/controllers/suppliers_controller.rb +19 -0
- data/app/controllers/user_sessions_decorator.rb +39 -0
- data/app/helpers/admin/suppliers_helper.rb +21 -0
- data/app/helpers/cities_helper.rb +2 -0
- data/app/helpers/dragonfly_helper.rb +16 -0
- data/app/helpers/messages_helper.rb +2 -0
- data/app/helpers/suppliers_helper.rb +16 -0
- data/app/mailers/supplier_mailer.rb +11 -0
- data/app/models/ability_decorator.rb +19 -0
- data/app/models/delivery.rb +6 -0
- data/app/models/hour.rb +4 -0
- data/app/models/item.rb +5 -0
- data/app/models/message.rb +3 -0
- data/app/models/pickup.rb +10 -0
- data/app/models/pickup_date.rb +3 -0
- data/app/models/pickup_location.rb +7 -0
- data/app/models/supplier.rb +33 -0
- data/app/models/supplier_invoice.rb +5 -0
- data/app/views/admin/orders/index.html.erb +107 -0
- data/app/views/admin/orders/show.html.erb +35 -0
- data/app/views/admin/orders/user.html.erb +19 -0
- data/app/views/admin/pickup_locations/_pickup_location.html.erb +10 -0
- data/app/views/admin/pickup_locations/edit.html.erb +44 -0
- data/app/views/admin/pickup_locations/new.html.erb +48 -0
- data/app/views/admin/pickup_locations/show.html.erb +1 -0
- data/app/views/admin/pickups/_pickup.erb +0 -0
- data/app/views/admin/pickups/index.html.erb +44 -0
- data/app/views/admin/pickups/new.html.erb +33 -0
- data/app/views/admin/pickups/show.html.erb +42 -0
- data/app/views/admin/products/_suppliers_form.html.erb +5 -0
- data/app/views/admin/shared/_order_tabs_decide.html.erb +5 -0
- data/app/views/admin/shared/_vendor_order_tabs.html.erb +39 -0
- data/app/views/admin/shipping_options/edit.html.erb +38 -0
- data/app/views/admin/supplier_taxons/_form.html.erb +23 -0
- data/app/views/admin/supplier_taxons/_taxon_table.html.erb +23 -0
- data/app/views/admin/supplier_taxons/available.js.erb +33 -0
- data/app/views/admin/supplier_taxons/edit.html.erb +11 -0
- data/app/views/admin/supplier_taxons/remove.html.erb +1 -0
- data/app/views/admin/supplier_taxons/select.js.erb +2 -0
- data/app/views/admin/supplier_taxons/selected.html.erb +51 -0
- data/app/views/admin/suppliers/_edit_form.html.erb +75 -0
- data/app/views/admin/suppliers/_edit_hours_form.html.erb +18 -0
- data/app/views/admin/suppliers/_form.html.erb +72 -0
- data/app/views/admin/suppliers/_hours_form.html.erb +11 -0
- data/app/views/admin/suppliers/_image_form.html.erb +40 -0
- data/app/views/admin/suppliers/_supplier.html.erb +37 -0
- data/app/views/admin/suppliers/_supplier_tabs.html.erb +18 -0
- data/app/views/admin/suppliers/_suppliers_table.html.erb +25 -0
- data/app/views/admin/suppliers/_upload_image.html.erb +14 -0
- data/app/views/admin/suppliers/available.js.erb +34 -0
- data/app/views/admin/suppliers/edit.html.erb +20 -0
- data/app/views/admin/suppliers/index.html.erb +102 -0
- data/app/views/admin/suppliers/line_items.html.erb +20 -0
- data/app/views/admin/suppliers/new.html.erb +22 -0
- data/app/views/admin/suppliers/remove.html.erb +1 -0
- data/app/views/admin/suppliers/select.html.erb +1 -0
- data/app/views/admin/suppliers/selected.html.erb +40 -0
- data/app/views/admin/suppliers/show.html.erb +2 -0
- data/app/views/admin/users/_form.html.erb +40 -0
- data/app/views/admin/vendor_overview/index.html.erb +1 -0
- data/app/views/checkout/_delivery.html.erb +5 -0
- data/app/views/dash/overview/index.html.erb +58 -0
- data/app/views/dash/pickup_locations/_pickup_location.html.erb +3 -0
- data/app/views/dash/pickup_locations/new.html.erb +47 -0
- data/app/views/dash/pickups/_pickup.erb +3 -0
- data/app/views/dash/pickups/new.html.erb +24 -0
- data/app/views/dash/products/new.html.erb +38 -0
- data/app/views/layouts/admin.html.erb +81 -0
- data/app/views/messages/_message_form.html.erb +17 -0
- data/app/views/messages/create.html.erb +2 -0
- data/app/views/messages/destroy.html.erb +2 -0
- data/app/views/messages/new.html.erb +2 -0
- data/app/views/shared/_deliveries.html.erb +113 -0
- data/app/views/shared/_hours.html.erb +21 -0
- data/app/views/shared/_products_vendor.html.erb +49 -0
- data/app/views/shared/_supplier_invoices.html.erb +67 -0
- data/app/views/supplier_mailer/invoice_email.html.erb +72 -0
- data/app/views/suppliers/_supplier.html.erb +7 -0
- data/app/views/suppliers/_supplier_list.erb +20 -0
- data/app/views/suppliers/index.html.erb +17 -0
- data/app/views/suppliers/show.html.erb +106 -0
- data/app/views/suppliers/supplier_list.erb +14 -0
- data/config/initializers/dragonfly.rb +8 -0
- data/config/initializers/supplier_invoice_mailer.rb +10 -0
- data/config/locales/en-US.yml +13 -0
- data/config/routes.rb +48 -0
- data/db/migrate/20091209201716_supplier_setup.rb +36 -0
- data/db/migrate/20110922213437_create_messages.rb +18 -0
- data/db/migrate/20110928203155_create_hours.rb +21 -0
- data/db/migrate/20111006185052_create_pickups.rb +17 -0
- data/db/migrate/20111010191125_add_location_to_addresses.rb +9 -0
- data/db/migrate/20111010214313_create_pickup_dates.rb +14 -0
- data/db/migrate/20111011180211_add_supplier_id_to_user.rb +9 -0
- data/db/migrate/20111012211422_create_pickup_locations.rb +21 -0
- data/db/migrate/20111013155257_create_supplier_invoices.rb +16 -0
- data/db/migrate/20111013161225_create_items.rb +18 -0
- data/db/migrate/20111018133543_add_attributes_to_products.rb +17 -0
- data/db/migrate/20111028190454_add_attributes_to_assets.rb +11 -0
- data/db/migrate/20111029230805_create_suppliers_taxons.rb +16 -0
- data/db/migrate/20111101165933_create_deliveries.rb +17 -0
- data/db/migrate/20111108213108_create_shipping_methods_suppliers.rb +16 -0
- data/db/seeds.rb +14 -0
- data/lib/spree_suppliers.rb +411 -0
- data/lib/spree_suppliers_hooks.rb +40 -0
- data/lib/tasks/spree_suppliers.rake +27 -0
- data/public/javascripts/jquery-ui.js +312 -0
- data/public/javascripts/jquery-ui.multidatespicker.js +398 -0
- data/public/javascripts/jquery.ui.datepicker.js +1791 -0
- data/public/stylesheets/suppliers.css +676 -0
- data/spec/controllers/cities_controller_spec.rb +157 -0
- data/spec/controllers/shipping_options_controller_spec.rb +12 -0
- data/spec/helpers/cities_helper_spec.rb +15 -0
- data/spec/models/city_spec.rb +5 -0
- data/spec/models/comment_spec.rb +64 -0
- data/spec/models/item_spec.rb +5 -0
- data/spec/models/message_spec.rb +5 -0
- data/spec/models/pickup_date_spec.rb +5 -0
- data/spec/models/pickup_location_spec.rb +5 -0
- data/spec/models/pickup_spec.rb +5 -0
- data/spec/models/rating_spec.rb +24 -0
- data/spec/models/supplier_invoice_spec.rb +5 -0
- data/spec/models/supplier_spec.rb +11 -0
- data/spec/requests/cities_spec.rb +11 -0
- data/spec/routing/cities_routing_spec.rb +35 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/views/cities/edit.html.erb_spec.rb +22 -0
- data/spec/views/cities/index.html.erb_spec.rb +28 -0
- data/spec/views/cities/new.html.erb_spec.rb +22 -0
- data/spec/views/cities/show.html.erb_spec.rb +21 -0
- data/spec/views/shipping_options/edit.html.erb_spec.rb +5 -0
- data/spree_suppliers.gemspec +24 -0
- metadata +181 -14
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreatePickups < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :pickups do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :address_id
|
6
|
+
t.integer :supplier_id
|
7
|
+
t.integer :pickup_location_id
|
8
|
+
t.integer :delivery_id
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :pickups
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreatePickupLocations < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :pickup_locations do |t|
|
4
|
+
t.string :location_name
|
5
|
+
t.string :address1
|
6
|
+
t.string :address2
|
7
|
+
t.string :city
|
8
|
+
t.integer :state_id
|
9
|
+
t.string :zipcode
|
10
|
+
t.integer :country_id
|
11
|
+
t.integer :supplier_id
|
12
|
+
t.boolean :featured
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :pickup_locations
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateSupplierInvoices < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :supplier_invoices do |t|
|
4
|
+
t.integer :order_id
|
5
|
+
t.integer :item_count
|
6
|
+
t.integer :supplier_id
|
7
|
+
t.decimal :invoice_total, :precision => 8, :scale => 2, :default => 0.0, :null => false
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :supplier_invoices
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateItems < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :items do |t|
|
4
|
+
t.integer :product_id
|
5
|
+
t.string :delivery_type
|
6
|
+
t.integer :pickup_id
|
7
|
+
t.integer :quantity
|
8
|
+
t.integer :supplier_invoice_id
|
9
|
+
t.integer :line_item_id
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :items
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddAttributesToProducts < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :products, :number_of_units, :decimal
|
4
|
+
add_column :products, :unit, :string
|
5
|
+
add_column :products, :cost_per_unit, :decimal
|
6
|
+
add_column :products, :shipping_method_id, :integer
|
7
|
+
add_column :products, :shipping, :boolean
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
remove_column :products, :number_of_units
|
12
|
+
remove_column :products, :unit
|
13
|
+
remove_column :products, :cost_per_unit
|
14
|
+
remove_column :products, :shipping_method_id
|
15
|
+
remove_column :products, :shipping
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateSuppliersTaxons < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :suppliers_taxons, :id => false do |t|
|
4
|
+
t.integer :supplier_id
|
5
|
+
t.integer :taxon_id
|
6
|
+
end
|
7
|
+
add_index :suppliers_taxons, :supplier_id
|
8
|
+
add_index :suppliers_taxons, :taxon_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
remove_index :suppliers_taxons, :column => :taxon_id
|
13
|
+
remove_index :suppliers_taxons, :column => :supplier_id
|
14
|
+
drop_table :suppliers_taxons
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateDeliveries < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :deliveries do |t|
|
4
|
+
t.integer :supplier_id
|
5
|
+
t.integer :order_id
|
6
|
+
t.boolean :pick_up
|
7
|
+
t.integer :shipping_method_id
|
8
|
+
t.integer :pickup_id
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :deliveries
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateShippingMethodsSuppliers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :shipping_methods_suppliers, :id => false do |t|
|
4
|
+
t.integer :supplier_id
|
5
|
+
t.integer :shipping_method_id
|
6
|
+
end
|
7
|
+
add_index :shipping_methods_suppliers, :supplier_id
|
8
|
+
add_index :shipping_methods_suppliers, :shipping_method_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
remove_index :shipping_methods_suppliers, :column => :shipping_method_id
|
13
|
+
remove_index :shipping_methods_suppliers, :column => :supplier_id
|
14
|
+
drop_table :shipping_methods_suppliers
|
15
|
+
end
|
16
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Use this file to load your own seed data from extensions.
|
2
|
+
# See the db/seeds.rb file in the Spree core for some ideas on what you can do here.
|
3
|
+
#
|
4
|
+
Rake::Task["db:load_dir"].invoke( "default" )
|
5
|
+
puts "Default data has been loaded"
|
6
|
+
|
7
|
+
puts "Create Taxonomy"
|
8
|
+
|
9
|
+
t = Taxonomy.create :name => "Products"
|
10
|
+
|
11
|
+
puts "Create Vendor Role"
|
12
|
+
|
13
|
+
r = Role.create :name => "vendor"
|
14
|
+
|
@@ -0,0 +1,411 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_suppliers_hooks'
|
3
|
+
require 'gmaps4rails'
|
4
|
+
require 'dragonfly'
|
5
|
+
require 'rack-cache'
|
6
|
+
|
7
|
+
module SpreeSuppliers
|
8
|
+
class Engine < Rails::Engine
|
9
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
10
|
+
|
11
|
+
def self.activate
|
12
|
+
Ability.register_ability(AbilityDecorator)
|
13
|
+
#### Modify the controllers with changes that are only associated with the Suppliers extension
|
14
|
+
|
15
|
+
# Append the checkout controller
|
16
|
+
#
|
17
|
+
CheckoutController.class_eval do
|
18
|
+
def edit
|
19
|
+
@order_products = @order.products
|
20
|
+
@suppliers = @order_products.collect{|item| item.supplier_id}.uniq
|
21
|
+
@delivery = Delivery.new
|
22
|
+
end
|
23
|
+
# Updates the order and advances to the next state (when possible.)
|
24
|
+
def update
|
25
|
+
@order_products = @order.products
|
26
|
+
@suppliers = @order_products.collect{|item| item.supplier_id}.uniq
|
27
|
+
if @order.update_attributes(object_params)
|
28
|
+
if @order.next
|
29
|
+
state_callback(:after)
|
30
|
+
else
|
31
|
+
flash[:error] = I18n.t(:payment_processing_failed)
|
32
|
+
respond_with(@order, :location => checkout_state_path(@order.state))
|
33
|
+
return
|
34
|
+
end
|
35
|
+
if @order.state == "payment"
|
36
|
+
@suppliers.each do |s|
|
37
|
+
delivery = @order.deliveries.find_or_create_by_supplier_id(s)
|
38
|
+
if delivery
|
39
|
+
if !params["shipping_method"].nil?
|
40
|
+
delivery.update_attributes(:pick_up => params["deliveries"][s.to_s], :pickup_id => params["pickups"][s.to_s], :shipping_method_id => params["shipping_method"][s.to_s])
|
41
|
+
else
|
42
|
+
delivery.update_attributes(:pick_up => params["deliveries"][s.to_s], :pickup_id => params["pickups"][s.to_s])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if @order.state == "complete" || @order.completed?
|
48
|
+
# This is where the SupplierInvoices are generated
|
49
|
+
# Back to the normal checkout process
|
50
|
+
flash[:notice] = I18n.t(:order_processed_successfully)
|
51
|
+
flash[:commerce_tracking] = "nothing special"
|
52
|
+
respond_with(@order, :location => completion_route)
|
53
|
+
else
|
54
|
+
respond_with(@order, :location => checkout_state_path(@order.state))
|
55
|
+
end
|
56
|
+
else
|
57
|
+
respond_with(@order) { |format| format.html { render :edit } }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Append the admin orders controller
|
63
|
+
#
|
64
|
+
Admin::OrdersController.class_eval do
|
65
|
+
def show
|
66
|
+
load_order
|
67
|
+
@fee = "0.86".to_d
|
68
|
+
if current_user.has_role?("vendor")
|
69
|
+
@invoices = @order.supplier_invoices
|
70
|
+
@invoices.select! {|s| s.supplier_id == current_user.supplier.id}
|
71
|
+
else
|
72
|
+
@invoices = @order.supplier_invoices
|
73
|
+
end
|
74
|
+
respond_with(@order)
|
75
|
+
end
|
76
|
+
def index
|
77
|
+
params[:search] ||= {}
|
78
|
+
params[:search][:completed_at_is_not_null] ||= '1' if Spree::Config[:show_only_complete_orders_by_default]
|
79
|
+
@show_only_completed = params[:search][:completed_at_is_not_null].present?
|
80
|
+
params[:search][:meta_sort] ||= @show_only_completed ? 'completed_at.desc' : 'created_at.desc'
|
81
|
+
@search = Order.metasearch(params[:search])
|
82
|
+
if !params[:search][:created_at_greater_than].blank?
|
83
|
+
params[:search][:created_at_greater_than] = Time.zone.parse(params[:search][:created_at_greater_than]).beginning_of_day rescue ""
|
84
|
+
end
|
85
|
+
if !params[:search][:created_at_less_than].blank?
|
86
|
+
params[:search][:created_at_less_than] = Time.zone.parse(params[:search][:created_at_less_than]).end_of_day rescue ""
|
87
|
+
end
|
88
|
+
if @show_only_completed
|
89
|
+
params[:search][:completed_at_greater_than] = params[:search].delete(:created_at_greater_than)
|
90
|
+
params[:search][:completed_at_less_than] = params[:search].delete(:created_at_less_than)
|
91
|
+
end
|
92
|
+
@orders = Order.metasearch(params[:search]).paginate(
|
93
|
+
:include => [:user, :shipments, :payments],
|
94
|
+
:per_page => Spree::Config[:orders_per_page],
|
95
|
+
:page => params[:page])
|
96
|
+
if current_user.has_role?("vendor")
|
97
|
+
@orders.select! {|o| o.supplier_invoices.select {|s| s.supplier_id == current_user.supplier.id}.size > 0}
|
98
|
+
end
|
99
|
+
respond_with(@orders)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Append the admin products controller
|
104
|
+
#
|
105
|
+
Admin::ProductsController.class_eval do
|
106
|
+
before_filter :load
|
107
|
+
before_filter :load_index, :only => [:index]
|
108
|
+
before_filter :edit_before, :only => [:edit]
|
109
|
+
create.before :create_before
|
110
|
+
create.fails :reset
|
111
|
+
update.before :update_taxons
|
112
|
+
def load
|
113
|
+
@suppliers = Supplier.find(:all, :order => "name")
|
114
|
+
if !Taxon.find_by_name("Products").nil?
|
115
|
+
@options = Taxon.all
|
116
|
+
end
|
117
|
+
end
|
118
|
+
def load_index
|
119
|
+
if current_user.roles.member?(Role.find_by_name("vendor"))
|
120
|
+
@collection.select! {|c| c.supplier_id == current_user.supplier.id}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
#indicate that we want to create a new product
|
124
|
+
def new
|
125
|
+
@object = Product.new()
|
126
|
+
@status = true
|
127
|
+
end
|
128
|
+
def edit_before
|
129
|
+
@status = false
|
130
|
+
end
|
131
|
+
def taxon_push object
|
132
|
+
object.taxons = []
|
133
|
+
Taxon.all.map {|m| object.taxons.push(Taxon.find_by_id(params[m.name])) if params.member?(m.name)}
|
134
|
+
return object
|
135
|
+
end
|
136
|
+
def reset
|
137
|
+
@status = true
|
138
|
+
end
|
139
|
+
def update_taxons
|
140
|
+
@object = taxon_push(@object)
|
141
|
+
end
|
142
|
+
def create_before
|
143
|
+
if current_user.has_role?("vendor")
|
144
|
+
@object = current_user.supplier.products.build(params[:product])
|
145
|
+
else
|
146
|
+
@object = Product.new(params[:product])
|
147
|
+
end
|
148
|
+
@object = taxon_push(@object)
|
149
|
+
end
|
150
|
+
def publish
|
151
|
+
p = Product.find_by_name(params[:id])
|
152
|
+
p.available_on = Date.today
|
153
|
+
p.save
|
154
|
+
redirect_to edit_admin_product_path(p)
|
155
|
+
end
|
156
|
+
def unpublish
|
157
|
+
p = Product.find_by_name(params[:id])
|
158
|
+
p.available_on = nil
|
159
|
+
p.save
|
160
|
+
redirect_to edit_admin_product_path(p)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
UserSessionsController.class_eval do
|
165
|
+
def create
|
166
|
+
authenticate_user!
|
167
|
+
if user_signed_in?
|
168
|
+
if current_user.has_role?("vendor")
|
169
|
+
redirect_to admin_orders_path
|
170
|
+
else
|
171
|
+
respond_to do |format|
|
172
|
+
format.html {
|
173
|
+
flash[:notice] = I18n.t("logged_in_succesfully")
|
174
|
+
redirect_back_or_default(products_path)
|
175
|
+
}
|
176
|
+
format.js {
|
177
|
+
user = resource.record
|
178
|
+
render :json => {:ship_address => user.ship_address, :bill_address => user.bill_address}.to_json
|
179
|
+
}
|
180
|
+
end
|
181
|
+
end
|
182
|
+
else
|
183
|
+
flash[:error] = I18n.t("devise.failure.invalid")
|
184
|
+
render :new
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#### Modify the Models with changes that are only associated with the Suppliers extension
|
190
|
+
# Append the product model
|
191
|
+
#
|
192
|
+
Product.class_eval do
|
193
|
+
belongs_to :supplier
|
194
|
+
has_one :item
|
195
|
+
end
|
196
|
+
|
197
|
+
# Append the order model
|
198
|
+
#
|
199
|
+
LineItem.class_eval do
|
200
|
+
has_many :items
|
201
|
+
end
|
202
|
+
|
203
|
+
Image.class_eval do
|
204
|
+
attachment_definitions[:attachment][:styles] = {
|
205
|
+
:mini => '48x48>', # thumbs under image
|
206
|
+
:small => '100x100>', # images on category view
|
207
|
+
:product => '240x240>', # full product image
|
208
|
+
:large => '600x600>' # light box image
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
# Append the order model
|
213
|
+
#
|
214
|
+
Order.class_eval do
|
215
|
+
has_many :supplier_invoices
|
216
|
+
has_many :deliveries
|
217
|
+
def generate_invoices(order)
|
218
|
+
@order = order
|
219
|
+
@order_products = @order.line_items
|
220
|
+
@suppliers = @order_products.collect{|item| item.product.supplier_id}.uniq
|
221
|
+
@invoices = @suppliers.count
|
222
|
+
|
223
|
+
for i in 0..@invoices - 1
|
224
|
+
@supplier_products = @order_products.select{|x| x.product.supplier_id == @suppliers[i]}
|
225
|
+
@product_count = @supplier_products.count
|
226
|
+
invoice = SupplierInvoice.create(:order_id => @order.id, :supplier_id => @suppliers[i], :item_count => @product_count)
|
227
|
+
|
228
|
+
@supplier_products.each do |item|
|
229
|
+
invoice.items.create(:product_id => item.product.id, :quantity => item.quantity, :line_item_id => item.id)
|
230
|
+
end
|
231
|
+
|
232
|
+
item_total = "0.00".to_d
|
233
|
+
invoice.items.each do |i|
|
234
|
+
item_total = (i.line_item.variant.price * i.quantity) + item_total
|
235
|
+
end
|
236
|
+
invoice.update_attributes(:invoice_total => item_total)
|
237
|
+
@invoice = invoice
|
238
|
+
#SupplierMailer.invoice_email(@invoice).deliver
|
239
|
+
end
|
240
|
+
end
|
241
|
+
def finalize!
|
242
|
+
update_attribute(:completed_at, Time.now)
|
243
|
+
self.out_of_stock_items = InventoryUnit.assign_opening_inventory(self)
|
244
|
+
# lock any optional adjustments (coupon promotions, etc.)
|
245
|
+
adjustments.optional.each { |adjustment| adjustment.update_attribute("locked", true) }
|
246
|
+
# generate the invoices for each supplier
|
247
|
+
generate_invoices(self)
|
248
|
+
OrderMailer.confirm_email(self).deliver
|
249
|
+
|
250
|
+
self.state_events.create({
|
251
|
+
:previous_state => "cart",
|
252
|
+
:next_state => "complete",
|
253
|
+
:name => "order" ,
|
254
|
+
:user_id => (User.respond_to?(:current) && User.current.try(:id)) || self.user_id
|
255
|
+
})
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Append the state model
|
260
|
+
#
|
261
|
+
State.class_eval do
|
262
|
+
has_many :suppliers
|
263
|
+
end
|
264
|
+
|
265
|
+
# Append the user model
|
266
|
+
#
|
267
|
+
User.class_eval do
|
268
|
+
belongs_to :supplier
|
269
|
+
def user_address
|
270
|
+
"#{self.bill_address.address1}, #{self.bill_address.city}, #{self.bill_address.state.country.name}"
|
271
|
+
end
|
272
|
+
def vendor?
|
273
|
+
self.roles.member?(Role.find_by_name("vendor"))
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
Taxon.class_eval do
|
278
|
+
has_and_belongs_to_many :suppliers
|
279
|
+
end
|
280
|
+
|
281
|
+
Admin::UsersController.class_eval do
|
282
|
+
def new
|
283
|
+
@user = User.new
|
284
|
+
end
|
285
|
+
def create
|
286
|
+
@user.create(params[:user])
|
287
|
+
if @user.save
|
288
|
+
@user.supplier_id = params[:user][:supplier_id]
|
289
|
+
@user.save
|
290
|
+
flash[:notice] = "User updated successfully."
|
291
|
+
redirect_to :back
|
292
|
+
else
|
293
|
+
flash[:error] = "There was an error updating the user."
|
294
|
+
redirect_to :back
|
295
|
+
end
|
296
|
+
end
|
297
|
+
def edit
|
298
|
+
@user = User.find(params[:id])
|
299
|
+
end
|
300
|
+
def update
|
301
|
+
@user.update_attributes(params[:user])
|
302
|
+
if @user.save
|
303
|
+
@user.supplier_id = params[:user][:supplier_id]
|
304
|
+
@user.save
|
305
|
+
flash[:notice] = "User updated successfully."
|
306
|
+
redirect_to :back
|
307
|
+
else
|
308
|
+
flash[:error] = "There was an error updating the user."
|
309
|
+
redirect_to :back
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
### UGLY HACK
|
315
|
+
Admin::ProductsController.class_eval do
|
316
|
+
def authorize_admin
|
317
|
+
authorize! :admin, Product
|
318
|
+
authorize! params[:action].to_sym, Product
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
Admin::PromotionsController.class_eval do
|
323
|
+
def authorize_admin
|
324
|
+
authorize! :admin, Promotion
|
325
|
+
authorize! params[:action].to_sym, Promotion
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
Admin::VariantsController.class_eval do
|
330
|
+
def authorize_admin
|
331
|
+
authorize! :admin, Variant
|
332
|
+
authorize! params[:action].to_sym, Variant
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
Admin::OptionTypesController.class_eval do
|
337
|
+
def authorize_admin
|
338
|
+
authorize! :admin, OptionType
|
339
|
+
authorize! params[:action].to_sym, OptionType
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
Admin::PropertiesController.class_eval do
|
344
|
+
def authorize_admin
|
345
|
+
authorize! :admin , Property
|
346
|
+
authorize! params[:action].to_sym, Property
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
Admin::PrototypesController.class_eval do
|
351
|
+
def authorize_admin
|
352
|
+
authorize! :admin, Prototype
|
353
|
+
authorize! params[:action].to_sym, Prototype
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
Admin::ProductGroupsController.class_eval do
|
358
|
+
def authorize_admin
|
359
|
+
authorize! :admin, ProductGroup
|
360
|
+
authorize! params[:action].to_sym, ProductGroup
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
Admin::ProductPropertiesController.class_eval do
|
365
|
+
def authorize_admin
|
366
|
+
authorize! :admin, Product
|
367
|
+
authorize! params[:action].to_sym, Product
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
Admin::TaxonsController.class_eval do
|
372
|
+
def authorize_admin
|
373
|
+
authorize! :admin, Taxon
|
374
|
+
authorize! params[:action].to_sym, Taxon
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
Admin::PickupsController.class_eval do
|
379
|
+
def authorize_admin
|
380
|
+
authorize! :admin, Pickup
|
381
|
+
authorize! params[:action].to_sym, Pickup
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
Admin::PickupLocationsController.class_eval do
|
386
|
+
def authorize_admin
|
387
|
+
authorize! :admin, PickupLocation
|
388
|
+
authorize! params[:action].to_sym, PickupLocation
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
Admin::OrdersController.class_eval do
|
393
|
+
def authorize_admin
|
394
|
+
authorize! :admin, Order
|
395
|
+
authorize! params[:action].to_sym, Order
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
Admin::SuppliersController.class_eval do
|
400
|
+
def authorize_admin
|
401
|
+
authorize! :admin, Supplier
|
402
|
+
authorize! params[:action].to_sym, Supplier
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
### END UGLY HACK
|
407
|
+
end
|
408
|
+
|
409
|
+
config.to_prepare &method(:activate).to_proc
|
410
|
+
end
|
411
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class SuppliersHooks < Spree::ThemeSupport::HookListener
|
2
|
+
insert_after :admin_tabs do
|
3
|
+
%(<%= tab(:suppliers) %>)
|
4
|
+
end
|
5
|
+
|
6
|
+
# insert_after :admin_order_tabs do
|
7
|
+
# %(<%= tab(:order_line_items) %>)
|
8
|
+
# end
|
9
|
+
|
10
|
+
# insert_after :admin_product_tabs do
|
11
|
+
# %(<%= tab(:selected_admin_productor_vendors_url) %>)
|
12
|
+
# end
|
13
|
+
insert_after :admin_product_form_right ,"admin/products/suppliers_form"
|
14
|
+
|
15
|
+
insert_after :admin_configuration_menu do
|
16
|
+
%(<tr><td><%= link_to t("Suppliers"), admin_suppliers_url %><td><td><%= t("Suppliers_description") %></td></tr>)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Add on_hand field to admin/products listing
|
20
|
+
insert_after :admin_products_index_headers do
|
21
|
+
%(<th><%= sort_link @search, :count_on_hand, t("count_on_hand") %></th>)
|
22
|
+
end
|
23
|
+
|
24
|
+
insert_after :admin_tabs do
|
25
|
+
%(<%= tab(:pickups) %>)
|
26
|
+
end
|
27
|
+
|
28
|
+
insert_after :admin_inside_head do
|
29
|
+
%(<%= javascript_include_tag 'jquery.ui.datepicker.js', 'jquery-ui.multidatespicker.js' %>)
|
30
|
+
end
|
31
|
+
|
32
|
+
insert_after :admin_inside_head do
|
33
|
+
%(<%= stylesheet_link_tag 'suppliers.css' %>)
|
34
|
+
end
|
35
|
+
|
36
|
+
insert_after :admin_products_index_rows do
|
37
|
+
%(<td><%= product.count_on_hand %></td>)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
namespace :spree_suppliers do
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
+
task :install do
|
4
|
+
Rake::Task['spree_suppliers:install:migrations'].invoke
|
5
|
+
Rake::Task['spree_suppliers:install:assets'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :install do
|
9
|
+
|
10
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
11
|
+
task :migrations do
|
12
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
13
|
+
destination = File.join(Rails.root, 'db')
|
14
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
18
|
+
task :assets do
|
19
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
20
|
+
destination = File.join(Rails.root, 'public')
|
21
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
22
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|