mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-12 18:36:49 +00:00
Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f03d9b66f0 | ||
|
|
5dcba7403b | ||
|
|
926440a978 | ||
|
|
9b32579bd6 | ||
|
|
5ac904005b | ||
|
|
03610c93de | ||
|
|
c5941d6cb5 | ||
|
|
773adca838 | ||
|
|
13317347bb | ||
|
|
f960cc44ba | ||
|
|
a9293709d8 | ||
|
|
a3042118c7 | ||
|
|
ede4649fbf | ||
|
|
4dd5e12968 | ||
|
|
d74591afe6 | ||
|
|
09b60908b8 | ||
|
|
d1b9ce92f6 | ||
|
|
784969097d | ||
|
|
15e91f7743 | ||
|
|
c46019d68c | ||
|
|
aa336d9b9f | ||
|
|
ff029b8903 | ||
|
|
a362dd5161 | ||
|
|
51850be83e | ||
|
|
41d547ac2d | ||
|
|
81b33772fe | ||
|
|
32db258db0 | ||
|
|
3b855a866a | ||
|
|
eb7d69fe6b | ||
|
|
4c0109bccc | ||
|
|
f83a5b0ba8 | ||
|
|
ddb01e4ccb | ||
|
|
87a89324d9 | ||
|
|
4fc7295b97 | ||
|
|
5b025a6cba | ||
|
|
9166829930 | ||
|
|
8c7a02ec10 | ||
|
|
f4f250675c | ||
|
|
394a269df2 | ||
|
|
41dcc85ad1 | ||
|
|
9be9d75cb5 | ||
|
|
11483a77e8 | ||
|
|
ba895ed486 | ||
|
|
36d342f216 | ||
|
|
d09123eb22 | ||
|
|
642f58551c | ||
|
|
9fbcd8c01b | ||
|
|
927970d1a9 | ||
|
|
3dd3d8030f | ||
|
|
cab61ddb7c | ||
|
|
015b7f88b0 | ||
|
|
28fc16ac66 | ||
|
|
e1d4ee318c | ||
|
|
48497266da | ||
|
|
fe5fd76415 | ||
|
|
c05911fa10 | ||
|
|
a686a820d9 | ||
|
|
3889545f2b | ||
|
|
7432cb416e | ||
|
|
0b830a7845 | ||
|
|
58e5724f81 | ||
|
|
c07a33d88c | ||
|
|
d080aa49d5 | ||
|
|
a31c5bbe46 | ||
|
|
b35fb618f3 | ||
|
|
8c7ed6f4ef | ||
|
|
1709083d8f | ||
|
|
5803da9c55 | ||
|
|
0ad6045363 | ||
|
|
9737f21bb8 | ||
|
|
d7a5a87aef | ||
|
|
3b8c41840f | ||
|
|
fe3743af16 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,4 +27,5 @@ public/stylesheets
|
||||
public/images
|
||||
public/spree
|
||||
config/abr.yml
|
||||
config/heroku_env.rb
|
||||
NERD_tree*
|
||||
|
||||
7
Gemfile
7
Gemfile
@@ -6,9 +6,10 @@ gem 'rails', '3.2.8'
|
||||
gem 'pg'
|
||||
gem 'spree', :git => 'git://github.com/spree/spree.git', :branch => '1-1-stable'
|
||||
gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git'
|
||||
gem 'spree_paypal_express', :git => 'git://github.com/spree/spree_paypal_express.git', :branch => '1-1-stable'
|
||||
gem 'spree_paypal_express', :git => 'git://github.com/eaterprises/spree_paypal_express.git', :branch => '1-1-stable'
|
||||
gem 'spree_last_address', :git => 'git://github.com/dancinglightning/spree-last-address.git'
|
||||
|
||||
gem 'comfortable_mexican_sofa'
|
||||
|
||||
# Fix bug in simple_form preventing collection_check_boxes usage within form_for block
|
||||
# When merged, revert to upstream gem
|
||||
@@ -16,9 +17,9 @@ gem 'simple_form', :git => 'git://github.com/RohanM/simple_form.git'
|
||||
|
||||
gem 'unicorn'
|
||||
gem 'bugsnag'
|
||||
gem 'spree_heroku', :git => 'git://github.com/joneslee85/spree-heroku.git'
|
||||
gem 'spree_heroku', :git => 'git://github.com/eaterprises/spree-heroku.git'
|
||||
gem 'haml'
|
||||
gem 'aws-s3'
|
||||
gem 'aws-sdk'
|
||||
gem 'andand'
|
||||
gem 'truncate_html'
|
||||
|
||||
|
||||
74
Gemfile.lock
74
Gemfile.lock
@@ -14,16 +14,25 @@ GIT
|
||||
spree_core (>= 1.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/joneslee85/spree-heroku.git
|
||||
revision: 63f0cfa47089cae50365e226ec7dd1eccde0ac05
|
||||
remote: git://github.com/eaterprises/spree-heroku.git
|
||||
revision: a1e07bf7a22fc0c07a1be9148f477d20b557dbf6
|
||||
specs:
|
||||
spree_heroku (1.0)
|
||||
aws-sdk (~> 1.3.4)
|
||||
spree_core (>= 0.70.0)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/eaterprises/spree_paypal_express.git
|
||||
revision: 7dd46e6e549d82c4d603f685a7cb7fbb4af0d973
|
||||
branch: 1-1-stable
|
||||
specs:
|
||||
spree_paypal_express (1.1.0)
|
||||
spree_auth (>= 1.0.0)
|
||||
spree_core (>= 1.0.0)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/spree/spree.git
|
||||
revision: d66ffac9088d0d5d0b0d146f305044ce619f0464
|
||||
revision: 46691e075129fd3d7b59e296d73149a9066c1b9d
|
||||
branch: 1-1-stable
|
||||
specs:
|
||||
spree (1.1.3)
|
||||
@@ -54,7 +63,7 @@ GIT
|
||||
jquery-rails (~> 2.0)
|
||||
kaminari (= 0.13.0)
|
||||
nested_set (= 1.7.0)
|
||||
paperclip (~> 2.7)
|
||||
paperclip (~> 2.8)
|
||||
rails (~> 3.2.8)
|
||||
ransack (~> 0.6.0)
|
||||
state_machine (= 1.1.2)
|
||||
@@ -77,15 +86,6 @@ GIT
|
||||
i18n (~> 0.5)
|
||||
spree (~> 1.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/spree/spree_paypal_express.git
|
||||
revision: 2c61f1700ef853e3d4f39739793dc3308422e94b
|
||||
branch: 1-1-stable
|
||||
specs:
|
||||
spree_paypal_express (1.1.0)
|
||||
spree_auth (>= 1.0.0)
|
||||
spree_core (>= 1.0.0)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
@@ -102,6 +102,7 @@ GEM
|
||||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.1.3)
|
||||
active_link_to (1.0.0)
|
||||
active_utils (1.0.5)
|
||||
activesupport (>= 2.3.11)
|
||||
i18n
|
||||
@@ -128,25 +129,21 @@ GEM
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
acts_as_list (0.1.4)
|
||||
addressable (2.2.8)
|
||||
addressable (2.3.2)
|
||||
andand (1.3.3)
|
||||
ansi (1.4.2)
|
||||
arel (3.0.2)
|
||||
awesome_print (1.0.2)
|
||||
aws-s3 (0.6.3)
|
||||
builder
|
||||
mime-types
|
||||
xml-simple
|
||||
aws-sdk (1.3.9)
|
||||
httparty (~> 0.7)
|
||||
json (~> 1.4)
|
||||
nokogiri (>= 1.4.4)
|
||||
uuidtools (~> 2.1)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bugsnag (1.1.2)
|
||||
httparty (~> 0.8.3)
|
||||
multi_json (~> 1.3.4)
|
||||
builder (3.0.3)
|
||||
bugsnag (1.2.4)
|
||||
httparty (>= 0.5, < 1.0)
|
||||
multi_json (~> 1.0)
|
||||
builder (3.0.4)
|
||||
cancan (1.6.7)
|
||||
capybara (1.1.2)
|
||||
mime-types (>= 1.16)
|
||||
@@ -155,9 +152,9 @@ GEM
|
||||
rack-test (>= 0.5.4)
|
||||
selenium-webdriver (~> 2.0)
|
||||
xpath (~> 0.1.4)
|
||||
childprocess (0.3.2)
|
||||
ffi (~> 1.0.6)
|
||||
cocaine (0.3.0)
|
||||
childprocess (0.3.6)
|
||||
ffi (~> 1.0, >= 1.0.6)
|
||||
cocaine (0.4.2)
|
||||
coderay (1.0.7)
|
||||
coffee-rails (3.2.2)
|
||||
coffee-script (>= 2.2.0)
|
||||
@@ -167,6 +164,10 @@ GEM
|
||||
execjs
|
||||
coffee-script-source (1.3.3)
|
||||
columnize (0.3.6)
|
||||
comfortable_mexican_sofa (1.6.24)
|
||||
active_link_to (~> 1.0.0)
|
||||
paperclip (>= 2.3.0)
|
||||
rails (>= 3.0.0)
|
||||
database_cleaner (0.7.1)
|
||||
debugger (1.1.4)
|
||||
columnize (>= 0.3.1)
|
||||
@@ -195,7 +196,7 @@ GEM
|
||||
faker (1.0.1)
|
||||
i18n (~> 0.4)
|
||||
ffaker (1.12.1)
|
||||
ffi (1.0.11)
|
||||
ffi (1.1.5)
|
||||
haml (3.1.6)
|
||||
highline (1.6.11)
|
||||
hike (1.2.1)
|
||||
@@ -204,7 +205,7 @@ GEM
|
||||
multi_xml
|
||||
i18n (0.6.1)
|
||||
journey (1.0.4)
|
||||
jquery-rails (2.1.2)
|
||||
jquery-rails (2.1.3)
|
||||
railties (>= 3.1.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
json (1.7.5)
|
||||
@@ -214,7 +215,7 @@ GEM
|
||||
railties (>= 3.0.0)
|
||||
kgio (2.7.4)
|
||||
libv8 (3.3.10.4)
|
||||
libwebsocket (0.1.3)
|
||||
libwebsocket (0.1.5)
|
||||
addressable
|
||||
mail (2.4.4)
|
||||
i18n (>= 0.4.0)
|
||||
@@ -232,7 +233,7 @@ GEM
|
||||
railties (>= 3.0.0)
|
||||
nokogiri (1.5.5)
|
||||
orm_adapter (0.0.7)
|
||||
paperclip (2.7.0)
|
||||
paperclip (2.8.0)
|
||||
activerecord (>= 2.3.0)
|
||||
activesupport (>= 2.3.2)
|
||||
cocaine (>= 0.0.2)
|
||||
@@ -256,7 +257,7 @@ GEM
|
||||
rack (>= 0.4)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.1)
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.2.8)
|
||||
actionmailer (= 3.2.8)
|
||||
@@ -294,15 +295,14 @@ GEM
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec (~> 2.10.0)
|
||||
rubyzip (0.9.8)
|
||||
rubyzip (0.9.9)
|
||||
sass (3.1.19)
|
||||
sass-rails (3.2.5)
|
||||
railties (~> 3.2.0)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3)
|
||||
selenium-webdriver (2.22.2)
|
||||
selenium-webdriver (2.25.0)
|
||||
childprocess (>= 0.2.5)
|
||||
ffi (~> 1.0)
|
||||
libwebsocket (~> 0.1.3)
|
||||
multi_json (~> 1.0)
|
||||
rubyzip
|
||||
@@ -320,13 +320,13 @@ GEM
|
||||
libv8 (~> 3.3.10)
|
||||
thor (0.16.0)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.10)
|
||||
treetop (1.4.12)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
truncate_html (0.5.5)
|
||||
turn (0.8.3)
|
||||
ansi
|
||||
tzinfo (0.3.33)
|
||||
tzinfo (0.3.34)
|
||||
uglifier (1.2.4)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
@@ -337,7 +337,6 @@ GEM
|
||||
uuidtools (2.1.3)
|
||||
warden (1.1.1)
|
||||
rack (>= 1.0)
|
||||
xml-simple (1.1.1)
|
||||
xpath (0.1.4)
|
||||
nokogiri (~> 1.3)
|
||||
|
||||
@@ -347,10 +346,11 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
andand
|
||||
awesome_print
|
||||
aws-s3
|
||||
aws-sdk
|
||||
bugsnag
|
||||
capybara
|
||||
coffee-rails (~> 3.2.1)
|
||||
comfortable_mexican_sofa
|
||||
database_cleaner (= 0.7.1)
|
||||
factory_girl_rails
|
||||
faker
|
||||
|
||||
@@ -20,11 +20,11 @@ hosted at GitHub.
|
||||
|
||||
You can view the code at:
|
||||
|
||||
https://github.com/andrewspinks/openfoodweb
|
||||
https://github.com/eaterprises/openfoodweb
|
||||
|
||||
You can download the source with the command:
|
||||
|
||||
git clone git@github.com:andrewspinks/openfoodweb
|
||||
git clone git@github.com:eaterprises/openfoodweb
|
||||
|
||||
|
||||
## Get it running
|
||||
@@ -80,6 +80,7 @@ speak to Andrew Spinks.
|
||||
|
||||
* Andrew Spinks (http://github.com/andrewspinks)
|
||||
* Rohan Mitchell (http://github.com/rohanm)
|
||||
* Rob Harrington (http://github.com/oeoeaio)
|
||||
|
||||
|
||||
## Licence
|
||||
|
||||
@@ -10,6 +10,15 @@ $(document).ready(function() {
|
||||
|
||||
// Product page with master price only
|
||||
$(".add-to-cart input.title:not(#quantity):not(.max_quantity)").change(products_update_price_without_variant).change();
|
||||
|
||||
// Product page other
|
||||
$("#distributor_id").change(function() {
|
||||
var distributor_html = distributors[$(this).val()];
|
||||
if(!distributor_html) {
|
||||
distributor_html = 'When you select a distributor for your order, their address and pickup times will be displayed here.';
|
||||
}
|
||||
$("#product-distributor-details .distributor-details").html(distributor_html);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -4,4 +4,11 @@
|
||||
|
||||
#header h1 {
|
||||
left: 275px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Fix conflict between Spree and elRTE's styles */
|
||||
.el-rte .toolbar {
|
||||
float: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,13 @@ ul.product-listing {
|
||||
}
|
||||
|
||||
|
||||
/* Supplier and distributor description */
|
||||
.supplier-description, .distributor-description {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Highlight local products in distributor-split product listings */
|
||||
#products-local ul {
|
||||
margin-bottom: 1em;
|
||||
@@ -137,6 +144,19 @@ ul.product-listing {
|
||||
}
|
||||
|
||||
|
||||
/* Distributor details on product details page */
|
||||
fieldset#product-distributor-details {
|
||||
float: right;
|
||||
margin-top: 0;
|
||||
width: 250px;
|
||||
@extend #shipping;
|
||||
}
|
||||
|
||||
#product-variants {
|
||||
float: none;
|
||||
}
|
||||
|
||||
|
||||
/* Add to cart form on product details page */
|
||||
#cart-form {
|
||||
.error-distributor {
|
||||
|
||||
28
app/controllers/admin/distributors_controller.rb
Normal file
28
app/controllers/admin/distributors_controller.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Admin
|
||||
class DistributorsController < ResourceController
|
||||
before_filter :load_distributor_set, :only => :index
|
||||
before_filter :load_countries, :except => :index
|
||||
|
||||
def bulk_update
|
||||
@distributor_set = DistributorSet.new(params[:distributor_set])
|
||||
if @distributor_set.save
|
||||
redirect_to main_app.admin_distributors_path, :notice => 'Distributor collection times updated.'
|
||||
else
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_distributor_set
|
||||
@distributor_set = DistributorSet.new :distributors => collection
|
||||
end
|
||||
|
||||
def load_countries
|
||||
@countries = Spree::Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
42
app/controllers/admin/resource_controller.rb
Normal file
42
app/controllers/admin/resource_controller.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
module Admin
|
||||
class ResourceController < Spree::Admin::ResourceController
|
||||
def model_class
|
||||
"#{controller_name.classify}".constantize
|
||||
end
|
||||
|
||||
|
||||
# URL helpers
|
||||
def new_object_url(options = {})
|
||||
if parent_data.present?
|
||||
main_app.new_polymorphic_url([:admin, parent, model_class], options)
|
||||
else
|
||||
main_app.new_polymorphic_url([:admin, model_class], options)
|
||||
end
|
||||
end
|
||||
|
||||
def edit_object_url(object, options = {})
|
||||
if parent_data.present?
|
||||
main_app.send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options
|
||||
else
|
||||
main_app.send "edit_admin_#{object_name}_url", object, options
|
||||
end
|
||||
end
|
||||
|
||||
def object_url(object = nil, options = {})
|
||||
target = object ? object : @object
|
||||
if parent_data.present?
|
||||
main_app.send "admin_#{model_name}_#{object_name}_url", parent, target, options
|
||||
else
|
||||
main_app.send "admin_#{object_name}_url", target, options
|
||||
end
|
||||
end
|
||||
|
||||
def collection_url(options = {})
|
||||
if parent_data.present?
|
||||
main_app.polymorphic_url([:admin, parent, model_class], options)
|
||||
else
|
||||
main_app.polymorphic_url([:admin, model_class], options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/controllers/admin/suppliers_controller.rb
Normal file
16
app/controllers/admin/suppliers_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Admin
|
||||
class SuppliersController < ResourceController
|
||||
before_filter :load_data, :except => [:index]
|
||||
|
||||
helper 'spree/products'
|
||||
|
||||
private
|
||||
def load_data
|
||||
@countries = Spree::Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,12 +1,18 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
|
||||
before_filter :load_data_for_menu
|
||||
before_filter :load_data_for_sidebar
|
||||
|
||||
private
|
||||
def load_data_for_menu
|
||||
@cms_site = Cms::Site.where(:identifier => 'open-food-web').first
|
||||
end
|
||||
|
||||
|
||||
def load_data_for_sidebar
|
||||
@suppliers = Spree::Supplier.all
|
||||
@distributors = Spree::Distributor.with_active_products_on_hand.by_name
|
||||
@suppliers = Supplier.all
|
||||
@distributors = Distributor.with_active_products_on_hand.by_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
10
app/controllers/base_controller.rb
Normal file
10
app/controllers/base_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class BaseController < ApplicationController
|
||||
include Spree::Core::ControllerHelpers
|
||||
include Spree::Core::RespondWith
|
||||
|
||||
helper 'spree/base'
|
||||
|
||||
# Spree::Core::ControllerHelpers declares helper_method get_taxonomies, so we need to
|
||||
# include Spree::ProductsHelper so that method is available on the controller
|
||||
include Spree::ProductsHelper
|
||||
end
|
||||
45
app/controllers/distributors_controller.rb
Normal file
45
app/controllers/distributors_controller.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
class DistributorsController < BaseController
|
||||
def index
|
||||
@distributors = Distributor.all
|
||||
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
@distributor_details = Hash[@distributors.map { |d| [d.id, render_to_string(:partial => 'distributors/details', :locals => {:distributor => d})] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@distributor = Distributor.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
|
||||
def select
|
||||
distributor = Distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = distributor
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to distributor
|
||||
end
|
||||
|
||||
def deselect
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = nil
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class DistributorsController < ResourceController
|
||||
before_filter :load_distributor_set, :only => :index
|
||||
before_filter :load_countries, :except => :index
|
||||
|
||||
def bulk_update
|
||||
@distributor_set = DistributorSet.new(params[:distributor_set])
|
||||
if @distributor_set.save
|
||||
redirect_to admin_distributors_path, :notice => 'Distributor collection times updated.'
|
||||
else
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_distributor_set
|
||||
@distributor_set = Spree::DistributorSet.new :distributors => collection
|
||||
end
|
||||
|
||||
def load_countries
|
||||
@countries = Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,15 @@
|
||||
require 'csv'
|
||||
require 'open_food_web/order_and_distributor_report'
|
||||
require 'open_food_web/group_buy_report'
|
||||
require 'open_food_web/order_grouper'
|
||||
|
||||
Spree::Admin::ReportsController.class_eval do
|
||||
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:orders_and_distributors => {:name => "Orders And Distributors", :description => "Orders with distributor details"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:group_buys => {:name => "Group Buys", :description => "Orders by supplier and variant"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:bulk_coop => {:name => "Bulk Co-Op", :description => "Reports for Bulk Co-Op orders"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:payments => {:name => "Payment Reports", :description => "Reports for Payments"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:order_cycles => {:name => "Order Cycle Reports", :description => "Reports for Order Cycles"}})
|
||||
|
||||
def orders_and_distributors
|
||||
params[:q] = {} unless params[:q]
|
||||
@@ -23,7 +29,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
orders = @search.result
|
||||
|
||||
@report = OpenFoodWeb::OrderAndDistributorReport.new orders
|
||||
if(!params[:csv])
|
||||
unless params[:csv]
|
||||
render :html => @report
|
||||
else
|
||||
csv_string = CSV.generate do |csv|
|
||||
@@ -34,4 +40,455 @@ Spree::Admin::ReportsController.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
def group_buys
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "created_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
|
||||
@distributors = Distributor.all
|
||||
|
||||
@report = OpenFoodWeb::GroupBuyReport.new orders
|
||||
unless params[:csv]
|
||||
render :html => @report
|
||||
else
|
||||
csv_string = CSV.generate do |csv|
|
||||
csv << @report.header
|
||||
@report.table.each { |row| csv << row }
|
||||
end
|
||||
send_data csv_string, :filename => "group_buy.csv"
|
||||
end
|
||||
end
|
||||
|
||||
def bulk_coop
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "created_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
line_items = orders.map { |o| o.line_items }.flatten
|
||||
|
||||
@distributors = Distributor.all
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
when "bulk_coop_supplier_report"
|
||||
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * li.variant.weight || 0 } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * li.variant.weight || 0 } } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "bulk_coop_allocation"
|
||||
|
||||
header = ["Customer", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } },
|
||||
{ group_by: proc { |li| li.order.user },
|
||||
sort_by: proc { |user| user.to_s } } ]
|
||||
|
||||
when "bulk_coop_packing_sheets"
|
||||
|
||||
header = ["Customer", "Product", "Variant", "Sum Total"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.sum { |li| li.quantity } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } },
|
||||
{ group_by: proc { |li| li.order.user },
|
||||
sort_by: proc { |user| user.to_s } } ]
|
||||
|
||||
when "bulk_coop_customer_payments"
|
||||
|
||||
header = ["Customer", "Date of Order", "Total Cost", "Amount Owing", "Amount Paid"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.order.created_at.to_s },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.total } },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.outstanding_balance } },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.payment_total } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.order.user },
|
||||
sort_by: proc { |user| user.to_s } },
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.created_at } } ]
|
||||
|
||||
else # List all line items
|
||||
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| "UNIT SIZE" },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
|
||||
@header = header
|
||||
@table = order_grouper.table(line_items)
|
||||
csv_file_name = "bulk_coop.csv"
|
||||
|
||||
render_report(@header, @table, params[:csv], csv_file_name)
|
||||
end
|
||||
|
||||
def payments
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "created_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
|
||||
|
||||
@distributors = Distributor.all
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
when "payments_by_payment_type"
|
||||
table_items = payments
|
||||
|
||||
header = ["Payment State", "Distributor", "Payment Type", "Total ($)"]
|
||||
|
||||
columns = [ proc { |payments| payments.first.order.payment_state },
|
||||
proc { |payments| payments.first.order.distributor.name },
|
||||
proc { |payments| payments.first.payment_method.name },
|
||||
proc { |payments| payments.sum { |payment| payment.amount } } ]
|
||||
|
||||
rules = [ { group_by: proc { |payment| payment.order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |payment| payment.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } },
|
||||
{ group_by: proc { |payment| payment.payment_method },
|
||||
sort_by: proc { |method| method.name } } ]
|
||||
|
||||
when "itemised_payment_totals"
|
||||
table_items = orders
|
||||
|
||||
header = ["Payment State", "Distributor", "Product Total ($)", "Shipping Total ($)", "Outstanding Balance ($)", "Total ($)"]
|
||||
|
||||
columns = [ proc { |orders| orders.first.payment_state },
|
||||
proc { |orders| orders.first.distributor.name },
|
||||
proc { |orders| orders.sum { |o| o.item_total } },
|
||||
proc { |orders| orders.sum { |o| o.ship_total } },
|
||||
proc { |orders| orders.sum { |o| o.outstanding_balance } },
|
||||
proc { |orders| orders.sum { |o| o.total } } ]
|
||||
|
||||
rules = [ { group_by: proc { |order| order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |order| order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } } ]
|
||||
|
||||
when "payment_totals"
|
||||
table_items = orders
|
||||
|
||||
header = ["Payment State", "Distributor", "Product Total ($)", "Shipping Total ($)", "Total ($)", "EFT ($)", "PayPal ($)", "Outstanding Balance ($)"]
|
||||
|
||||
columns = [ proc { |orders| orders.first.payment_state },
|
||||
proc { |orders| orders.first.distributor.name },
|
||||
proc { |orders| orders.sum { |o| o.item_total } },
|
||||
proc { |orders| orders.sum { |o| o.ship_total } },
|
||||
proc { |orders| orders.sum { |o| o.total } },
|
||||
proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "EFT") }.sum { |payment| payment.amount } } },
|
||||
proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "PayPal") }.sum{ |payment| payment.amount } } },
|
||||
proc { |orders| orders.sum { |o| o.outstanding_balance } } ]
|
||||
|
||||
rules = [ { group_by: proc { |order| order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |order| order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } } ]
|
||||
|
||||
else
|
||||
table_items = payments
|
||||
|
||||
header = ["Payment State", "Distributor", "Payment Type", "Total ($)"]
|
||||
|
||||
columns = [ proc { |payments| payments.first.order.payment_state },
|
||||
proc { |payments| payments.first.order.distributor.name },
|
||||
proc { |payments| payments.first.payment_method.name },
|
||||
proc { |payments| payments.sum { |payment| payment.amount } } ]
|
||||
|
||||
rules = [ { group_by: proc { |payment| payment.order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |payment| payment.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } },
|
||||
{ group_by: proc { |payment| payment.payment_method },
|
||||
sort_by: proc { |method| method.name } } ]
|
||||
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
|
||||
@header = header
|
||||
@table = order_grouper.table(table_items)
|
||||
csv_file_name = "payments.csv"
|
||||
|
||||
render_report(@header, @table, params[:csv], csv_file_name)
|
||||
|
||||
end
|
||||
|
||||
def order_cycles
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "created_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
line_items = orders.map { |o| o.line_items }.flatten
|
||||
#payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
|
||||
|
||||
@distributors = Distributor.all
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
when "order_cycle_supplier_totals"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Status", "Incoming Transport"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "status" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "order_cycle_supplier_totals_by_distributor"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "To Distributor", "Amount", "Cost per Unit", "Total Cost", "Shipping Method"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "shipping method" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text },
|
||||
summary_columns: [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } } ]
|
||||
|
||||
when "order_cycle_distributor_totals_by_supplier"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Distributor", "Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Total Shipping Cost", "Shipping Method"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "shipping method" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "total shipping cost" },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "order_cycle_customer_totals"
|
||||
table_items = line_items
|
||||
@include_blank = false
|
||||
|
||||
header = ["Customer", "Email", "Phone", "Product", "Variant", "Amount", "Total Cost", "Paid?", "Packed?", "Shipped?"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
proc { |line_items| line_items.first.order.email },
|
||||
proc { |line_items| line_items.first.order.bill_address.phone },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.order.user },
|
||||
sort_by: proc { |user| user.to_s },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
proc { |line_items| line_items.first.order.email },
|
||||
proc { |line_items| line_items.first.order.bill_address.phone },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "work out whether paid or not" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
else
|
||||
table_items = line_items
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Status", "Incoming Transport"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "status" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
|
||||
@header = header
|
||||
@table = order_grouper.table(table_items)
|
||||
csv_file_name = "order_cycles.csv"
|
||||
|
||||
render_report(@header, @table, params[:csv], csv_file_name)
|
||||
|
||||
end
|
||||
|
||||
def render_report (header, table, create_csv, csv_file_name)
|
||||
unless create_csv
|
||||
render :html => table
|
||||
else
|
||||
csv_string = CSV.generate do |csv|
|
||||
csv << header
|
||||
table.each { |row| csv << row }
|
||||
end
|
||||
send_data csv_string, :filename => csv_file_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class SuppliersController < ResourceController
|
||||
before_filter :load_data, :except => [:index]
|
||||
|
||||
private
|
||||
def load_data
|
||||
@countries = Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
module Spree
|
||||
class DistributorsController < BaseController
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
render :template => 'spree/products/index'
|
||||
end
|
||||
|
||||
def select
|
||||
distributor = Distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = distributor
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def deselect
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = nil
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::HomeController.class_eval do
|
||||
include Spree::DistributorsHelper
|
||||
include DistributorsHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :index => { :html => { :success => lambda {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
Spree::OrdersController.class_eval do
|
||||
before_filter :populate_order_distributor, :only => :populate
|
||||
after_filter :populate_variant_attributes, :only => :populate
|
||||
before_filter :populate_order_distributor, :only => :populate
|
||||
after_filter :populate_variant_attributes, :only => :populate
|
||||
|
||||
def populate_order_distributor
|
||||
@distributor = params[:distributor_id].present? ? Spree::Distributor.find(params[:distributor_id]) : nil
|
||||
@distributor = params[:distributor_id].present? ? Distributor.find(params[:distributor_id]) : nil
|
||||
|
||||
if populate_valid? @distributor
|
||||
order = current_order(true)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::ProductsController.class_eval do
|
||||
include Spree::DistributorsHelper
|
||||
include DistributorsHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :index => { :html => { :success => lambda {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
module Spree
|
||||
class SuppliersController < BaseController
|
||||
helper 'spree/products'
|
||||
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
render :template => 'spree/products/index'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::TaxonsController.class_eval do
|
||||
include Spree::DistributorsHelper
|
||||
include DistributorsHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :show => { :html => { :success => lambda {
|
||||
|
||||
15
app/controllers/suppliers_controller.rb
Normal file
15
app/controllers/suppliers_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class SuppliersController < BaseController
|
||||
def index
|
||||
@suppliers = Supplier.all
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@supplier = Supplier.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
end
|
||||
@@ -1,2 +1,18 @@
|
||||
module ApplicationHelper
|
||||
def home_page_cms_content
|
||||
if controller.controller_name == 'home' && controller.action_name == 'index'
|
||||
cms_page_content(:content, Cms::Page.find_by_full_path('/'))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Pass URL helper calls on to spree where applicable so that we don't need to use
|
||||
# spree.foo_path in any view rendered from non-spree-namespaced controllers.
|
||||
def method_missing(method, *args, &block)
|
||||
if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && spree.respond_to?(method)
|
||||
spree.send(method, *args)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
5
app/helpers/distributors_helper.rb
Normal file
5
app/helpers/distributors_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module DistributorsHelper
|
||||
def current_distributor
|
||||
@current_distributor ||= current_order(false).andand.distributor
|
||||
end
|
||||
end
|
||||
@@ -1,7 +0,0 @@
|
||||
module Spree
|
||||
module DistributorsHelper
|
||||
def current_distributor
|
||||
@current_distributor ||= current_order(false).andand.distributor
|
||||
end
|
||||
end
|
||||
end
|
||||
31
app/models/distributor.rb
Normal file
31
app/models/distributor.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class Distributor < ActiveRecord::Base
|
||||
belongs_to :pickup_address, :foreign_key => 'pickup_address_id', :class_name => 'Spree::Address'
|
||||
has_many :orders, :class_name => 'Spree::Order'
|
||||
|
||||
has_many :product_distributions, :dependent => :destroy
|
||||
has_many :products, :through => :product_distributions
|
||||
|
||||
accepts_nested_attributes_for :pickup_address
|
||||
|
||||
validates_presence_of :name, :pickup_address
|
||||
validates_associated :pickup_address
|
||||
|
||||
scope :by_name, order('name')
|
||||
scope :with_active_products_on_hand, lambda { joins(:products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(distributors.*)') }
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
def initialize_country
|
||||
self.pickup_address ||= Spree::Address.new
|
||||
self.pickup_address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) if self.pickup_address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
pickup_address.firstname = pickup_address.lastname = pickup_address.phone = 'unused' if pickup_address.present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
34
app/models/distributor_set.rb
Normal file
34
app/models/distributor_set.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# Tableless model to handle updating multiple distributors at once from a
|
||||
# single form. Used to update next_collection_at field for all distributors in
|
||||
# admin backend.
|
||||
class DistributorSet
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :distributors
|
||||
|
||||
def initialize(attributes={})
|
||||
@distributors = Distributor.all
|
||||
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def distributors_attributes=(attributes)
|
||||
attributes.each do |k, attributes|
|
||||
# attributes == {:id => 123, :next_collection_at => '...'}
|
||||
d = @distributors.detect { |d| d.id.to_s == attributes[:id].to_s }
|
||||
d.assign_attributes(attributes.except(:id))
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
distributors.all?(&:save)
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
9
app/models/product_distribution.rb
Normal file
9
app/models/product_distribution.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class ProductDistribution < ActiveRecord::Base
|
||||
belongs_to :product, :class_name => 'Spree::Product'
|
||||
belongs_to :distributor
|
||||
belongs_to :shipping_method, :class_name => 'Spree::ShippingMethod'
|
||||
|
||||
validates_presence_of :product_id, :on => :update
|
||||
validates_presence_of :distributor_id, :shipping_method_id
|
||||
validates_uniqueness_of :product_id, :scope => :distributor_id
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
module Spree
|
||||
class Distributor < ActiveRecord::Base
|
||||
self.table_name = 'distributors'
|
||||
belongs_to :pickup_address, :foreign_key => 'pickup_address_id', :class_name => 'Spree::Address'
|
||||
has_many :orders
|
||||
|
||||
has_many :product_distributions, :dependent => :destroy
|
||||
has_many :products, :through => :product_distributions
|
||||
|
||||
accepts_nested_attributes_for :pickup_address
|
||||
|
||||
validates_presence_of :name, :pickup_address
|
||||
validates_associated :pickup_address
|
||||
|
||||
scope :by_name, order('name')
|
||||
scope :with_active_products_on_hand, lambda { joins(:products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(distributors.*)') }
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
def initialize_country
|
||||
self.pickup_address ||= Address.new
|
||||
self.pickup_address.country = Country.find_by_id(Spree::Config[:default_country_id]) if self.pickup_address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
pickup_address.firstname = pickup_address.lastname = pickup_address.phone = 'unused' if pickup_address.present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
# Tableless model to handle updating multiple distributors at once from a
|
||||
# single form. Used to update next_collection_at field for all distributors in
|
||||
# admin backend.
|
||||
module Spree
|
||||
class DistributorSet
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :distributors
|
||||
|
||||
def initialize(attributes={})
|
||||
@distributors = Spree::Distributor.all
|
||||
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def distributors_attributes=(attributes)
|
||||
attributes.each do |k, attributes|
|
||||
# attributes == {:id => 123, :next_collection_at => '...'}
|
||||
d = @distributors.detect { |d| d.id.to_s == attributes[:id].to_s }
|
||||
d.assign_attributes(attributes.except(:id))
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
distributors.all?(&:save)
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,6 @@ Spree::LineItem.class_eval do
|
||||
|
||||
before_create :set_itemwise_shipping_method
|
||||
|
||||
|
||||
def itemwise_shipping_cost
|
||||
order = OpenStruct.new :line_items => [self]
|
||||
shipping_method.compute_amount(order)
|
||||
|
||||
@@ -6,7 +6,7 @@ Spree::Product.class_eval do
|
||||
|
||||
accepts_nested_attributes_for :product_distributions, :allow_destroy => true
|
||||
|
||||
attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy
|
||||
attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size
|
||||
|
||||
validates_presence_of :supplier
|
||||
|
||||
@@ -23,7 +23,7 @@ Spree::Product.class_eval do
|
||||
|
||||
# Build a product distribution for each distributor
|
||||
def build_product_distributions
|
||||
Spree::Distributor.all.each do |distributor|
|
||||
Distributor.all.each do |distributor|
|
||||
unless self.product_distributions.find_by_distributor_id distributor.id
|
||||
self.product_distributions.build(:distributor => distributor)
|
||||
end
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
module Spree
|
||||
class ProductDistribution < ActiveRecord::Base
|
||||
self.table_name = 'product_distributions'
|
||||
|
||||
belongs_to :product
|
||||
belongs_to :distributor
|
||||
belongs_to :shipping_method
|
||||
|
||||
validates_presence_of :product_id, :on => :update
|
||||
validates_presence_of :distributor_id, :shipping_method_id
|
||||
validates_uniqueness_of :product_id, :scope => :distributor_id
|
||||
end
|
||||
end
|
||||
@@ -1,28 +0,0 @@
|
||||
module Spree
|
||||
class Supplier < ActiveRecord::Base
|
||||
self.table_name = 'suppliers'
|
||||
has_many :products
|
||||
belongs_to :address
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
|
||||
validates_presence_of :name, :address
|
||||
validates_associated :address
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
def initialize_country
|
||||
self.address ||= Address.new
|
||||
self.address.country = Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
address.firstname = address.lastname = address.phone = 'unused' if address.present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
33
app/models/supplier.rb
Normal file
33
app/models/supplier.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class Supplier < ActiveRecord::Base
|
||||
has_many :products, :class_name => 'Spree::Product'
|
||||
belongs_to :address, :class_name => 'Spree::Address'
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
|
||||
validates_presence_of :name, :address
|
||||
validates_associated :address
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
def has_products_on_hand?
|
||||
self.products.where('count_on_hand > 0').present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def initialize_country
|
||||
self.address ||= Spree::Address.new
|
||||
self.address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
address.firstname = address.lastname = address.phone = 'unused' if address.present?
|
||||
end
|
||||
|
||||
end
|
||||
4
app/overrides/add_cms_admin_tab.rb
Normal file
4
app/overrides/add_cms_admin_tab.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
||||
:name => "cms_admin_tab",
|
||||
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
||||
:text => "<li><%= link_to('CMS Admin', main_app.cms_admin_path) %></li>")
|
||||
9
app/overrides/add_distributor_details_to_product.rb
Normal file
9
app/overrides/add_distributor_details_to_product.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_before => "[data-hook='cart_form']",
|
||||
:partial => "spree/products/distributor_details",
|
||||
:name => "product_distributor_details")
|
||||
|
||||
Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_after => "[data-hook='product_show']",
|
||||
:text => "<%= javascript_include_tag main_app.distributors_path(:format => :js) %>",
|
||||
:name => "product_distributor_details_js")
|
||||
4
app/overrides/add_feedback_script.rb
Normal file
4
app/overrides/add_feedback_script.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
|
||||
:insert_bottom => "[data-hook='inside_head']",
|
||||
:partial => "layouts/feedback_script",
|
||||
:name => "feedback_script")
|
||||
@@ -1,11 +1,11 @@
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
||||
:name => "distributors_admin_tabs",
|
||||
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
||||
:text => "<%= tab(:distributors, :url => spree.admin_distributors_path) %>",
|
||||
:text => "<%= tab(:distributors, :url => main_app.admin_distributors_path) %>",
|
||||
:disabled => false)
|
||||
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
||||
:name => "suppliers_admin_tabs",
|
||||
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
||||
:text => "<%= tab(:suppliers, :url => spree.admin_suppliers_path) %>",
|
||||
:disabled => false)
|
||||
:text => "<%= tab(:suppliers, :url => main_app.admin_suppliers_path) %>",
|
||||
:disabled => false)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
- content_for :head do
|
||||
= render 'shared/cms_elrte_head'
|
||||
|
||||
%table{"data-hook" => "distributors"}
|
||||
%tr{"data-hook" => "name"}
|
||||
%td Name:
|
||||
@@ -5,6 +8,9 @@
|
||||
%tr{"data-hook" => "description"}
|
||||
%td Description:
|
||||
%td= f.text_field :description
|
||||
%tr{'data-hook' => "long_description"}
|
||||
%td Extended Description:
|
||||
%td= f.text_area :long_description, :class => 'rich_text'
|
||||
%tr{"data-hook" => "contact"}
|
||||
%td Contact:
|
||||
%td= f.text_field :contact
|
||||
@@ -1,13 +1,13 @@
|
||||
<div class="toolbar" data-hook="toolbar">
|
||||
<ul class="actions">
|
||||
<li>
|
||||
<%= button_link_to "New Distributor", spree.new_admin_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
|
||||
<%= button_link_to "New Distributor", main_app.new_admin_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
|
||||
</li>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
<%= form_for @distributor_set, :url => bulk_update_admin_distributors_path do |f| %>
|
||||
<%= form_for @distributor_set, :url => main_app.bulk_update_admin_distributors_path do |f| %>
|
||||
<table class="index" id="listing_distributors">
|
||||
<thead>
|
||||
<tr data-hook="distributors_header">
|
||||
@@ -21,7 +21,7 @@
|
||||
<%= f.fields_for :distributors do |distributor_form| %>
|
||||
<% distributor = distributor_form.object %>
|
||||
<tr>
|
||||
<td><%= link_to distributor.name, spree.admin_distributor_path(distributor) %></td>
|
||||
<td><%= link_to distributor.name, main_app.admin_distributor_path(distributor) %></td>
|
||||
<td><%= distributor_form.text_field :next_collection_at %></td>
|
||||
<td><%= distributor.description %></td>
|
||||
<td data-hook="admin_users_index_row_actions">
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @distributor } %>
|
||||
|
||||
<%= form_for [:admin, @distributor] do |f| %>
|
||||
<%= form_for [main_app, :admin, @distributor] do |f| %>
|
||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||
<%= render :partial => 'spree/admin/shared/new_resource_links' %>
|
||||
<% end %>
|
||||
@@ -6,6 +6,9 @@
|
||||
%tr
|
||||
%th Description:
|
||||
%td= @distributor.description
|
||||
%tr
|
||||
%th Extended Description:
|
||||
%td= @distributor.long_description.andand.html_safe
|
||||
%tr
|
||||
%th Contact person:
|
||||
%td= @distributor.contact
|
||||
@@ -34,6 +37,6 @@
|
||||
%th URL:
|
||||
%td= @distributor.url
|
||||
%p
|
||||
= link_to :Edit, spree.edit_admin_distributor_path(@distributor), :class => 'edit_distributor'
|
||||
= link_to :Edit, main_app.edit_admin_distributor_path(@distributor), :class => 'edit_distributor'
|
||||
= t(:or)
|
||||
= link_to t(:back), spree.admin_distributors_path
|
||||
= link_to t(:back), main_app.admin_distributors_path
|
||||
@@ -1,3 +1,6 @@
|
||||
- content_for :head do
|
||||
= render 'shared/cms_elrte_head'
|
||||
|
||||
%table{'data-hook' => "suppliers"}
|
||||
%tr{'data-hook' => "name"}
|
||||
%td Name:
|
||||
@@ -5,6 +8,9 @@
|
||||
%tr{'data-hook' => "description"}
|
||||
%td Description:
|
||||
%td= f.text_field :description
|
||||
%tr{'data-hook' => "long_description"}
|
||||
%td Extended Description:
|
||||
%td= f.text_area :long_description, :class => 'rich_text'
|
||||
= f.fields_for :address do |address_form|
|
||||
= render 'spree/admin/shared/address_form', :f => address_form
|
||||
%tr{'data-hook' => "email"}
|
||||
@@ -1,6 +1,6 @@
|
||||
.toolbar{'data-hook' => "suppliers"}
|
||||
%ul.actions
|
||||
%li= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link'
|
||||
%li= button_link_to "New Supplier", main_app.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link'
|
||||
%br.clear
|
||||
%table#listing_suppliers.index
|
||||
%thead
|
||||
@@ -11,7 +11,7 @@
|
||||
%tbody
|
||||
- @suppliers.each do |supplier|
|
||||
%tr
|
||||
%td= link_to supplier.name, spree.admin_supplier_path(supplier)
|
||||
%td= link_to supplier.name, main_app.admin_supplier_path(supplier)
|
||||
%td= supplier.description
|
||||
%td{'data-hook' => "admin_supplier_index_row_actions"}
|
||||
= link_to_edit supplier, :class => 'edit'
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
|
||||
|
||||
= form_for [:admin, @supplier] do |f|
|
||||
= form_for [main_app, :admin, @supplier] do |f|
|
||||
= render :partial => 'form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/new_resource_links'
|
||||
@@ -6,6 +6,9 @@
|
||||
%tr
|
||||
%th Description:
|
||||
%td= @supplier.description
|
||||
%tr
|
||||
%th Extended Description:
|
||||
%td= @supplier.long_description.andand.html_safe
|
||||
%tr
|
||||
%th Address:
|
||||
%td= render 'spree/shared/address', :address => @supplier.address
|
||||
@@ -19,6 +22,6 @@
|
||||
%th Twitter:
|
||||
%td= @supplier.twitter
|
||||
%p
|
||||
= link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
|
||||
= link_to :Edit, main_app.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
|
||||
= t(:or)
|
||||
= link_to t(:back), spree.admin_suppliers_path
|
||||
= link_to t(:back), main_app.admin_suppliers_path
|
||||
23
app/views/distributors/_details.html.haml
Normal file
23
app/views/distributors/_details.html.haml
Normal file
@@ -0,0 +1,23 @@
|
||||
%h2= distributor.name
|
||||
%p
|
||||
%strong Address:
|
||||
%br/
|
||||
= render 'spree/shared/address', :address => distributor.pickup_address
|
||||
%p
|
||||
%strong Next collection time:
|
||||
%br/
|
||||
= distributor.next_collection_at
|
||||
%p
|
||||
%strong Regular collection times:
|
||||
%br/
|
||||
= distributor.pickup_times
|
||||
%p
|
||||
%strong Contact:
|
||||
%br/
|
||||
= distributor.contact
|
||||
%br/
|
||||
= "Phone: #{distributor.phone}"
|
||||
%br/
|
||||
= "Email: #{distributor.email}"
|
||||
%p= distributor.description
|
||||
%p= link_to distributor.url, distributor.url if distributor.url
|
||||
1
app/views/distributors/index.js.erb
Normal file
1
app/views/distributors/index.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
distributors = <%= @distributor_details.to_json.html_safe %>;
|
||||
7
app/views/distributors/show.html.haml
Normal file
7
app/views/distributors/show.html.haml
Normal file
@@ -0,0 +1,7 @@
|
||||
%h2= @distributor.name
|
||||
|
||||
.distributor-description= @distributor.long_description.andand.html_safe
|
||||
|
||||
%h3 Available Now
|
||||
|
||||
= render :template => 'spree/products/index'
|
||||
1
app/views/layouts/_cms_nav_spree.html.haml
Normal file
1
app/views/layouts/_cms_nav_spree.html.haml
Normal file
@@ -0,0 +1 @@
|
||||
%li= link_to 'Spree Admin', spree.admin_path
|
||||
8
app/views/layouts/_feedback_script.html
Normal file
8
app/views/layouts/_feedback_script.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<script type="text/javascript">
|
||||
var uvOptions = {};
|
||||
(function() {
|
||||
var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
|
||||
uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/mCbT1cbjQZkPELXOix9Ag.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
|
||||
})();
|
||||
</script>
|
||||
@@ -1,14 +1 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Openfoodweb</title>
|
||||
<%= stylesheet_link_tag "application" %>
|
||||
<%= javascript_include_tag "application" %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<%= render :file => 'spree/layouts/spree_application' %>
|
||||
|
||||
17
app/views/shared/_cms_elrte_head.html.haml
Normal file
17
app/views/shared/_cms_elrte_head.html.haml
Normal file
@@ -0,0 +1,17 @@
|
||||
-# Include all stylesheets except reset (which overrides Spree styles)
|
||||
-# See cms/app/views/layouts/cms_admin/_head.html.erb
|
||||
= stylesheet_link_tag 'comfortable_mexican_sofa/structure',
|
||||
'comfortable_mexican_sofa/typography',
|
||||
'comfortable_mexican_sofa/form',
|
||||
'comfortable_mexican_sofa/content',
|
||||
'comfortable_mexican_sofa/files',
|
||||
'comfortable_mexican_sofa/elrte',
|
||||
'comfortable_mexican_sofa/codemirror',
|
||||
'comfortable_mexican_sofa/jquery_ui',
|
||||
'comfortable_mexican_sofa/dialogs',
|
||||
'comfortable_mexican_sofa/widgets'
|
||||
|
||||
= javascript_include_tag('comfortable_mexican_sofa/application')
|
||||
|
||||
%meta{:name => "cms-admin-path", :content => ComfortableMexicanSofa.config.admin_route_prefix}
|
||||
%meta{:name => "cms-locale", :content => I18n.locale}
|
||||
@@ -5,3 +5,8 @@
|
||||
= f.label :group_buy_1, 'Yes'
|
||||
= f.radio_button :group_buy, '0', :checked => !f.object.group_buy
|
||||
= f.label :group_buy_0, 'No'
|
||||
|
||||
= f.field_container :group_buy_unit_size do
|
||||
= f.label :group_buy_unit_size
|
||||
%br
|
||||
= f.text_field :group_buy_unit_size
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
%br
|
||||
= f.collection_select(:supplier_id, Spree::Supplier.all, :id, :name, :include_blank => true)
|
||||
= f.error_message_on :supplier
|
||||
= f.collection_select(:supplier_id, Supplier.all, :id, :name, :include_blank => true)
|
||||
= f.error_message_on :supplier
|
||||
|
||||
39
app/views/spree/admin/reports/bulk_coop.html.haml
Normal file
39
app/views/spree/admin/reports/bulk_coop.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
= form_for @search, :url => spree.bulk_coop_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :created_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :created_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => 'All')
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select([['Bulk Co-op - Totals by Supplier',:bulk_coop_supplier_report],['Bulk Co-op - Allocation',:bulk_coop_allocation],['Bulk Co-op - Packing Sheets',:bulk_coop_packing_sheets],['Bulk Co-op - Customer Payments',:bulk_coop_customer_payments]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
37
app/views/spree/admin/reports/group_buys.html.haml
Normal file
37
app/views/spree/admin/reports/group_buys.html.haml
Normal file
@@ -0,0 +1,37 @@
|
||||
= form_for @search, :url => spree.group_buys_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :created_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :created_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name)
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @report.header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @report.table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @report.table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
|
||||
39
app/views/spree/admin/reports/order_cycles.html.haml
Normal file
39
app/views/spree/admin/reports/order_cycles.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
= form_for @search, :url => spree.order_cycles_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :created_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :created_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => @include_blank)
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select([['Order Cycle Supplier Totals',:order_cycle_supplier_totals], ['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor], ['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier], ['Order Cycle Customer Totals',:order_cycle_customer_totals]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
39
app/views/spree/admin/reports/payments.html.haml
Normal file
39
app/views/spree/admin/reports/payments.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
= form_for @search, :url => spree.payments_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :created_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :created_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => 'All')
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select([['Payments By Type',:payments_by_payment_type],['Itemised Payment Totals',:itemised_payment_totals],['Payment Totals',:payment_totals]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
@@ -1,27 +1,4 @@
|
||||
.columns.omega.six
|
||||
%fieldset#shipping
|
||||
%legend Distributor
|
||||
%h2= @order.distributor.name
|
||||
%p
|
||||
%strong Address:
|
||||
%br/
|
||||
= render 'spree/shared/address', :address => @order.distributor.pickup_address
|
||||
%p
|
||||
%strong Next collection time:
|
||||
%br/
|
||||
= @order.distributor.next_collection_at
|
||||
%p
|
||||
%strong Regular collection times:
|
||||
%br/
|
||||
= @order.distributor.pickup_times
|
||||
%p
|
||||
%strong Contact:
|
||||
%br/
|
||||
= @order.distributor.contact
|
||||
%br/
|
||||
= "Phone: #{@order.distributor.phone}"
|
||||
%br/
|
||||
= "Email: #{@order.distributor.email}"
|
||||
%p= @order.distributor.description
|
||||
%p= link_to @order.distributor.url, @order.distributor.url if @order.distributor.url
|
||||
|
||||
= render 'distributors/details', :distributor => @order.distributor
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
- order = current_order(false)
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
%p Distributor
|
||||
= select_tag "distributor_id", options_from_collection_for_select([Spree::Distributor.new]+@product.distributors, "id", "name", current_distributor.andand.id)
|
||||
= select_tag "distributor_id", options_from_collection_for_select([Distributor.new]+@product.distributors, "id", "name", current_distributor.andand.id)
|
||||
- else
|
||||
= hidden_field_tag "distributor_id", order.distributor.id
|
||||
.distributor-fixed= "Your distributor for this order is #{order.distributor.name}"
|
||||
|
||||
8
app/views/spree/products/_distributor_details.html.haml
Normal file
8
app/views/spree/products/_distributor_details.html.haml
Normal file
@@ -0,0 +1,8 @@
|
||||
%fieldset#product-distributor-details.columns.five.omega
|
||||
%legend Distributor
|
||||
.distributor-details
|
||||
- order = current_order(false)
|
||||
- if order.andand.distributor.present?
|
||||
= render 'distributors/details', :distributor => order.distributor
|
||||
- else
|
||||
When you select a distributor for your order, their address and pickup times will be displayed here.
|
||||
@@ -2,7 +2,9 @@
|
||||
%h6.filter_name Shop by Supplier
|
||||
%ul.filter_choices
|
||||
- @suppliers.each do |supplier|
|
||||
%li.nowrap= link_to supplier.name, supplier
|
||||
- if supplier.has_products_on_hand?
|
||||
%li.nowrap= link_to supplier.name, [main_app, supplier]
|
||||
= button_to 'Browse All Suppliers', main_app.suppliers_path, :method => :get
|
||||
|
||||
%h6.filter_name Shop by Distributor
|
||||
%ul.filter_choices
|
||||
@@ -10,10 +12,10 @@
|
||||
- @distributors.each do |distributor|
|
||||
%li.nowrap
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
= link_to distributor.name, select_distributor_path(distributor)
|
||||
= link_to distributor.name, main_app.select_distributor_path(distributor)
|
||||
- elsif order.distributor == distributor
|
||||
= link_to distributor.name, root_path
|
||||
= link_to distributor.name, [main_app, distributor]
|
||||
- else
|
||||
%span.inactive= distributor.name
|
||||
- if current_distributor && order.can_change_distributor?
|
||||
= button_to 'Browse All Distributors', deselect_distributors_path, :method => :get
|
||||
= button_to 'Browse All Distributors', main_app.deselect_distributors_path, :method => :get
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
= home_page_cms_content
|
||||
|
||||
- if @products
|
||||
#products= render 'spree/shared/products', :products => @products, :taxon => @taxon
|
||||
- else
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
%li#home-link{'data-hook' => ''}
|
||||
= link_to t(:home), root_path
|
||||
|
||||
- if @cms_site
|
||||
- @cms_site.pages.root.children.published.each do |page|
|
||||
%li= link_to page.label, page.full_path
|
||||
|
||||
%li#link-to-cart{'data-hook' => ''}
|
||||
= link_to_cart
|
||||
|
||||
|
||||
12
app/views/suppliers/index.html.haml
Normal file
12
app/views/suppliers/index.html.haml
Normal file
@@ -0,0 +1,12 @@
|
||||
- content_for :sidebar do
|
||||
%div{'data-hook' => "homepage_sidebar_navigation"}
|
||||
= render 'spree/sidebar'
|
||||
|
||||
|
||||
%h1 Suppliers
|
||||
|
||||
= cms_page_content(:content, Cms::Page.find_by_full_path('/suppliers'))
|
||||
|
||||
%ul.suppliers
|
||||
- @suppliers.each do |supplier|
|
||||
%li= link_to supplier.name, supplier
|
||||
7
app/views/suppliers/show.html.haml
Normal file
7
app/views/suppliers/show.html.haml
Normal file
@@ -0,0 +1,7 @@
|
||||
%h2= @supplier.name
|
||||
|
||||
.supplier-description= @supplier.long_description.andand.html_safe
|
||||
|
||||
%h3 Available Now
|
||||
|
||||
= render :template => 'spree/products/index'
|
||||
@@ -66,6 +66,6 @@ module Openfoodweb
|
||||
config.assets.version = '1.0'
|
||||
|
||||
config.assets.initialize_on_precompile = false
|
||||
config.assets.precompile += ['store/all.css', 'store/all.js', 'admin/all.css', 'admin/*.js', 'admin/**/*.js']
|
||||
config.assets.precompile += ['store/all.css', 'store/all.js', 'admin/all.css', 'admin/*.js', 'admin/**/*.js', 'comfortable_mexican_sofa/*']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,3 +28,8 @@ Openfoodweb::Application.configure do
|
||||
# Expands the lines which load the assets
|
||||
config.assets.debug = true
|
||||
end
|
||||
|
||||
|
||||
# Load heroku vars from local file
|
||||
heroku_env = File.join(Rails.root, 'config', 'heroku_env.rb')
|
||||
load(heroku_env) if File.exists?(heroku_env)
|
||||
|
||||
134
config/initializers/comfortable_mexican_sofa.rb
Normal file
134
config/initializers/comfortable_mexican_sofa.rb
Normal file
@@ -0,0 +1,134 @@
|
||||
# encoding: utf-8
|
||||
|
||||
ComfortableMexicanSofa.configure do |config|
|
||||
# Title of the admin area
|
||||
# config.cms_title = 'ComfortableMexicanSofa CMS Engine'
|
||||
|
||||
# Module responsible for authentication. You can replace it with your own.
|
||||
# It simply needs to have #authenticate method. See http_auth.rb for reference.
|
||||
config.admin_auth = 'CmsSpreeAuth'
|
||||
|
||||
# Module responsible for public authentication. Similar to the above. You also
|
||||
# will have access to @cms_site, @cms_layout, @cms_page so you can use them in
|
||||
# your logic. Default module doesn't do anything.
|
||||
# config.public_auth = 'ComfortableMexicanSofa::DummyAuth'
|
||||
|
||||
# Default url to access admin area is http://yourhost/cms-admin/
|
||||
# You can change 'cms-admin' to 'admin', for example. To disable admin area
|
||||
# entirely set this to '' or nil
|
||||
# config.admin_route_prefix = 'cms-admin'
|
||||
|
||||
# When arriving at /cms-admin you may chose to redirect to arbirtary path,
|
||||
# for example '/cms-admin/users'
|
||||
# config.admin_route_redirect = ''
|
||||
|
||||
# Normally we include default routes from https://github.com/comfy/comfortable-mexican-sofa/blob/master/config/routes.rb
|
||||
# If you want to include the routes manually set this to false
|
||||
# config.use_default_routes = true
|
||||
|
||||
# /sitemap.xml that is used by search engines for indexing. It's enabled by
|
||||
# default, but you may turn it off.
|
||||
# config.enable_sitemap = true
|
||||
|
||||
# File uploads use Paperclip and can support filesystem or s3 uploads. Override
|
||||
# the upload method and appropriate settings based on Paperclip. For S3 see:
|
||||
# http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3, and for
|
||||
# filesystem see: http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/Filesystem
|
||||
config.upload_file_options = {
|
||||
:storage => 's3',
|
||||
:s3_credentials => {
|
||||
:bucket => ENV['S3_BUCKET'],
|
||||
:access_key_id => ENV['S3_KEY'],
|
||||
:secret_access_key => ENV['S3_SECRET']
|
||||
}
|
||||
}
|
||||
|
||||
# Sofa allows you to setup entire site from files. Database is updated with each
|
||||
# request (if necessary). Please note that database entries are destroyed if there's
|
||||
# no corresponding file. Fixtures are disabled by default.
|
||||
# config.enable_fixtures = false
|
||||
|
||||
# Path where fixtures can be located.
|
||||
# config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
|
||||
|
||||
# Importing fixtures into Database
|
||||
# To load fixtures into the database just run this rake task:
|
||||
# local: $ rake comfortable_mexican_sofa:fixtures:import FROM=example.local TO=localhost
|
||||
# Heroku: $ heroku run rake comfortable_mexican_sofa:fixtures:import FROM=example.local TO=yourapp.herokuapp.com
|
||||
# From indicates folder the fixtures are in and to is the Site hostname you have defined in the database.
|
||||
|
||||
# Exporting fixtures into Files
|
||||
# If you need to dump database contents into fixture files run:
|
||||
# local: $ rake comfortable_mexican_sofa:fixtures:export FROM=localhost TO=example.local
|
||||
# Heroku: $ heroku run rake comfortable_mexican_sofa:fixtures:export FROM=yourapp.herokuapp.com TO=example.local
|
||||
# This will create example.local folder and dump all content from example.com Site.
|
||||
|
||||
# Content for Layouts, Pages and Snippets has a revision history. You can revert
|
||||
# a previous version using this system. You can control how many revisions per
|
||||
# object you want to keep. Set it to 0 if you wish to turn this feature off.
|
||||
# config.revisions_limit = 25
|
||||
|
||||
# Locale definitions. If you want to define your own locale merge
|
||||
# {:locale => 'Locale Title'} with this.
|
||||
# config.locales = {:en => 'English', :es => 'Español'}
|
||||
|
||||
# Admin interface will respect the locale of the site being managed. However you can
|
||||
# force it to English by setting this to `:en`
|
||||
# config.admin_locale = nil
|
||||
|
||||
# If you want to keep your CMS tables in a location other than the default database
|
||||
# add a database_config. For example, setting it to 'cms' will look for a cms_#{Rails.env}
|
||||
# definition in your database.yml file
|
||||
# config.database_config = nil
|
||||
|
||||
# A class that is included as a sweeper to admin base controller if it's set
|
||||
# config.admin_cache_sweeper = nil
|
||||
|
||||
# By default you cannot have irb code inside your layouts/pages/snippets.
|
||||
# Generally this is to prevent putting something like this:
|
||||
# <% User.delete_all %> but if you really want to allow it...
|
||||
# config.allow_irb = false
|
||||
|
||||
# Whitelist of all helper methods that can be used via {{cms:helper}} tag. By default
|
||||
# all helpers are allowed except `eval`, `send`, `call` and few others. Empty array
|
||||
# will prevent rendering of all helpers.
|
||||
# config.allowed_helpers = nil
|
||||
|
||||
# Whitelist of partials paths that can be used via {{cms:partial}} tag. All partials
|
||||
# are accessible by default. Empty array will prevent rendering of all partials.
|
||||
# config.allowed_partials = nil
|
||||
|
||||
# Site aliases, if you want to have aliases for your site. Good for harmonizing
|
||||
# production env with dev/testing envs.
|
||||
# e.g. config.site_aliases = {'host.com' => 'host.inv', 'host_a.com' => ['host.lvh.me', 'host.dev']}
|
||||
# Default is nil (not used)
|
||||
# config.hostname_aliases = nil
|
||||
|
||||
end
|
||||
|
||||
module CmsSpreeAuth
|
||||
def authenticate
|
||||
unless current_user && current_user.has_role?('admin')
|
||||
redirect_to spree.login_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Default credentials for ComfortableMexicanSofa::HttpAuth
|
||||
# YOU REALLY WANT TO CHANGE THIS BEFORE PUTTING YOUR SITE LIVE
|
||||
ComfortableMexicanSofa::HttpAuth.username = 'username'
|
||||
ComfortableMexicanSofa::HttpAuth.password = 'password'
|
||||
|
||||
# If you need to inject some html in cms admin views you can define what partial
|
||||
# should be rendered into the following areas:
|
||||
# ComfortableMexicanSofa::ViewHooks.add(:navigation, '/layouts/admin/navigation')
|
||||
# ComfortableMexicanSofa::ViewHooks.add(:html_head, '/layouts/admin/html_head')
|
||||
# ComfortableMexicanSofa::ViewHooks.add(:page_form, '/layouts/admin/page_form')
|
||||
ComfortableMexicanSofa::ViewHooks.add(:navigation, 'layouts/cms_nav_spree')
|
||||
|
||||
# Provide some Spree helpers to the CMS controller so it can render Spree's layout
|
||||
ComfortableMexicanSofa::CmsContentController.class_eval do
|
||||
helper 'spree/base'
|
||||
include Spree::Core::ControllerHelpers
|
||||
include Spree::Core::Engine.routes.url_helpers
|
||||
end
|
||||
@@ -1,10 +1,6 @@
|
||||
Openfoodweb::Application.routes.draw do
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
end
|
||||
root :to => 'spree/home#index'
|
||||
|
||||
|
||||
Spree::Core::Engine.routes.prepend do
|
||||
resources :suppliers
|
||||
resources :distributors do
|
||||
get :select, :on => :member
|
||||
@@ -18,5 +14,15 @@ Spree::Core::Engine.routes.prepend do
|
||||
resources :suppliers
|
||||
end
|
||||
|
||||
match '/admin/reports/orders_and_distributors' => 'admin/reports#orders_and_distributors', :as => "orders_and_distributors_admin_reports", :via => [:get, :post]
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
end
|
||||
|
||||
|
||||
Spree::Core::Engine.routes.prepend do
|
||||
match '/admin/reports/orders_and_distributors' => 'admin/reports#orders_and_distributors', :as => "orders_and_distributors_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/group_buys' => 'admin/reports#group_buys', :as => "group_buys_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/bulk_coop' => 'admin/reports#bulk_coop', :as => "bulk_coop_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/payments' => 'admin/reports#payments', :as => "payments_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/order_cycles' => 'admin/reports#order_cycles', :as => "order_cycles_admin_reports", :via => [:get, :post]
|
||||
end
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
developement:
|
||||
bucket: openfoodweb_test
|
||||
access_key_id: AKIAJ3EE2EKGP36D4PUA
|
||||
secret_access_key: GUvfWLC5G5bpcjqRYOa9/IyxofIPjKQjgJonJuTW
|
||||
production:
|
||||
bucket: openfoodweb_production
|
||||
access_key_id: AKIAJ3EE2EKGP36D4PUA
|
||||
secret_access_key: GUvfWLC5G5bpcjqRYOa9/IyxofIPjKQjgJonJuTW
|
||||
1
db/cms_fixtures/example.com/layouts/default/_default.yml
Normal file
1
db/cms_fixtures/example.com/layouts/default/_default.yml
Normal file
@@ -0,0 +1 @@
|
||||
label: Default Fixture Layout
|
||||
5
db/cms_fixtures/example.com/layouts/default/content.html
Normal file
5
db/cms_fixtures/example.com/layouts/default/content.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
{{ cms:page:content }}
|
||||
</body>
|
||||
</html>
|
||||
1
db/cms_fixtures/example.com/layouts/default/css.css
Normal file
1
db/cms_fixtures/example.com/layouts/default/css.css
Normal file
@@ -0,0 +1 @@
|
||||
body{color: red}
|
||||
1
db/cms_fixtures/example.com/layouts/default/js.js
Normal file
1
db/cms_fixtures/example.com/layouts/default/js.js
Normal file
@@ -0,0 +1 @@
|
||||
// default js
|
||||
@@ -0,0 +1,2 @@
|
||||
label: Default Fixture Nested Layout
|
||||
position: 42
|
||||
@@ -0,0 +1,2 @@
|
||||
<div class='left'> {{ cms:page:left }} </div>
|
||||
<div class='right'> {{ cms:page:right }} </div>
|
||||
@@ -0,0 +1 @@
|
||||
div{float:left}
|
||||
1
db/cms_fixtures/example.com/layouts/default/nested/js.js
Normal file
1
db/cms_fixtures/example.com/layouts/default/nested/js.js
Normal file
@@ -0,0 +1 @@
|
||||
// nested js
|
||||
2
db/cms_fixtures/example.com/pages/index/_index.yml
Normal file
2
db/cms_fixtures/example.com/pages/index/_index.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
label: Home Fixture Page
|
||||
layout: default
|
||||
3
db/cms_fixtures/example.com/pages/index/child/_child.yml
Normal file
3
db/cms_fixtures/example.com/pages/index/child/_child.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
label: Child Fixture Page
|
||||
layout: nested
|
||||
position: 42
|
||||
1
db/cms_fixtures/example.com/pages/index/child/left.html
Normal file
1
db/cms_fixtures/example.com/pages/index/child/left.html
Normal file
@@ -0,0 +1 @@
|
||||
Child Page Left Fixture Content
|
||||
1
db/cms_fixtures/example.com/pages/index/child/right.html
Normal file
1
db/cms_fixtures/example.com/pages/index/child/right.html
Normal file
@@ -0,0 +1 @@
|
||||
Child Page Right Fixture Content
|
||||
2
db/cms_fixtures/example.com/pages/index/content.html
Normal file
2
db/cms_fixtures/example.com/pages/index/content.html
Normal file
@@ -0,0 +1,2 @@
|
||||
Home Page Fixture Contént
|
||||
{{ cms:snippet:default }}
|
||||
@@ -0,0 +1 @@
|
||||
label: Default Fixture Snippet
|
||||
@@ -0,0 +1 @@
|
||||
Fixture Content for Default Snippet
|
||||
@@ -8,7 +8,7 @@ class MoveDistributorFromOrderToProduct < ActiveRecord::Migration
|
||||
end
|
||||
|
||||
# Associate all products with the first distributor
|
||||
distributor = Spree::Distributor.first
|
||||
distributor = Distributor.first
|
||||
if distributor
|
||||
Spree::Product.all.each do |product|
|
||||
product.distributors << distributor
|
||||
|
||||
@@ -2,9 +2,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
def up
|
||||
# -- Distributors
|
||||
add_column :distributors, :pickup_address_id, :integer
|
||||
Spree::Distributor.reset_column_information
|
||||
Distributor.reset_column_information
|
||||
|
||||
Spree::Distributor.all.each do |distributor|
|
||||
Distributor.all.each do |distributor|
|
||||
pickup_address = Spree::Address.create!(:firstname => 'unused',
|
||||
:lastname => 'unused',
|
||||
:phone => 'unused',
|
||||
@@ -24,9 +24,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
|
||||
# -- Suppliers
|
||||
add_column :suppliers, :address_id, :integer
|
||||
Spree::Supplier.reset_column_information
|
||||
Supplier.reset_column_information
|
||||
|
||||
Spree::Supplier.all.each do |supplier|
|
||||
Supplier.all.each do |supplier|
|
||||
address = Spree::Address.create!(:firstname => 'unused',
|
||||
:lastname => 'unused',
|
||||
:phone => 'unused',
|
||||
@@ -51,9 +51,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
add_column :distributors, :post_code, :string
|
||||
add_column :distributors, :state_id, :integer
|
||||
add_column :distributors, :country_id, :integer
|
||||
Spree::Distributor.reset_column_information
|
||||
Distributor.reset_column_information
|
||||
|
||||
Spree::Distributor.all.each do |distributor|
|
||||
Distributor.all.each do |distributor|
|
||||
distributor[:pickup_address] = distributor.pickup_address.address1
|
||||
distributor.city = distributor.pickup_address.city
|
||||
distributor.post_code = distributor.pickup_address.zipcode
|
||||
@@ -71,9 +71,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
add_column :suppliers, :postcode, :string
|
||||
add_column :suppliers, :state_id, :integer
|
||||
add_column :suppliers, :country_id, :integer
|
||||
Spree::Supplier.reset_column_information
|
||||
Supplier.reset_column_information
|
||||
|
||||
Spree::Supplier.all.each do |supplier|
|
||||
Supplier.all.each do |supplier|
|
||||
supplier[:address] = supplier.address.address1
|
||||
supplier.city = supplier.address.city
|
||||
supplier.post_code = supplier.address.zipcode
|
||||
|
||||
@@ -10,7 +10,7 @@ class RenameDistributorsProductsToProductDistributions < ActiveRecord::Migration
|
||||
|
||||
# Set default shipping method on all product distributions
|
||||
sm = Spree::ShippingMethod.first
|
||||
Spree::ProductDistribution.update_all(:shipping_method_id => sm.id) if sm
|
||||
ProductDistribution.update_all(:shipping_method_id => sm.id) if sm
|
||||
end
|
||||
|
||||
def down
|
||||
|
||||
137
db/migrate/20121009232513_create_cms.rb
Normal file
137
db/migrate/20121009232513_create_cms.rb
Normal file
@@ -0,0 +1,137 @@
|
||||
class CreateCms < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
|
||||
text_limit = case ActiveRecord::Base.connection.adapter_name
|
||||
when 'PostgreSQL'
|
||||
{ }
|
||||
else
|
||||
{ :limit => 16777215 }
|
||||
end
|
||||
|
||||
# -- Sites --------------------------------------------------------------
|
||||
create_table :cms_sites do |t|
|
||||
t.string :label, :null => false
|
||||
t.string :identifier, :null => false
|
||||
t.string :hostname, :null => false
|
||||
t.string :path
|
||||
t.string :locale, :null => false, :default => 'en'
|
||||
t.boolean :is_mirrored, :null => false, :default => false
|
||||
end
|
||||
add_index :cms_sites, :hostname
|
||||
add_index :cms_sites, :is_mirrored
|
||||
|
||||
# -- Layouts ------------------------------------------------------------
|
||||
create_table :cms_layouts do |t|
|
||||
t.integer :site_id, :null => false
|
||||
t.integer :parent_id
|
||||
t.string :app_layout
|
||||
t.string :label, :null => false
|
||||
t.string :identifier, :null => false
|
||||
t.text :content, text_limit
|
||||
t.text :css, text_limit
|
||||
t.text :js, text_limit
|
||||
t.integer :position, :null => false, :default => 0
|
||||
t.boolean :is_shared, :null => false, :default => false
|
||||
t.timestamps
|
||||
end
|
||||
add_index :cms_layouts, [:parent_id, :position]
|
||||
add_index :cms_layouts, [:site_id, :identifier], :unique => true
|
||||
|
||||
# -- Pages --------------------------------------------------------------
|
||||
create_table :cms_pages do |t|
|
||||
t.integer :site_id, :null => false
|
||||
t.integer :layout_id
|
||||
t.integer :parent_id
|
||||
t.integer :target_page_id
|
||||
t.string :label, :null => false
|
||||
t.string :slug
|
||||
t.string :full_path, :null => false
|
||||
t.text :content, text_limit
|
||||
t.integer :position, :null => false, :default => 0
|
||||
t.integer :children_count, :null => false, :default => 0
|
||||
t.boolean :is_published, :null => false, :default => true
|
||||
t.boolean :is_shared, :null => false, :default => false
|
||||
t.timestamps
|
||||
end
|
||||
add_index :cms_pages, [:site_id, :full_path]
|
||||
add_index :cms_pages, [:parent_id, :position]
|
||||
|
||||
# -- Page Blocks --------------------------------------------------------
|
||||
create_table :cms_blocks do |t|
|
||||
t.integer :page_id, :null => false
|
||||
t.string :identifier, :null => false
|
||||
t.text :content
|
||||
t.timestamps
|
||||
end
|
||||
add_index :cms_blocks, [:page_id, :identifier]
|
||||
|
||||
# -- Snippets -----------------------------------------------------------
|
||||
create_table :cms_snippets do |t|
|
||||
t.integer :site_id, :null => false
|
||||
t.string :label, :null => false
|
||||
t.string :identifier, :null => false
|
||||
t.text :content, text_limit
|
||||
t.integer :position, :null => false, :default => 0
|
||||
t.boolean :is_shared, :null => false, :default => false
|
||||
t.timestamps
|
||||
end
|
||||
add_index :cms_snippets, [:site_id, :identifier], :unique => true
|
||||
add_index :cms_snippets, [:site_id, :position]
|
||||
|
||||
# -- Files --------------------------------------------------------------
|
||||
create_table :cms_files do |t|
|
||||
t.integer :site_id, :null => false
|
||||
t.integer :block_id
|
||||
t.string :label, :null => false
|
||||
t.string :file_file_name, :null => false
|
||||
t.string :file_content_type, :null => false
|
||||
t.integer :file_file_size, :null => false
|
||||
t.string :description, :limit => 2048
|
||||
t.integer :position, :null => false, :default => 0
|
||||
t.timestamps
|
||||
end
|
||||
add_index :cms_files, [:site_id, :label]
|
||||
add_index :cms_files, [:site_id, :file_file_name]
|
||||
add_index :cms_files, [:site_id, :position]
|
||||
add_index :cms_files, [:site_id, :block_id]
|
||||
|
||||
# -- Revisions -----------------------------------------------------------
|
||||
create_table :cms_revisions, :force => true do |t|
|
||||
t.string :record_type, :null => false
|
||||
t.integer :record_id, :null => false
|
||||
t.text :data, text_limit
|
||||
t.datetime :created_at
|
||||
end
|
||||
add_index :cms_revisions, [:record_type, :record_id, :created_at]
|
||||
|
||||
# -- Categories ---------------------------------------------------------
|
||||
create_table :cms_categories, :force => true do |t|
|
||||
t.integer :site_id, :null => false
|
||||
t.string :label, :null => false
|
||||
t.string :categorized_type, :null => false
|
||||
end
|
||||
add_index :cms_categories, [:site_id, :categorized_type, :label], :unique => true
|
||||
|
||||
create_table :cms_categorizations, :force => true do |t|
|
||||
t.integer :category_id, :null => false
|
||||
t.string :categorized_type, :null => false
|
||||
t.integer :categorized_id, :null => false
|
||||
end
|
||||
add_index :cms_categorizations, [:category_id, :categorized_type, :categorized_id], :unique => true,
|
||||
:name => 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id'
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :cms_sites
|
||||
drop_table :cms_layouts
|
||||
drop_table :cms_pages
|
||||
drop_table :cms_snippets
|
||||
drop_table :cms_blocks
|
||||
drop_table :cms_files
|
||||
drop_table :cms_revisions
|
||||
drop_table :cms_categories
|
||||
drop_table :cms_categorizations
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddLongDescriptionToDistributorsAndSuppliers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :distributors, :long_description, :text
|
||||
add_column :suppliers, :long_description, :text
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddGroupBuyUnitSizeToProducts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spree_products, :group_buy_unit_size, :string
|
||||
end
|
||||
end
|
||||
280
db/schema.rb
280
db/schema.rb
@@ -11,7 +11,124 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
|
||||
create_table "cms_blocks", :force => true do |t|
|
||||
t.integer "page_id", :null => false
|
||||
t.string "identifier", :null => false
|
||||
t.text "content"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_blocks", ["page_id", "identifier"], :name => "index_cms_blocks_on_page_id_and_identifier"
|
||||
|
||||
create_table "cms_categories", :force => true do |t|
|
||||
t.integer "site_id", :null => false
|
||||
t.string "label", :null => false
|
||||
t.string "categorized_type", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_categories", ["site_id", "categorized_type", "label"], :name => "index_cms_categories_on_site_id_and_categorized_type_and_label", :unique => true
|
||||
|
||||
create_table "cms_categorizations", :force => true do |t|
|
||||
t.integer "category_id", :null => false
|
||||
t.string "categorized_type", :null => false
|
||||
t.integer "categorized_id", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_categorizations", ["category_id", "categorized_type", "categorized_id"], :name => "index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id", :unique => true
|
||||
|
||||
create_table "cms_files", :force => true do |t|
|
||||
t.integer "site_id", :null => false
|
||||
t.integer "block_id"
|
||||
t.string "label", :null => false
|
||||
t.string "file_file_name", :null => false
|
||||
t.string "file_content_type", :null => false
|
||||
t.integer "file_file_size", :null => false
|
||||
t.string "description", :limit => 2048
|
||||
t.integer "position", :default => 0, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_files", ["site_id", "block_id"], :name => "index_cms_files_on_site_id_and_block_id"
|
||||
add_index "cms_files", ["site_id", "file_file_name"], :name => "index_cms_files_on_site_id_and_file_file_name"
|
||||
add_index "cms_files", ["site_id", "label"], :name => "index_cms_files_on_site_id_and_label"
|
||||
add_index "cms_files", ["site_id", "position"], :name => "index_cms_files_on_site_id_and_position"
|
||||
|
||||
create_table "cms_layouts", :force => true do |t|
|
||||
t.integer "site_id", :null => false
|
||||
t.integer "parent_id"
|
||||
t.string "app_layout"
|
||||
t.string "label", :null => false
|
||||
t.string "identifier", :null => false
|
||||
t.text "content"
|
||||
t.text "css"
|
||||
t.text "js"
|
||||
t.integer "position", :default => 0, :null => false
|
||||
t.boolean "is_shared", :default => false, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_layouts", ["parent_id", "position"], :name => "index_cms_layouts_on_parent_id_and_position"
|
||||
add_index "cms_layouts", ["site_id", "identifier"], :name => "index_cms_layouts_on_site_id_and_identifier", :unique => true
|
||||
|
||||
create_table "cms_pages", :force => true do |t|
|
||||
t.integer "site_id", :null => false
|
||||
t.integer "layout_id"
|
||||
t.integer "parent_id"
|
||||
t.integer "target_page_id"
|
||||
t.string "label", :null => false
|
||||
t.string "slug"
|
||||
t.string "full_path", :null => false
|
||||
t.text "content"
|
||||
t.integer "position", :default => 0, :null => false
|
||||
t.integer "children_count", :default => 0, :null => false
|
||||
t.boolean "is_published", :default => true, :null => false
|
||||
t.boolean "is_shared", :default => false, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_pages", ["parent_id", "position"], :name => "index_cms_pages_on_parent_id_and_position"
|
||||
add_index "cms_pages", ["site_id", "full_path"], :name => "index_cms_pages_on_site_id_and_full_path"
|
||||
|
||||
create_table "cms_revisions", :force => true do |t|
|
||||
t.string "record_type", :null => false
|
||||
t.integer "record_id", :null => false
|
||||
t.text "data"
|
||||
t.datetime "created_at"
|
||||
end
|
||||
|
||||
add_index "cms_revisions", ["record_type", "record_id", "created_at"], :name => "index_cms_revisions_on_record_type_and_record_id_and_created_at"
|
||||
|
||||
create_table "cms_sites", :force => true do |t|
|
||||
t.string "label", :null => false
|
||||
t.string "identifier", :null => false
|
||||
t.string "hostname", :null => false
|
||||
t.string "path"
|
||||
t.string "locale", :default => "en", :null => false
|
||||
t.boolean "is_mirrored", :default => false, :null => false
|
||||
end
|
||||
|
||||
add_index "cms_sites", ["hostname"], :name => "index_cms_sites_on_hostname"
|
||||
add_index "cms_sites", ["is_mirrored"], :name => "index_cms_sites_on_is_mirrored"
|
||||
|
||||
create_table "cms_snippets", :force => true do |t|
|
||||
t.integer "site_id", :null => false
|
||||
t.string "label", :null => false
|
||||
t.string "identifier", :null => false
|
||||
t.text "content"
|
||||
t.integer "position", :default => 0, :null => false
|
||||
t.boolean "is_shared", :default => false, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "cms_snippets", ["site_id", "identifier"], :name => "index_cms_snippets_on_site_id_and_identifier", :unique => true
|
||||
add_index "cms_snippets", ["site_id", "position"], :name => "index_cms_snippets_on_site_id_and_position"
|
||||
|
||||
create_table "distributors", :force => true do |t|
|
||||
t.string "name"
|
||||
@@ -23,10 +140,11 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "abn"
|
||||
t.string "acn"
|
||||
t.string "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "pickup_address_id"
|
||||
t.string "next_collection_at"
|
||||
t.text "long_description"
|
||||
end
|
||||
|
||||
create_table "product_distributions", :force => true do |t|
|
||||
@@ -65,8 +183,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "alternative_phone"
|
||||
t.integer "state_id"
|
||||
t.integer "country_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "company"
|
||||
end
|
||||
|
||||
@@ -75,12 +193,12 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
|
||||
create_table "spree_adjustments", :force => true do |t|
|
||||
t.integer "source_id"
|
||||
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0
|
||||
t.decimal "amount", :precision => 8, :scale => 2
|
||||
t.string "label"
|
||||
t.string "source_type"
|
||||
t.integer "adjustable_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.boolean "mandatory"
|
||||
t.boolean "locked"
|
||||
t.integer "originator_id"
|
||||
@@ -112,15 +230,15 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "type"
|
||||
t.integer "calculable_id", :null => false
|
||||
t.string "calculable_type", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_configurations", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "type", :limit => 50
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "spree_configurations", ["name", "type"], :name => "index_configurations_on_name_and_type"
|
||||
@@ -133,7 +251,7 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "numcode"
|
||||
end
|
||||
|
||||
create_table "spree_credit_cards", :force => true do |t|
|
||||
create_table "spree_creditcards", :force => true do |t|
|
||||
t.string "month"
|
||||
t.string "year"
|
||||
t.string "cc_type"
|
||||
@@ -158,8 +276,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "environment", :default => "development"
|
||||
t.string "server", :default => "test"
|
||||
t.boolean "test_mode", :default => true
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_inventory_units", :force => true do |t|
|
||||
@@ -167,8 +285,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "state"
|
||||
t.integer "variant_id"
|
||||
t.integer "order_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "shipment_id"
|
||||
t.integer "return_authorization_id"
|
||||
end
|
||||
@@ -182,8 +300,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "variant_id"
|
||||
t.integer "quantity", :null => false
|
||||
t.decimal "price", :precision => 8, :scale => 2, :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "max_quantity"
|
||||
t.integer "shipping_method_id"
|
||||
end
|
||||
@@ -195,22 +313,22 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "source_id"
|
||||
t.string "source_type"
|
||||
t.text "details"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_mail_methods", :force => true do |t|
|
||||
t.string "environment"
|
||||
t.boolean "active", :default => true
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_option_types", :force => true do |t|
|
||||
t.string "name", :limit => 100
|
||||
t.string "presentation", :limit => 100
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "position", :default => 0, :null => false
|
||||
end
|
||||
|
||||
@@ -224,8 +342,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "name"
|
||||
t.string "presentation"
|
||||
t.integer "option_type_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_option_values_variants", :id => false, :force => true do |t|
|
||||
@@ -244,8 +362,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.decimal "adjustment_total", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.decimal "credit_total", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "completed_at"
|
||||
t.integer "bill_address_id"
|
||||
t.integer "ship_address_id"
|
||||
@@ -266,8 +384,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.text "description"
|
||||
t.boolean "active", :default => true
|
||||
t.string "environment", :default => "development"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "deleted_at"
|
||||
t.string "display_on"
|
||||
end
|
||||
@@ -275,8 +393,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
create_table "spree_payments", :force => true do |t|
|
||||
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.integer "order_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "source_id"
|
||||
t.string "source_type"
|
||||
t.integer "payment_method_id"
|
||||
@@ -305,8 +423,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.text "value"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "key"
|
||||
t.string "value_type"
|
||||
end
|
||||
@@ -331,16 +449,16 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "position"
|
||||
t.integer "product_id"
|
||||
t.integer "option_type_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_product_properties", :force => true do |t|
|
||||
t.string "value"
|
||||
t.integer "product_id"
|
||||
t.integer "property_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "spree_product_properties", ["product_id"], :name => "index_product_properties_on_product_id"
|
||||
@@ -364,11 +482,12 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "meta_keywords"
|
||||
t.integer "tax_category_id"
|
||||
t.integer "shipping_category_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "count_on_hand", :default => 0, :null => false
|
||||
t.integer "supplier_id"
|
||||
t.boolean "group_buy"
|
||||
t.string "group_buy_unit_size"
|
||||
end
|
||||
|
||||
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"
|
||||
@@ -409,8 +528,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "user_id"
|
||||
t.integer "product_group_id"
|
||||
t.string "type"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "spree_promotion_rules", ["product_group_id"], :name => "index_promotion_rules_on_product_group_id"
|
||||
@@ -427,8 +546,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
create_table "spree_properties", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "presentation", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_properties_prototypes", :id => false, :force => true do |t|
|
||||
@@ -438,8 +557,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
|
||||
create_table "spree_prototypes", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_return_authorizations", :force => true do |t|
|
||||
@@ -448,8 +567,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.integer "order_id"
|
||||
t.text "reason"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_roles", :force => true do |t|
|
||||
@@ -472,8 +591,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "order_id"
|
||||
t.integer "shipping_method_id"
|
||||
t.integer "address_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "state"
|
||||
end
|
||||
|
||||
@@ -481,15 +600,15 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
|
||||
create_table "spree_shipping_categories", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_shipping_methods", :force => true do |t|
|
||||
t.string "name"
|
||||
t.integer "zone_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "display_on"
|
||||
t.integer "shipping_category_id"
|
||||
t.boolean "match_none"
|
||||
@@ -505,8 +624,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "transaction_id"
|
||||
t.integer "customer_id"
|
||||
t.string "payment_type"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_state_changes", :force => true do |t|
|
||||
@@ -514,8 +633,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "previous_state"
|
||||
t.integer "stateful_id"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "stateful_type"
|
||||
t.string "next_state"
|
||||
end
|
||||
@@ -529,8 +648,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
create_table "spree_tax_categories", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.boolean "is_default", :default => false
|
||||
t.datetime "deleted_at"
|
||||
end
|
||||
@@ -539,15 +658,15 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.decimal "amount", :precision => 8, :scale => 5
|
||||
t.integer "zone_id"
|
||||
t.integer "tax_category_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.boolean "included_in_price", :default => false
|
||||
end
|
||||
|
||||
create_table "spree_taxonomies", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_taxons", :force => true do |t|
|
||||
@@ -556,8 +675,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "name", :null => false
|
||||
t.string "permalink"
|
||||
t.integer "taxonomy_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "lft"
|
||||
t.integer "rgt"
|
||||
t.string "icon_file_name"
|
||||
@@ -575,8 +694,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "permissable_id"
|
||||
t.string "permissable_type"
|
||||
t.string "token"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "spree_tokenized_permissions", ["permissable_id", "permissable_type"], :name => "index_tokenized_name_and_type"
|
||||
@@ -585,8 +704,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "environment"
|
||||
t.string "analytics_id"
|
||||
t.boolean "active", :default => true
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_users", :force => true do |t|
|
||||
@@ -607,8 +726,8 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "login"
|
||||
t.integer "ship_address_id"
|
||||
t.integer "bill_address_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "authentication_token"
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
@@ -631,7 +750,7 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.boolean "is_master", :default => false
|
||||
t.integer "product_id"
|
||||
t.integer "count_on_hand", :default => 0, :null => false
|
||||
t.decimal "cost_price", :precision => 8, :scale => 2, :default => 0.0
|
||||
t.decimal "cost_price", :precision => 8, :scale => 2
|
||||
t.integer "position"
|
||||
end
|
||||
|
||||
@@ -641,15 +760,15 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.integer "zoneable_id"
|
||||
t.string "zoneable_type"
|
||||
t.integer "zone_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "spree_zones", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.boolean "default_tax", :default => false
|
||||
t.integer "zone_members_count", :default => 0
|
||||
end
|
||||
@@ -660,9 +779,10 @@ ActiveRecord::Schema.define(:version => 20121005015852) do
|
||||
t.string "email"
|
||||
t.string "twitter"
|
||||
t.string "website"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "address_id"
|
||||
t.text "long_description"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
14
db/seeds.rb
14
db/seeds.rb
@@ -60,7 +60,7 @@ end
|
||||
|
||||
|
||||
# -- Suppliers and distributors
|
||||
unless Spree::Supplier.count > 0
|
||||
unless Supplier.count > 0
|
||||
puts "[db:seed] Seeding suppliers and distributors"
|
||||
|
||||
3.times { FactoryGirl.create(:supplier) }
|
||||
@@ -74,19 +74,19 @@ unless Spree::Product.count > 0
|
||||
|
||||
FactoryGirl.create(:product,
|
||||
:name => 'Garlic', :price => 20.00,
|
||||
:supplier => Spree::Supplier.all[0],
|
||||
:distributors => [Spree::Distributor.all[0]],
|
||||
:supplier => Supplier.all[0],
|
||||
:distributors => [Distributor.all[0]],
|
||||
:taxons => [Spree::Taxon.find_by_name('Vegetables')])
|
||||
|
||||
FactoryGirl.create(:product,
|
||||
:name => 'Fuji Apple', :price => 5.00,
|
||||
:supplier => Spree::Supplier.all[1],
|
||||
:distributors => Spree::Distributor.all,
|
||||
:supplier => Supplier.all[1],
|
||||
:distributors => Distributor.all,
|
||||
:taxons => [Spree::Taxon.find_by_name('Fruit')])
|
||||
|
||||
FactoryGirl.create(:product,
|
||||
:name => 'Beef - 5kg Trays', :price => 50.00,
|
||||
:supplier => Spree::Supplier.all[2],
|
||||
:distributors => [Spree::Distributor.all[2]],
|
||||
:supplier => Supplier.all[2],
|
||||
:distributors => [Distributor.all[2]],
|
||||
:taxons => [Spree::Taxon.find_by_name('Meat and Fish')])
|
||||
end
|
||||
|
||||
57
lib/open_food_web/group_buy_report.rb
Normal file
57
lib/open_food_web/group_buy_report.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
module OpenFoodWeb
|
||||
|
||||
GroupBuyVariantRow = Struct.new(:variant, :sum_quantities, :sum_max_quantities) do
|
||||
def to_row
|
||||
[variant.product.supplier.name, variant.product.name, "UNITSIZE", variant.options_text, variant.weight, sum_quantities, sum_max_quantities]
|
||||
end
|
||||
end
|
||||
|
||||
GroupBuyProductRow = Struct.new(:product, :sum_quantities, :sum_max_quantities) do
|
||||
def to_row
|
||||
[product.supplier.name, product.name, "UNITSIZE", "TOTAL", "", sum_quantities, sum_max_quantities]
|
||||
end
|
||||
end
|
||||
|
||||
class GroupBuyReport
|
||||
def initialize orders
|
||||
@orders = orders
|
||||
end
|
||||
|
||||
def header
|
||||
["Supplier", "Product", "Unit Size", "Variant", "Weight", "Total Ordered", "Total Max"]
|
||||
end
|
||||
|
||||
def variants_and_quantities
|
||||
variants_and_quantities = []
|
||||
line_items = @orders.map { |o| o.line_items }.flatten
|
||||
supplier_groups = line_items.group_by { |li| li.variant.product.supplier }
|
||||
supplier_groups.each do |supplier, line_items_by_supplier|
|
||||
product_groups = line_items_by_supplier.group_by { |li| li.variant.product }
|
||||
product_groups.each do |product, line_items_by_product|
|
||||
|
||||
# Cycle thorugh variant of a product
|
||||
variant_groups = line_items_by_product.group_by { |li| li.variant }
|
||||
variant_groups.each do |variant, line_items_by_variant|
|
||||
sum_quantities = line_items_by_variant.sum { |li| li.quantity }
|
||||
sum_max_quantities = line_items_by_variant.sum { |li| li.max_quantity || 0 }
|
||||
variants_and_quantities << GroupBuyVariantRow.new(variant, sum_quantities, sum_max_quantities)
|
||||
end
|
||||
|
||||
# Sum quantities for each product (Total line)
|
||||
sum_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * li.quantity }
|
||||
sum_max_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * (li.max_quantity || 0) }
|
||||
variants_and_quantities << GroupBuyProductRow.new(product, sum_quantities, sum_max_quantities)
|
||||
end
|
||||
end
|
||||
variants_and_quantities
|
||||
end
|
||||
|
||||
def table
|
||||
table = []
|
||||
variants_and_quantities.each do |vr|
|
||||
table << vr.to_row
|
||||
end
|
||||
table
|
||||
end
|
||||
end
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user