Compare commits

...

114 Commits

Author SHA1 Message Date
Rohan Mitchell
9fbcd8c01b Display CMS pages with Spree's layout 2012-10-12 10:21:21 +11:00
Rohan Mitchell
927970d1a9 Viewing another products listing page does not display home page content 2012-10-12 09:39:49 +11:00
Rohan Mitchell
3dd3d8030f Display CMS pages in menu 2012-10-11 17:00:34 +11:00
Rohan Mitchell
cab61ddb7c CMS content on home page 2012-10-11 16:21:33 +11:00
Rohan Mitchell
015b7f88b0 Add tests for CMS admin security 2012-10-11 13:17:05 +11:00
Rohan Mitchell
28fc16ac66 Create links between Spree and CMS admin sections 2012-10-11 12:50:59 +11:00
Rohan Mitchell
e1d4ee318c Fix issues with elRTE - sprites and functionality now work for link and image functions 2012-10-11 12:00:30 +11:00
Rohan Mitchell
48497266da Precompile CMS assets 2012-10-11 11:06:52 +11:00
Rohan Mitchell
fe5fd76415 Further syntax fixes for GroupBuyReport 2012-10-11 10:53:33 +11:00
Rohan Mitchell
c05911fa10 Fix spree_creditcards table renamed in Spree 1.2 upgrade, remove old pending test 2012-10-11 10:50:37 +11:00
Rohan Mitchell
a686a820d9 Add distributor show page, redirect here after selecting distributor 2012-10-11 10:50:36 +11:00
Rohan Mitchell
3889545f2b Convert suppliers page to HAML 2012-10-11 10:50:36 +11:00
Rohan Mitchell
7432cb416e Andand all the html_safes 2012-10-11 10:50:36 +11:00
Rohan Mitchell
0b830a7845 Suppliers and distributors long description editable with WYSIWYG editor from CMS and displayed as HTML 2012-10-11 10:50:36 +11:00
Rohan Mitchell
58e5724f81 Display supplier details on supplier page 2012-10-11 10:50:36 +11:00
Rohan Mitchell
c07a33d88c Edit long description field in admin for suppliers and distributors 2012-10-11 10:50:36 +11:00
Rohan Mitchell
d080aa49d5 Add long description field to distributors and suppliers 2012-10-11 10:50:36 +11:00
Rohan Mitchell
a31c5bbe46 Authorise CMS via Spree login 2012-10-11 10:50:36 +11:00
Rohan Mitchell
b35fb618f3 Add base install of Comfortable Mexican Sofa 2012-10-11 10:50:36 +11:00
Rob H
8c7ed6f4ef Merge branch 'group-buy-report' 2012-10-10 15:47:02 +11:00
Rob H
1709083d8f Merge branch 'master' of github.com:andrewspinks/openfoodweb 2012-10-10 15:45:42 +11:00
Rob H
5803da9c55 Syntax fixes for group buy report classes and tests 2012-10-10 15:13:15 +11:00
Rohan Mitchell
0ad6045363 Fix struct superclass mismatch error 2012-10-10 14:02:44 +11:00
Rob H
9737f21bb8 WIP: Write body of group buy report 2012-10-10 13:46:51 +11:00
Rohan Mitchell
2535e3965b When merging orders, set distributor when target order distributor is nil 2012-10-09 08:42:29 +11:00
Rohan Mitchell
568d948cbe Destroy incomplete orders if they can't be merged, prevents that order unexpectedly appearing in cart after checkout. Also ensure all orders have a shipping method. 2012-10-05 12:09:53 +10:00
Rob H
d7a5a87aef create group buy report, display header 2012-10-03 11:49:21 +10:00
Rob H
3b8c41840f Merge branch 'master' of github.com:andrewspinks/openfoodweb
Conflicts:
	app/models/spree/line_item_decorator.rb
	db/migrate/20120919013335_add_shipping_method_to_line_items.rb
2012-10-03 10:27:19 +10:00
Rohan Mitchell
6d9257d941 Do not delete shipping method referenced by a line item 2012-10-02 12:15:09 +10:00
Rohan Mitchell
7430fc9bdd Do not delete shipping method referenced by a product distribution 2012-10-02 11:58:18 +10:00
Rohan Mitchell
473b4e9adc Add positive case test 2012-10-02 11:54:18 +10:00
Rohan Mitchell
2aa450b072 Do not delete shipping method referenced by an order 2012-10-02 11:51:13 +10:00
Rohan Mitchell
3886ec39f7 Add web helper method to visit paths with delete method 2012-10-02 11:47:55 +10:00
Rohan Mitchell
afb8faa96f Update zeus config 2012-10-02 11:44:50 +10:00
Rohan Mitchell
27b7d59f46 BaseController does not attempt to merge incomplete and current orders when they have differing distributors 2012-10-02 09:44:51 +10:00
Rohan Mitchell
bc408d8b6e Add jquery and jquery_ujs includes to admin/all.js, as these have been removed from spree/admin/spree_core.js 2012-09-22 09:20:27 +10:00
Rohan Mitchell
a8758f1271 Fix OrdersHelper for upgraded spree 2012-09-21 16:36:50 +10:00
Rohan Mitchell
2bce9df25a Track 1-1-stable on spree git, fixes order quantity change bug 2012-09-21 15:55:51 +10:00
Rohan Mitchell
479c49752c Update spree_paypal_express, hopefully fixing 'Validation failed: State can't be blank' error 2012-09-21 15:32:19 +10:00
Rohan Mitchell
62d6067c1a Do not truncate cents for product price update on add to cart JS 2012-09-21 12:44:38 +10:00
Rohan Mitchell
a1b5102476 Fix checkout totals, also amend factories for valid test shipping method data 2012-09-21 12:35:01 +10:00
Rohan Mitchell
593f3887c8 Switch pry for pry-debugger 2012-09-21 12:29:06 +10:00
Rohan Mitchell
757456dd57 Set line item shipping method in callback so that Order#update shipping calcs run correctly 2012-09-20 10:45:50 +10:00
Rohan Mitchell
3894ce946d Fix error on supplier page, add test to cover 2012-09-19 15:46:56 +10:00
Rohan Mitchell
f1f9b5b2e8 Make order and distributor report resilient to orders without distributors 2012-09-19 15:19:30 +10:00
Rohan Mitchell
5402590d5f Add debug output on line item migration for lost data 2012-09-19 15:08:05 +10:00
Rohan Mitchell
eaca160367 Set line item shipping method when added to cart, update specs for changes to line item shipping method 2012-09-19 15:01:50 +10:00
Rohan Mitchell
85f18cfb12 Rob: Replace LineItem shipping_method method with relation 2012-09-19 14:27:28 +10:00
Rob H
fe3743af16 Replace shipping method lookup with relation 2012-09-19 12:06:43 +10:00
Rohan Mitchell
7492522066 Improve clarity of various totals (items, shipping, grand total) on checkout page 2012-09-14 15:35:22 +10:00
Rohan Mitchell
334f84637d Fix empty cart button alignment at checkout 2012-09-14 13:32:49 +10:00
Rohan Mitchell
3f15fc0b52 Set default admin orders view to sort with most recent orders first 2012-09-14 13:27:33 +10:00
Rohan Mitchell
a013854d2d Change logo to Eaterprises, update link colour to match 2012-09-14 11:25:36 +10:00
Rohan Mitchell
c883ab87b6 Add db backups and uploaded images to gitignore 2012-09-14 10:32:10 +10:00
Rohan Mitchell
0e313e5826 Add Zeus config 2012-09-14 10:23:22 +10:00
Rohan Mitchell
3794c00856 Upgrade Rails to 3.2.8 and Spree to 1.1.3 2012-09-14 10:20:52 +10:00
Rohan Mitchell
b87c59c051 Default to blank distributor on add to cart to require user to select one 2012-09-13 15:29:04 +10:00
Rohan Mitchell
356ae40c7b Display product descriptions as HTML in checkout 2012-09-13 13:05:12 +10:00
Rohan Mitchell
8394c47064 Add admin js includes 2012-09-13 12:27:20 +10:00
Rohan Mitchell
a84f6f08eb Compile all admin javascripts, fixes admin/images/new.js not found error 2012-09-13 12:20:35 +10:00
Rohan Mitchell
3a391d1e76 Give undefined payment method tolerance to orders and distributors report 2012-08-08 15:30:25 +10:00
Rohan Mitchell
9dd94eaf57 Weight shipping calculator treats variants without weight defined as zero weight 2012-08-08 15:29:47 +10:00
Rohan Mitchell
9f013f0e37 When loading distributors for sidebar, only show those that have active products on hand 2012-08-04 17:51:08 +10:00
Rohan Mitchell
f0ec3080e4 Remove instrumentation 2012-08-04 17:50:30 +10:00
Rohan Mitchell
245de4fe1a Add instrumentation to debug products not appearing on distributor view 2012-08-04 16:52:18 +10:00
Rohan Mitchell
9d33ef460c Max quantity field doesn't affect JS price calcs on products without variants 2012-08-04 16:51:43 +10:00
Rohan Mitchell
e0b8b8b4d4 Force precompile admin css and js 2012-08-04 10:27:15 +10:00
Rohan Mitchell
529de72f75 Force precompilation of store/all.css and store/all.js 2012-08-04 10:23:00 +10:00
Rohan Mitchell
b4f867924b Do not connect to db during asset precompile, fix heroku deploy to cedar 2012-08-04 10:12:06 +10:00
Rohan Mitchell
9d3afe80c6 split_products_by_distributor was not written with pre-pagination by searcher in mind, resulting in silently dropped products. Disable pagination at searcher. 2012-08-03 18:47:33 +10:00
Rohan Mitchell
28e75d6467 Fix add to cart JS for compatibility with group buy 2012-08-03 18:32:19 +10:00
Rohan Mitchell
b0fa05df0c Remove assets from git 2012-08-03 18:31:28 +10:00
Rohan Mitchell
f3ffba378a Add a product with variants to the cart with max quantity for a group buy 2012-08-03 18:05:45 +10:00
Rohan Mitchell
2d89640271 Instrument orders controller to debug populate_variant_attributes 2012-08-03 14:11:59 +10:00
Rohan Mitchell
e6ee6b5164 Itemwise shipping calculator returns 0 instead of nil when there are no items 2012-08-03 08:44:53 +10:00
Rohan Mitchell
768a170bb8 Fix with_products_on_hand query for server db compatibility 2012-08-03 08:21:45 +10:00
Rohan Mitchell
8834268970 Fix error on no shipping method defined 2012-08-02 17:45:22 +10:00
Rohan Mitchell
fe61b4aab1 Display shipping fee at all steps of the checkout process, not just after delivery method is chosen 2012-08-02 16:24:08 +10:00
Rohan Mitchell
a6c2490597 Enable auto-capture for spree_paypal_express 2012-08-02 15:45:31 +10:00
Rohan Mitchell
9110dc6414 Fix form local var naming for admin shared address form 2012-08-02 15:33:39 +10:00
Rohan Mitchell
77be0dd6eb Adding a product with a max quantity less than quantity results in max_quantity==quantity 2012-08-02 15:26:13 +10:00
Rohan Mitchell
40544eb27b Adding a product to cart that is not a group buy does not show max quantity field 2012-08-02 15:16:44 +10:00
Rohan Mitchell
306cb5b089 Add max quantity to order and distributor report 2012-08-02 15:07:34 +10:00
Rohan Mitchell
c46613877c Add max quantity field to add to cart form, add end-to-end test for max_quantity 2012-08-02 14:45:55 +10:00
Rohan Mitchell
2db2fbcade Change set_variant_attribute to set_variant_attributes, implement it on Order 2012-08-02 14:45:27 +10:00
Rohan Mitchell
ea05f05576 When adding a group buy product to the cart, set the max quantity on the order 2012-08-02 14:29:05 +10:00
Rohan Mitchell
361a87f580 Add group buy option to new/edit product in admin 2012-08-02 13:42:47 +10:00
Rohan Mitchell
330c62716c Add fields for group buy feature 2012-08-02 13:15:17 +10:00
Rohan Mitchell
63bf25293d Only show distributors in sidebar that have products in stock 2012-08-02 11:49:10 +10:00
Rohan Mitchell
93867682bb Only show distributors in sidebar that have products 2012-08-02 11:33:36 +10:00
Rohan Mitchell
7d5c158021 Install Bugsnag 2012-08-02 10:32:33 +10:00
Rohan Mitchell
06c6422591 Fix by-weight calculator to take line item quantity into account 2012-07-23 18:49:03 +10:00
Rohan Mitchell
5e04032797 Explicitly specify Spree 1.1.1, fix test regression in OrdersController 2012-07-23 18:48:30 +10:00
Andrew Spinks
f716176361 specify ruby version in Gemfile as per heroku requirement: https://devcenter.heroku.com/articles/ruby-versions 2012-07-20 20:40:55 +10:00
Andrew Spinks
2826f62497 Add extra details to the order report. 2012-07-20 20:25:53 +10:00
Andrew Spinks
7172fe0c87 added extra fields to order report. 2012-07-20 00:07:41 +10:00
Andrew Spinks
7e9a84087e cleaning up order report 2012-07-19 22:48:42 +10:00
Andrew Spinks
58e9cd3eeb fix distributor name in report 2012-07-15 21:00:10 +10:00
Andrew Spinks
54559c4a5f first cut at orders report. 2012-07-15 20:48:10 +10:00
Andrew Spinks
8f5b5e7ae4 allow shipping instructions to be provided. 2012-07-11 23:33:03 +10:00
Andrew Spinks
759ceae23f add distributor name to confirmation email 2012-07-11 23:20:59 +10:00
Andrew Spinks
32b37a1390 add padding to the second address line. 2012-07-11 22:45:57 +10:00
Andrew Spinks
0e43fcfaa1 adjust address formatting in confirmation email. 2012-07-11 22:25:42 +10:00
Andrew Spinks
6a27f8da32 update formatting of confirmation email. 2012-07-11 22:15:46 +10:00
Andrew Spinks
c24543c237 Add delivery details to confirmation email. 2012-07-11 22:07:18 +10:00
Andrew Spinks
44314ccb99 copied original spree confirmation mail 2012-07-11 21:35:07 +10:00
Andrew Spinks
9ad42a3966 adding precompiled assets 2012-07-11 20:46:20 +10:00
Andrew Spinks
d34e6570fc trying to get asset precompilation to work on deploy 2012-07-11 20:39:49 +10:00
Andrew Spinks
b5b35491cc allow asset precompile to work on new heroku instance 2012-07-07 10:17:33 +10:00
Rohan Mitchell
1e471e5e22 Name all form-containing partials with _form, tweak admin new product form 2012-07-02 16:28:31 +10:00
Rohan Mitchell
aa027f6e29 Display subtotal for delivery fees 2012-07-02 16:13:55 +10:00
Rohan Mitchell
6f581fce43 Admin can edit next collection date/time when editing an individual distributor 2012-07-02 14:36:45 +10:00
Rohan Mitchell
8156da509e Display distributor next collection time in checkout process 2012-07-02 14:32:53 +10:00
Rohan Mitchell
718e54f933 Add distributor next_collection_at field, bulk edit in admin backend 2012-07-02 14:24:52 +10:00
118 changed files with 2294 additions and 331 deletions

31
.gitignore vendored
View File

@@ -10,48 +10,21 @@ log/*.log.lck
log/*.log.*
tmp/
.idea/*
solr/data/
solr/pids/
\#*
.#*
*~
*.~lock.*
.emacs.desktop
.DS_Store
.emacs.desktop.lock*
coverage
merged_coverage
upstream_coverage
true/
reports
*.tmproj
*tags
dump.rdb
bin/
spec/javascripts/generated/*
db/development_structure.sql
db/test_structure.sql
db/staging_structure.sql
db/production_structure.sql
db/bootstrap/*.sql
db/bootstrap/*.dump
db/bootstrap/*.bak
db/bootstrap/*.pgz
db/bootstrap/image_fixtures/*
db/bootstrap/image_fixtures/properties/*
db/backup
public/system
public/stylesheets
public/images
vendor/bundle
config/database.Tom-Meiers-MacBook-Pro.local.yml
public/spree
config/abr.yml
vendor/ruby
ey-cloud-recipes/db/bootstrap/*.dump
ey-cloud-recipes/db/bootstrap/*.pgz
ey-cloud-recipes/db/bootstrap/image_fixtures/*
ey-cloud-recipes/.idea/*
chromedriver.log
financial_reports/*.csv
NERD_tree*
spec/reference_images/*
public/search

24
Gemfile
View File

@@ -1,23 +1,27 @@
source 'http://rubygems.org'
ruby "1.9.3"
gem 'rails', '3.2.3'
gem 'rails', '3.2.8'
gem 'pg'
gem 'spree'
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'
gem 'spree_paypal_express', :git => 'git://github.com/spree/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
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 'haml'
gem 'aws-s3'
gem 'andand'
gem 'truncate_html'
# Gems used only for assets and not required
# in production environments by default.
@@ -33,17 +37,6 @@ end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test, :development do
# Pretty printed test output
@@ -55,6 +48,7 @@ group :test, :development do
gem 'capybara'
gem 'database_cleaner', '0.7.1', :require => false
gem 'spork', '~> 1.0rc'
gem 'pry'
gem 'pry-debugger'
gem 'awesome_print'
end

View File

@@ -21,6 +21,54 @@ GIT
aws-sdk (~> 1.3.4)
spree_core (>= 0.70.0)
GIT
remote: git://github.com/spree/spree.git
revision: d66ffac9088d0d5d0b0d146f305044ce619f0464
branch: 1-1-stable
specs:
spree (1.1.3)
spree_api (= 1.1.3)
spree_auth (= 1.1.3)
spree_cmd (= 1.1.3)
spree_core (= 1.1.3)
spree_dash (= 1.1.3)
spree_promo (= 1.1.3)
spree_sample (= 1.1.3)
spree_api (1.1.3)
rabl (= 0.6.5)
spree_auth (= 1.1.3)
spree_core (= 1.1.3)
spree_auth (1.1.3)
cancan (= 1.6.7)
devise (~> 2.0.0)
spree_core (= 1.1.3)
spree_cmd (1.1.3)
thor (>= 0.14.6)
spree_core (1.1.3)
activemerchant (= 1.28.0)
acts_as_list (= 0.1.4)
aws-sdk (~> 1.3.4)
deface (>= 0.9.0)
ffaker (~> 1.12.0)
highline (= 1.6.11)
jquery-rails (~> 2.0)
kaminari (= 0.13.0)
nested_set (= 1.7.0)
paperclip (~> 2.7)
rails (~> 3.2.8)
ransack (~> 0.6.0)
state_machine (= 1.1.2)
stringex (~> 1.3.2)
spree_dash (1.1.3)
httparty (~> 0.8.1)
spree_auth (= 1.1.3)
spree_core (= 1.1.3)
spree_promo (1.1.3)
spree_auth (= 1.1.3)
spree_core (= 1.1.3)
spree_sample (1.1.3)
spree_core (= 1.1.3)
GIT
remote: git://github.com/spree/spree_i18n.git
revision: a96bee02340e008e60549295a4f09e047fd2e628
@@ -31,50 +79,53 @@ GIT
GIT
remote: git://github.com/spree/spree_paypal_express.git
revision: d48f4649506e876b88244dcb4e5a86250e4ef8f0
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:
actionmailer (3.2.3)
actionpack (= 3.2.3)
actionmailer (3.2.8)
actionpack (= 3.2.8)
mail (~> 2.4.4)
actionpack (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
actionpack (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
active_utils (1.0.3)
sprockets (~> 2.1.3)
active_link_to (1.0.0)
active_utils (1.0.5)
activesupport (>= 2.3.11)
i18n
activemerchant (1.20.4)
activemerchant (1.28.0)
active_utils (>= 1.0.2)
activesupport (>= 2.3.11)
braintree (>= 2.0.0)
builder (>= 2.0.0)
i18n
json (>= 1.5.1)
money (<= 3.7.1)
activemodel (3.2.3)
activesupport (= 3.2.3)
money
nokogiri
activemodel (3.2.8)
activesupport (= 3.2.8)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activerecord (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activesupport (3.2.3)
activeresource (3.2.8)
activemodel (= 3.2.8)
activesupport (= 3.2.8)
activesupport (3.2.8)
i18n (~> 0.6)
multi_json (~> 1.0)
acts_as_list (0.1.4)
@@ -82,6 +133,7 @@ GEM
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
@@ -92,9 +144,10 @@ GEM
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
bcrypt-ruby (3.0.1)
braintree (2.16.0)
builder (>= 2.0.0)
builder (3.0.0)
bugsnag (1.1.2)
httparty (~> 0.8.3)
multi_json (~> 1.3.4)
builder (3.0.3)
cancan (1.6.7)
capybara (1.1.2)
mime-types (>= 1.16)
@@ -105,8 +158,8 @@ GEM
xpath (~> 0.1.4)
childprocess (0.3.2)
ffi (~> 1.0.6)
cocaine (0.2.1)
coderay (1.0.6)
cocaine (0.3.0)
coderay (1.0.7)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -114,7 +167,19 @@ GEM
coffee-script-source
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)
debugger-linecache (~> 1.1.1)
debugger-ruby_core_source (~> 1.1.3)
debugger-linecache (1.1.2)
debugger-ruby_core_source (>= 1.1.1)
debugger-ruby_core_source (1.1.3)
deface (0.9.1)
nokogiri (~> 1.5.0)
rails (~> 3.1)
@@ -142,12 +207,12 @@ GEM
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
i18n (0.6.0)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
jquery-rails (2.1.2)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.3)
json (1.7.5)
kaminari (0.13.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
@@ -160,16 +225,17 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.7.1)
mime-types (1.18)
money (3.7.1)
method_source (0.8)
mime-types (1.19)
money (5.0.0)
i18n (~> 0.4)
json
multi_json (1.3.6)
multi_xml (0.5.1)
nested_set (1.7.0)
activerecord (>= 3.0.0)
railties (>= 3.0.0)
nokogiri (1.5.3)
nokogiri (1.5.5)
orm_adapter (0.0.7)
paperclip (2.7.0)
activerecord (>= 2.3.0)
@@ -180,10 +246,13 @@ GEM
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.3)
pry (0.9.9.6)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
method_source (~> 0.8)
slop (~> 3.3.1)
pry-debugger (0.2.0)
debugger (~> 1.1.3)
pry (~> 0.9.9)
rabl (0.6.5)
activesupport (>= 2.3.14)
multi_json (~> 1.0)
@@ -194,21 +263,21 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.3)
actionmailer (= 3.2.3)
actionpack (= 3.2.3)
activerecord (= 3.2.3)
activeresource (= 3.2.3)
activesupport (= 3.2.3)
rails (3.2.8)
actionmailer (= 3.2.8)
actionpack (= 3.2.8)
activerecord (= 3.2.8)
activeresource (= 3.2.8)
activesupport (= 3.2.8)
bundler (~> 1.0)
railties (= 3.2.3)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
railties (= 3.2.8)
railties (3.2.8)
actionpack (= 3.2.8)
activesupport (= 3.2.8)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
thor (>= 0.14.6, < 2.0)
raindrops (0.9.0)
rake (0.9.2.2)
ransack (0.6.0)
@@ -244,49 +313,8 @@ GEM
rubyzip
shoulda-matchers (1.1.0)
activesupport (>= 3.0.0)
slop (2.4.4)
slop (3.3.3)
spork (1.0.0rc3)
spree (1.1.1)
spree_api (= 1.1.1)
spree_auth (= 1.1.1)
spree_cmd (= 1.1.1)
spree_core (= 1.1.1)
spree_dash (= 1.1.1)
spree_promo (= 1.1.1)
spree_sample (= 1.1.1)
spree_api (1.1.1)
rabl (= 0.6.5)
spree_auth (= 1.1.1)
spree_core (= 1.1.1)
spree_auth (1.1.1)
cancan (= 1.6.7)
devise (~> 2.0.0)
spree_core (= 1.1.1)
spree_cmd (1.1.1)
spree_core (1.1.1)
activemerchant (= 1.20.4)
acts_as_list (= 0.1.4)
aws-sdk (~> 1.3.4)
deface (>= 0.8.0)
ffaker (~> 1.12.0)
highline (= 1.6.11)
jquery-rails (~> 2.0.0)
kaminari (>= 0.13.0)
nested_set (= 1.7.0)
paperclip (~> 2.7)
rails (>= 3.2.2, <= 3.2.3)
ransack (~> 0.6.0)
state_machine (= 1.1.2)
stringex (~> 1.3.2)
spree_dash (1.1.1)
httparty (~> 0.8.1)
spree_auth (= 1.1.1)
spree_core (= 1.1.1)
spree_promo (1.1.1)
spree_auth (= 1.1.1)
spree_core (= 1.1.1)
spree_sample (1.1.1)
spree_core (= 1.1.1)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
@@ -295,11 +323,12 @@ GEM
stringex (1.3.3)
therubyracer (0.10.1)
libv8 (~> 3.3.10)
thor (0.14.6)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
truncate_html (0.5.5)
turn (0.8.3)
ansi
tzinfo (0.3.33)
@@ -310,7 +339,7 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
uuidtools (2.1.2)
uuidtools (2.1.3)
warden (1.1.1)
rack (>= 1.0)
xml-simple (1.1.1)
@@ -322,28 +351,32 @@ PLATFORMS
DEPENDENCIES
andand
awesome_print
aws-s3
bugsnag
capybara
coffee-rails (~> 3.2.1)
comfortable_mexican_sofa
database_cleaner (= 0.7.1)
factory_girl_rails
faker
haml
jquery-rails
pg
pry
rails (= 3.2.3)
pry-debugger
rails (= 3.2.8)
rspec-rails
sass-rails (~> 3.2.3)
shoulda-matchers
simple_form!
spork (~> 1.0rc)
spree
spree!
spree_heroku!
spree_i18n!
spree_last_address!
spree_paypal_express!
therubyracer
truncate_html
turn (~> 0.8.3)
uglifier (>= 1.0.3)
unicorn

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
app/assets/images/logo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

BIN
app/assets/images/store/cart.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

View File

@@ -5,6 +5,8 @@
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require admin/spree_core
//= require admin/spree_auth
//= require admin/spree_promo

View File

@@ -9,7 +9,7 @@ $(document).ready(function() {
$("#quantity").change();
// Product page with master price only
$(".add-to-cart input.title:not(#quantity)").change(products_update_price_without_variant).change();
$(".add-to-cart input.title:not(#quantity):not(.max_quantity)").change(products_update_price_without_variant).change();
});
@@ -28,7 +28,7 @@ function products_update_price_without_variant() {
if(master_price == null) {
// Store off the master price
master_price = $("#product-price span.price").html();
master_price = master_price.substr(1, master_price.length-2);
master_price = master_price.substring(1);
$("#product-price span.price").data('master-price', master_price);
}

View File

@@ -0,0 +1,14 @@
#header #logo {
top: 10px;
}
#header h1 {
left: 275px;
}
/* Fix conflict between Spree and elRTE's styles */
.el-rte .toolbar {
float: none;
margin-bottom: 0;
}

View File

@@ -1,5 +1,23 @@
@import "screen";
a:hover {
color: lighten($link_text_color, 20) !important;
}
table {
tbody, tfoot {
tr {
&.alt, &.odd {
background-color: lighten($link_text_color, 75) !important;
}
}
}
}
#header #logo {
padding-top: 10px;
}
/* Style current distributor in main nav bar */
nav #main-nav-bar {
li {
@@ -110,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;
@@ -147,6 +172,7 @@ ul.product-listing {
}
#empty-cart {
float: left;
margin-top: 15px !important;
p {
padding: 0;
@@ -174,4 +200,15 @@ ul.product-listing {
}
}
}
.subtotal {
width: 100%;
text-align: right;
text-transform: uppercase;
margin-top: 15px;
span.order-total {
@extend span.price;
}
}
}

View File

@@ -0,0 +1,58 @@
/*--------------------------------------*/
/* Colors
/*--------------------------------------*/
$c_green: #8dba53; /* Spree green */
$c_red: #e45353; /* Error red */
$layout_background_color: #FFFFFF;
$title_text_color: #404042;
$body_text_color: #404042;
$link_text_color: #006066;
$product_background_color: #FFFFFF;
$product_title_text_color: #404042;
$product_body_text_color: #404042;
$product_link_text_color: #BBBBBB;
/*--------------------------------------*/
/* Fonts import from remote
/*--------------------------------------*/
@import url(//fonts.googleapis.com/css?family=Ubuntu:400,700,400italic,700italic|&subset=latin,cyrillic,greek,greek-ext,latin-ext,cyrillic-ext);
/*--------------------------------------*/
/* Font families
/*--------------------------------------*/
$ff_base: 'Ubuntu', sans-serif;
/*--------------------------------------
| Font sizes
|--------------------------------------
|- Navigation
| */
$header_navigation_font_size: 14px;
$horizontal_navigation_font_size: 16px;
$main_navigation_header_font_size: 14px;
$main_navigation_font_size: 12px;
/*|------------------------------------
|- Product Listing
| */
$product_list_name_font_size: 12px;
$product_list_price_font_size: 16px;
$product_list_header_font_size: 20px;
$product_list_search_font_size: 14px;
/*|------------------------------------
|- Product Details
| */
$product_detail_name_font_size: 24px;
$product_detail_description_font_size: 12px;
$product_detail_price_font_size: 20px;
$product_detail_title_font_size: 14px;
/*|------------------------------------
|- Basic
| */
$heading_font_size: 24px;
$sub_heading_font_size: 14px;
$button_font_size: 12px;
$input_box_font_size: 13px;
$base_font_size: 12px;
$button_border_color: rgba(0, 138, 189, .75);

View File

@@ -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.all
@distributors = Spree::Distributor.with_active_products_on_hand.by_name
end
end

View File

@@ -1,16 +1,30 @@
module Spree
module Admin
class DistributorsController < ResourceController
before_filter :load_data, :except => [:index]
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_data
@countries = Country.order(:name)
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)
super.order(:name)
end
end
end
end
end

View File

@@ -0,0 +1,70 @@
require 'csv'
require 'open_food_web/order_and_distributor_report'
require 'open_food_web/group_buy_report'
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"}})
def orders_and_distributors
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
@report = OpenFoodWeb::OrderAndDistributorReport.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 => "orders_and_distributors.csv"
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 = Spree::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
end

View File

@@ -0,0 +1,28 @@
module Spree
module Admin
ShippingMethodsController.class_eval do
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
def do_not_destroy_referenced_shipping_methods
order = Order.where(:shipping_method_id => @object).first
if order
flash[:error] = "That shipping method cannot be deleted as it is referenced by an order: #{order.number}."
redirect_to collection_url and return
end
product_distribution = ProductDistribution.where(:shipping_method_id => @object).first
if product_distribution
p = product_distribution.product
flash[:error] = "That shipping method cannot be deleted as it is referenced by a product distribution: #{p.id} - #{p.name}."
redirect_to collection_url and return
end
line_item = LineItem.where(:shipping_method_id => @object).first
if line_item
flash[:error] = "That shipping method cannot be deleted as it is referenced by a line item in order: #{line_item.order.number}."
redirect_to collection_url and return
end
end
end
end
end

View File

@@ -0,0 +1,25 @@
module Spree
BaseController.class_eval do
# Override definition in spree/auth/app/controllers/spree/base_controller_decorator.rb
# Do not attempt to merge incomplete and current orders when they have differing distributors
# Instead, destroy the incomplete orders, otherwise they are restored after checkout, causing much confusion
def set_current_order
if current_user
if current_user.respond_to?(:last_incomplete_order)
last_incomplete_order = current_user.last_incomplete_order
if session[:order_id].nil? && last_incomplete_order
session[:order_id] = last_incomplete_order.id
elsif current_order && last_incomplete_order && current_order != last_incomplete_order
if current_order.distributor.nil? || current_order.distributor == last_incomplete_order.distributor
current_order.set_distributor! last_incomplete_order.distributor if current_order.distributor.nil?
current_order.merge!(last_incomplete_order)
else
last_incomplete_order.destroy
end
end
end
end
end
end
end

View File

@@ -1,12 +1,15 @@
module Spree
class DistributorsController < BaseController
helper 'spree/products'
def show
options = {:distributor_id => params[:id]}
options.merge(params.reject { |k,v| k == :id })
@distributor = Distributor.find params[:id]
@searcher = Config.searcher_class.new(options)
@products = @searcher.retrieve_products
render :template => 'spree/products/index'
end
def select
@@ -19,7 +22,7 @@ module Spree
order.save!
end
redirect_to root_path
redirect_to distributor
end
def deselect

View File

@@ -1,20 +1,38 @@
Spree::OrdersController.class_eval do
before_filter :populate_order_distributor, :only => :populate
before_filter :populate_order_distributor, :only => :populate
after_filter :populate_variant_attributes, :only => :populate
def populate_order_distributor
@distributor = params.key?(:distributor_id) ? Spree::Distributor.find(params[:distributor_id]) : nil
@distributor = params[:distributor_id].present? ? Spree::Distributor.find(params[:distributor_id]) : nil
if populate_valid? @distributor
order = current_order(true)
order.distributor = @distributor
order.save!
order.set_distributor! @distributor
else
redirect_to cart_path
flash[:error] = "Please choose a distributor for this order." if @distributor.nil?
redirect_populate_to_first_product
end
end
def populate_variant_attributes
if params.key? :variant_attributes
params[:variant_attributes].each do |variant_id, attributes|
@order.set_variant_attributes(Spree::Variant.find(variant_id), attributes)
end
end
if params.key? :quantity
params[:products].each do |product_id, variant_id|
max_quantity = params[:max_quantity].to_i
@order.set_variant_attributes(Spree::Variant.find(variant_id), {:max_quantity => max_quantity})
end
end
end
private
def populate_valid? distributor
# -- Distributor must be specified
return false if distributor.nil?
@@ -38,4 +56,14 @@ Spree::OrdersController.class_eval do
true
end
def redirect_populate_to_first_product
product = if params[:products].present?
Spree::Product.find(params[:products].keys.first)
else
Spree::Variant.find(params[:variants].keys.first).product
end
redirect_to product
end
end

View File

@@ -1,12 +1,15 @@
module Spree
class SuppliersController < BaseController
helper 'spree/products'
def show
options = {:supplier_id => params[:id]}
options.merge(params.reject { |k,v| k == :id })
@supplier = Supplier.find params[:id]
@searcher = Config.searcher_class.new(options)
@products = @searcher.retrieve_products
render :template => 'spree/products/index'
end
end
end

View File

@@ -1,2 +1,7 @@
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
end

View File

@@ -0,0 +1,9 @@
module Spree
module OrdersHelper
def order_delivery_fee_subtotal(order, options={})
options.reverse_merge! :format_as_currency => true
amount = order.line_items.map { |li| li.itemwise_shipping_cost }.sum
options.delete(:format_as_currency) ? number_to_currency(amount) : amount
end
end
end

View File

@@ -7,7 +7,7 @@ module OpenFoodWeb
def compute(object)
# Given an order, sum the shipping on each individual item
object.line_items.map { |li| li.itemwise_shipping_cost }.inject(:+)
object.line_items.map { |li| li.itemwise_shipping_cost }.inject(:+) || 0
end
end
end

View File

@@ -8,7 +8,7 @@ module OpenFoodWeb
end
def compute(object)
total_weight = object.line_items.inject(0) { |sum, li| sum+li.variant.weight }
total_weight = object.line_items.inject(0) { |sum, li| sum + ((li.variant.andand.weight || 0) * li.quantity) }
total_weight * self.preferred_per_kg
end
end

View File

@@ -13,6 +13,7 @@ module Spree
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

View File

@@ -0,0 +1,36 @@
# 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

View File

@@ -1,10 +1,19 @@
Spree::LineItem.class_eval do
def shipping_method
self.product.shipping_method_for_distributor(self.order.distributor)
end
belongs_to :shipping_method
attr_accessible :max_quantity
before_create :set_itemwise_shipping_method
def itemwise_shipping_cost
order = OpenStruct.new :line_items => [self]
shipping_method.compute_amount(order)
end
private
def set_itemwise_shipping_method
self.shipping_method = self.product.shipping_method_for_distributor(self.order.distributor)
end
end

View File

@@ -1,6 +1,9 @@
Spree::Order.class_eval do
belongs_to :distributor
before_validation :shipping_address_from_distributor
after_create :set_default_shipping_method
def can_change_distributor?
# Distributor may not be changed once an item has been added to the cart/order
line_items.empty?
@@ -11,15 +14,47 @@ Spree::Order.class_eval do
super(distributor)
end
def set_distributor!(distributor)
self.distributor = distributor
save!
end
def can_add_product_to_cart?(product)
can_change_distributor? || product.distributors.include?(distributor)
end
def set_variant_attributes(variant, attributes)
line_item = contains?(variant)
if attributes.key?(:max_quantity) && attributes[:max_quantity].to_i < line_item.quantity
attributes[:max_quantity] = line_item.quantity
end
line_item.assign_attributes(attributes)
line_item.save!
end
before_validation :shipping_address_from_distributor
private
# On creation of the order (when the first item is added to the user's cart), set the
# shipping method to the first one available and create a shipment.
# order.create_shipment! creates an adjustment for the shipping cost on the order,
# which means that the customer can see their shipping cost at every step of the
# checkout process, not just after the delivery step.
# This is based on the assumption that there's only one shipping method visible to the user,
# which is a method using the itemwise shipping calculator.
def set_default_shipping_method
self.shipping_method = Spree::ShippingMethod.where("display_on != 'back_end'").first
if self.shipping_method
self.save!
self.create_shipment!
else
raise 'No default shipping method found'
end
end
def shipping_address_from_distributor
if distributor
self.ship_address = distributor.pickup_address.clone

View File

@@ -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
attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy
validates_presence_of :supplier

View 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>")

View File

@@ -1,9 +1,9 @@
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:insert_bottom => "[data-hook='admin_product_form_additional_fields']",
:partial => "spree/admin/products/distributors",
:insert_bottom => "[data-hook='admin_product_form_additional_fields']",
:partial => "spree/admin/products/distributors_form",
:name => "distributors")
Deface::Override.new(:virtual_path => "spree/admin/products/new",
:insert_bottom => ".left",
:partial => "spree/admin/products/distributors",
:insert_after => "[data-hook='new_product_attrs']",
:partial => "spree/admin/products/distributors_form",
:name => "distributors")

View File

@@ -0,0 +1,9 @@
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:insert_top => "[data-hook='admin_product_form_right']",
:partial => "spree/admin/products/group_buy_form",
:name => "group buy")
Deface::Override.new(:virtual_path => "spree/admin/products/new",
:insert_bottom => ".right",
:partial => "spree/admin/products/group_buy_form",
:name => "group buy")

View File

@@ -1,9 +1,9 @@
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:insert_top => "[data-hook='admin_product_form_right']",
:partial => "spree/admin/products/supplier",
:name => "supplier")
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:insert_top => "[data-hook='admin_product_form_right']",
:partial => "spree/admin/products/supplier_form",
:name => "supplier")
Deface::Override.new(:virtual_path => "spree/admin/products/new",
:insert_bottom => ".left",
:partial => "spree/admin/products/supplier",
:name => "supplier")
:insert_bottom => ".right",
:partial => "spree/admin/products/supplier_form",
:name => "supplier")

View File

@@ -0,0 +1,4 @@
Deface::Override.new(:virtual_path => "spree/orders/_line_item",
:replace => "[data-hook='cart_item_description']",
:partial => "spree/orders/cart_item_description",
:name => "cart_item_description")

View File

@@ -0,0 +1 @@
%li= link_to 'Spree Admin', spree.admin_path

View File

@@ -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' %>

View 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}

View File

@@ -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
@@ -26,8 +32,11 @@
%fieldset
%legend Pickup details
%table{"data-hook" => "distributors_pickup_details"}
%tr{"data-hook" => "next_collection_at"}
%td Next collection date/time:
%td= f.text_field :next_collection_at
%tr{"data-hook" => "pickup_times"}
%td Pickup times:
%td Regular pickup times:
%td= f.text_field :pickup_times
= f.fields_for :pickup_address do |pickup_address_form|
= render 'spree/admin/shared/address_form', :form => pickup_address_form
= render 'spree/admin/shared/address_form', :f => pickup_address_form

View File

@@ -1,4 +1,3 @@
<div class="toolbar" data-hook="toolbar">
<ul class="actions">
<li>
@@ -8,30 +7,34 @@
<br class="clear" />
</div>
<table class="index" id='listing_distributors'>
<thead>
<tr data-hook="distributors_header">
<th>Name</th>
<th>
Description
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<% @distributors.each do |distributor| %>
<tr >
<td><%= link_to distributor.name, spree.admin_distributor_path(distributor) %></td>
<td><%=distributor.description %></td>
<td data-hook="admin_users_index_row_actions">
<%= link_to_edit distributor, :class => 'edit' %> &nbsp;
<%= link_to_delete distributor %>
</td>
<%= form_for @distributor_set, :url => bulk_update_admin_distributors_path do |f| %>
<table class="index" id="listing_distributors">
<thead>
<tr data-hook="distributors_header">
<th>Name</th>
<th>Next Collection Date/Time</th>
<th>Description</th>
<th></th>
</tr>
<% end %>
<% if @distributors.empty? %>
<tr><td colspan="2"><%= t(:none) %></td></tr>
<% end %>
</tbody>
</table>
</thead>
<tbody>
<%= f.fields_for :distributors do |distributor_form| %>
<% distributor = distributor_form.object %>
<tr>
<td><%= link_to distributor.name, spree.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">
<%= link_to_edit distributor, :class => 'edit' %> &nbsp;
<%= link_to_delete distributor %>
</td>
</tr>
<% end %>
<% if @distributors.empty? %>
<tr><td colspan="4"><%= t(:none) %></td></tr>
<% end %>
</tbody>
</table>
<%= f.submit 'Update' %>
<% end %>

View File

@@ -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
@@ -19,7 +22,10 @@
%th Pickup address:
%td= render 'spree/shared/address', :address => @distributor.pickup_address
%tr
%th Pickup times:
%th Next collection date/time:
%td= @distributor.next_collection_at
%tr
%th Regular pickup times:
%td= @distributor.pickup_times
%tr
%th ABN:

View File

@@ -0,0 +1,7 @@
= f.field_container :group_buy do
= f.label :group_buy, 'Group buy?'
%br
= f.radio_button :group_buy, '1', :checked => f.object.group_buy
= f.label :group_buy_1, 'Yes'
= f.radio_button :group_buy, '0', :checked => !f.object.group_buy
= f.label :group_buy_0, 'No'

View 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)

View File

@@ -0,0 +1,32 @@
= form_for @search, :url => spree.orders_and_distributors_admin_reports_path do |s|
= label_tag nil, t(:date_range)
%br
.date-range-filter
%div{"class" => "left sub-field"}
= s.text_field :created_at_gt, :class => 'datepicker'
%br
= label_tag nil, t(:start), :class => 'sub'
%div{"class" => "right sub-field"}
= s.text_field :created_at_lt, :class => 'datepicker'
%br
= label_tag nil, t(:stop)
= 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)

View File

@@ -1,18 +1,18 @@
%tr{"data-hook" => "address1"}
%td Address:
%td= form.text_field :address1
%td= f.text_field :address1
%tr{"data-hook" => "address2"}
%td Address (cont.):
%td= form.text_field :address2
%td= f.text_field :address2
%tr{"data-hook" => "city"}
%td City:
%td= form.text_field :city
%td= f.text_field :city
%tr{"data-hook" => "zipcode"}
%td Postcode:
%td= form.text_field :zipcode
%td= f.text_field :zipcode
%tr{"data-hook" => "country"}
%td Country:
%td= form.collection_select(:country_id, available_countries, :id, :name)
%td= f.collection_select(:country_id, available_countries, :id, :name)
%tr{"data-hook" => "state"}
%td State:
%td= form.collection_select(:state_id, form.object.country.states, :id, :name)
%td= f.collection_select(:state_id, f.object.country.states, :id, :name)

View File

@@ -0,0 +1,6 @@
<%= tab :overview, :route => :admin %>
<%= tab :orders, :payments, :creditcard_payments, :shipments, :creditcards, :return_authorizations, {:url => admin_orders_path('q[s]' => 'completed_at desc')} %>
<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons %>
<%= tab :reports %>
<%= tab :configurations, :general_settings, :mail_methods, :tax_categories, :zones, :states, :payment_methods, :inventory_settings, :taxonomies, :shipping_methods, :trackers, :label => 'configuration' %>
<%= tab :users %>

View File

@@ -1,3 +1,6 @@
- content_for :head do
= render 'shared/cms_elrte_head'
%table{'data-hook' => "suppliers"}
%tr{'data-hook' => "name"}
%td Name:
@@ -5,8 +8,11 @@
%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', :form => address_form
= render 'spree/admin/shared/address_form', :f => address_form
%tr{'data-hook' => "email"}
%td Email:
%td= f.text_field :email

View File

@@ -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

View File

@@ -7,7 +7,11 @@
%br/
= render 'spree/shared/address', :address => @order.distributor.pickup_address
%p
%strong Pickup times:
%strong Next collection time:
%br/
= @order.distributor.next_collection_at
%p
%strong Regular collection times:
%br/
= @order.distributor.pickup_times
%p

View File

@@ -0,0 +1,7 @@
%h2= @distributor.name
.distributor-description= @distributor.long_description.andand.html_safe
%h3 Available Now
= render :template => 'spree/products/index'

View File

@@ -0,0 +1,33 @@
Dear Customer,
Please review and retain the following order information for your records.
============================================================
Order Summary
============================================================
<% @order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
<% end %>
============================================================
Subtotal: <%= number_to_currency @order.item_total %>
<% @order.adjustments.each do |adjustment| %>
<%= raw(adjustment.label) %> <%= number_to_currency(adjustment.amount) %>
<% end %>
Order Total: <%= number_to_currency(@order.total) %>
============================================================
Delivery Details
============================================================
Address:
<%= @order.distributor.name %>
<% address = @order.distributor.pickup_address %>
<%= address.address1 %> <%= ",\n #{address.address2}" unless address.address2.blank? %>
<%= [address.city, address.state_text, address.zipcode, address.country.name].compact.join ', ' %>
Colection time:
<%= @order.distributor.next_collection_at %>
Contact:
<%= @order.distributor.contact %>
<%= "Phone: #{@order.distributor.phone}" %>
<%= "Email: #{@order.distributor.email}" %>
Thank you for your business.

View File

@@ -0,0 +1,8 @@
%td{'data-hook' => "cart_item_description"}
%h4= link_to variant.product.name, product_path(variant.product)
= variant.options_text
- if @order.insufficient_stock_lines.include? line_item
%span.out-of-stock
= variant.in_stock? ? t(:insufficient_stock, :on_hand => variant.on_hand) : t(:out_of_stock)
%br/
= truncate_html(variant.product.description, :length => 100, :omission => "...")

View File

@@ -15,3 +15,9 @@
%h4= link_to line_item.product.name, product_path(line_item.product)
%td.item-shipping-method= line_item.shipping_method.name
%td.item-shipping-cost= number_to_currency line_item.itemwise_shipping_cost
.subtotal{'data-hook' => 'delivery_fees_subtotal'}
%h5
Shipping total
\:
%span.order-total= order_delivery_fee_subtotal(@order)

View File

@@ -4,9 +4,17 @@
#subtotal{'data-hook' => ""}
%h5
= t(:subtotal)
Item total
\:
%span.order-total= order_subtotal(@order)
%span.order-total.item-total= number_to_currency @order.item_total
%h5
Shipping total
\:
%span.order-total.shipping-total= order_delivery_fee_subtotal(@order)
%h4
Total
\:
%span.order-total.grand-total= order_subtotal(@order)
.links{'data-hook' => "cart_buttons"}
= button_tag :class => 'primary', :id => 'update-button' do

View File

@@ -11,10 +11,13 @@
- else
%p Quantity
= number_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"), 1, :class => 'title', :in => 1..@product.on_hand
- if @product.group_buy
%p Max quantity
= number_field_tag (@product.has_variants? ? :max_quantity : "variant_attributes[#{@product.master.id}][max_quantity]"), 1, :class => 'title max_quantity', :in => 1..@product.on_hand
- order = current_order(false)
- if order.nil? || order.can_change_distributor?
%p Distributor
= select_tag "distributor_id", options_from_collection_for_select(@product.distributors, "id", "name", current_distributor.andand.id)
= select_tag "distributor_id", options_from_collection_for_select([Spree::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}"

View File

@@ -12,7 +12,7 @@
- if order.nil? || order.can_change_distributor?
= link_to distributor.name, select_distributor_path(distributor)
- elsif order.distributor == distributor
= link_to distributor.name, root_path
= link_to distributor.name, distributor
- else
%span.inactive= distributor.name
- if current_distributor && order.can_change_distributor?

View File

@@ -1,3 +1,5 @@
= home_page_cms_content
- if @products
#products= render 'spree/shared/products', :products => @products, :taxon => @taxon
- else

View File

@@ -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

View File

@@ -0,0 +1,7 @@
%h2= @supplier.name
.supplier-description= @supplier.long_description.andand.html_safe
%h3 Available Now
= render :template => 'spree/products/index'

View File

@@ -64,5 +64,8 @@ module Openfoodweb
# Version of your assets, change this if you want to expire all your assets
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', 'comfortable_mexican_sofa/*']
end
end

View File

@@ -0,0 +1,3 @@
Bugsnag.configure do |config|
config.api_key = "937a200f492fad600b4cc29dddda5f71"
end

View File

@@ -0,0 +1,127 @@
# 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 = {:url => '/system/:class/:id/:attachment/:style/:filename'}
# 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

View File

@@ -12,11 +12,17 @@ require 'open_food_web/searcher'
Spree.config do |config|
config.site_name = "Open Food Web"
config.logo = 'logo.jpg'
config.admin_interface_logo = 'logo.jpg'
# config.shipping_instructions = true
config.shipping_instructions = true
config.checkout_zone = 'Australia'
config.address_requires_state = true
config.default_country_id = 12 # This should be Australia, see: spree/core/db/default/spree/countries.yml
config.searcher_class = OpenFoodWeb::Searcher
# -- spree_paypal_express
# Auto-capture payments. Without this option, payments must be manually captured in the paypal interface.
config.auto_capture = true
end

View File

@@ -12,7 +12,13 @@ Spree::Core::Engine.routes.prepend do
end
namespace :admin do
resources :distributors
resources :distributors do
post :bulk_update, :on => :collection, :as => :bulk_update
end
resources :suppliers
end
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]
end

View File

@@ -0,0 +1 @@
label: Default Fixture Layout

View File

@@ -0,0 +1,5 @@
<html>
<body>
{{ cms:page:content }}
</body>
</html>

View File

@@ -0,0 +1 @@
body{color: red}

View File

@@ -0,0 +1 @@
// default js

View File

@@ -0,0 +1,2 @@
label: Default Fixture Nested Layout
position: 42

View File

@@ -0,0 +1,2 @@
<div class='left'> {{ cms:page:left }} </div>
<div class='right'> {{ cms:page:right }} </div>

View File

@@ -0,0 +1 @@
div{float:left}

View File

@@ -0,0 +1 @@
// nested js

View File

@@ -0,0 +1,2 @@
label: Home Fixture Page
layout: default

View File

@@ -0,0 +1,3 @@
label: Child Fixture Page
layout: nested
position: 42

View File

@@ -0,0 +1 @@
Child Page Left Fixture Content

View File

@@ -0,0 +1 @@
Child Page Right Fixture Content

View File

@@ -0,0 +1,2 @@
Home Page Fixture Contént
{{ cms:snippet:default }}

View File

@@ -0,0 +1 @@
label: Default Fixture Snippet

View File

@@ -0,0 +1 @@
Fixture Content for Default Snippet

View File

@@ -0,0 +1,5 @@
class AddNextCollectionAtToDistributors < ActiveRecord::Migration
def change
add_column :distributors, :next_collection_at, :string
end
end

View File

@@ -0,0 +1,6 @@
class AddGroupBuyFields < ActiveRecord::Migration
def change
add_column :spree_products, :group_buy, :boolean
add_column :spree_line_items, :max_quantity, :integer
end
end

View File

@@ -0,0 +1,10 @@
# This migration comes from spree (originally 20120523061241)
class ConvertSalesTaxToDefaultTax < ActiveRecord::Migration
def up
execute "UPDATE spree_calculators SET type='Spree::Calculator::DefaultTax' WHERE type='Spree::Calculator::SalesTax'"
end
def down
execute "UPDATE spree_calculators SET type='Spree::Calculator::SalesTax' WHERE type='Spree::Calculator::DefaultTax'"
end
end

View File

@@ -0,0 +1,6 @@
# This migration comes from spree (originally 20120604030249)
class AddDeletedAtToSpreeShippingMethods < ActiveRecord::Migration
def change
add_column :spree_shipping_methods, :deleted_at, :datetime
end
end

View File

@@ -0,0 +1,11 @@
# This migration comes from spree (originally 20120605211305)
class MakeUsersEmailIndexUnique < ActiveRecord::Migration
def up
add_index "spree_users", ["email"], :name => "email_idx_unique", :unique => true
end
def down
remove_index "spree_users", :name => "email_idx_unique"
add_index "spree_users", ["email"], :name => "email_idx_unique"
end
end

View File

@@ -0,0 +1,15 @@
# This migration comes from spree (originally 20120712172620)
class AddCounterCacheToZoneMembers < ActiveRecord::Migration
def up
add_column :spree_zones, :zone_members_count, :integer, :default => 0
Spree::Zone.reset_column_information
Spree::Zone.find(:all).each do |zone|
Spree::Zone.update_counters zone.id, :zone_members_count => zone.zone_members.length
end
end
def down
remove_column :spree_zones, :zone_members_count
end
end

View File

@@ -0,0 +1,20 @@
class AddShippingMethodToLineItems < ActiveRecord::Migration
def up
add_column :spree_line_items, :shipping_method_id, :integer
Spree::LineItem.all.each do |li|
begin
shipping_method = li.product.shipping_method_for_distributor(li.order.distributor)
rescue ArgumentError
shipping_method = Spree::ShippingMethod.find_by_name 'Producer Delivery'
say "Line item #{li.id} does not have a valid shipping method, setting to '#{shipping_method.name}'"
end
Spree::LineItem.update_all("shipping_method_id = #{shipping_method.id}", "id = #{li.id}")
end
end
def down
remove_column :spree_line_items, :shipping_method_id
end
end

View File

@@ -0,0 +1,10 @@
class PopulateOrderDefaultShippingMethod < ActiveRecord::Migration
def up
Spree::Order.where(shipping_method_id: nil).each do |order|
order.send(:set_default_shipping_method)
end
end
def down
end
end

View 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

View File

@@ -0,0 +1,6 @@
class AddLongDescriptionToDistributorsAndSuppliers < ActiveRecord::Migration
def change
add_column :distributors, :long_description, :text
add_column :suppliers, :long_description, :text
end
end

View File

@@ -11,7 +11,124 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120629043648) do
ActiveRecord::Schema.define(:version => 20121010004400) 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"
@@ -26,6 +143,8 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "pickup_address_id"
t.string "next_collection_at"
t.text "long_description"
end
create_table "product_distributions", :force => true do |t|
@@ -143,8 +262,8 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.string "start_year"
t.string "issue_number"
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 "gateway_customer_profile_id"
t.string "gateway_payment_profile_id"
end
@@ -179,10 +298,12 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
create_table "spree_line_items", :force => true do |t|
t.integer "order_id"
t.integer "variant_id"
t.integer "quantity", :null => false
t.decimal "price", :precision => 8, :scale => 2, :null => false
t.integer "quantity", :null => false
t.decimal "price", :precision => 8, :scale => 2, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "max_quantity"
t.integer "shipping_method_id"
end
add_index "spree_line_items", ["order_id"], :name => "index_line_items_on_order_id"
@@ -365,6 +486,7 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.datetime "updated_at"
t.integer "count_on_hand", :default => 0, :null => false
t.integer "supplier_id"
t.boolean "group_buy"
end
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"
@@ -491,6 +613,7 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.boolean "match_none"
t.boolean "match_all"
t.boolean "match_one"
t.datetime "deleted_at"
end
create_table "spree_skrill_transactions", :force => true do |t|
@@ -612,6 +735,7 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.datetime "reset_password_sent_at"
end
add_index "spree_users", ["email"], :name => "email_idx_unique", :unique => true
add_index "spree_users", ["persistence_token"], :name => "index_users_on_persistence_token"
create_table "spree_variants", :force => true do |t|
@@ -644,7 +768,8 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "default_tax", :default => false
t.boolean "default_tax", :default => false
t.integer "zone_members_count", :default => 0
end
create_table "suppliers", :force => true do |t|
@@ -656,6 +781,7 @@ ActiveRecord::Schema.define(:version => 20120629043648) do
t.datetime "created_at"
t.datetime "updated_at"
t.integer "address_id"
t.text "long_description"
end
end

View 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 * li.quantity }
sum_max_quantities = line_items_by_product.sum { |li| li.variant.weight * (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

View File

@@ -0,0 +1,31 @@
module OpenFoodWeb
class OrderAndDistributorReport
def initialize orders
@orders = orders
end
def header
["Order date", "Order Id",
"Customer Name","Customer Email", "Customer Phone", "Customer City",
"SKU", "Item name", "Variant", "Quantity", "Max Quantity", "Cost", "Shipping cost",
"Payment method",
"Distributor", "Distributor address", "Distributor city", "Distributor postcode", "Shipping instructions"]
end
def table
order_and_distributor_details = []
@orders.each do |order|
order.line_items.each do |line_item|
order_and_distributor_details << [order.created_at, order.id,
order.bill_address.full_name, order.email, order.bill_address.phone, order.bill_address.city,
line_item.product.sku, line_item.product.name, line_item.variant.options_text, line_item.quantity, line_item.max_quantity, line_item.price * line_item.quantity, line_item.itemwise_shipping_cost,
order.payments.first.payment_method.andand.name,
order.distributor.andand.name, order.distributor.pickup_address.address1, order.distributor.pickup_address.city, order.distributor.pickup_address.zipcode, order.special_instructions ]
end
end
order_and_distributor_details
end
end
end

View File

@@ -3,6 +3,14 @@ require 'spree/core/search/base'
module OpenFoodWeb
class Searcher < Spree::Core::Search::Base
# Do not perform pagination
def retrieve_products
@products_scope = get_base_scope
curr_page = page || 1
@products = @products_scope.includes([:master])
end
def get_base_scope
base_scope = super

View File

@@ -4,9 +4,11 @@ require 'spree/core/current_order'
describe Spree::DistributorsController do
include Spree::Core::CurrentOrder
before do
before :each do
stub!(:before_save_new_order)
stub!(:after_save_new_order)
create(:itemwise_shipping_method)
end
@@ -40,9 +42,10 @@ describe Spree::DistributorsController do
d2 = create(:distributor)
p = create(:product, :distributors => [d1])
o = current_order(true)
o.distributor = d1
o.add_variant(p.master, 1)
o.save!
o.add_variant(p.master, 1)
# When I attempt to select a distributor
spree_get :select, :id => d2.id
@@ -58,8 +61,8 @@ describe Spree::DistributorsController do
p = create(:product, :distributors => [d])
o = current_order(true)
o.distributor = d
o.add_variant(p.master, 1)
o.save!
o.add_variant(p.master, 1)
# When I attempt to deselect the distributor
spree_get :deselect

View File

@@ -25,4 +25,39 @@ describe Spree::HomeController do
assigns(:products_local).should == [p1]
assigns(:products_remote).should == [p2]
end
context "BaseController: merging incomplete orders" do
it "does not attempt to merge incomplete and current orders when they have differing distributors" do
incomplete_order = double(:order, distributor: 1)
current_order = double(:order, distributor: 2)
user = double(:user, last_incomplete_order: incomplete_order)
controller.stub(:current_user).and_return(user)
controller.stub(:current_order).and_return(current_order)
incomplete_order.should_receive(:destroy)
incomplete_order.should_receive(:merge!).never
current_order.should_receive(:merge!).never
session[:order_id] = 123
spree_get :index
end
it "sets the distributor when the target order has no distributor" do
incomplete_order = double(:order, distributor: 1)
current_order = double(:order, distributor: nil)
user = double(:user, last_incomplete_order: incomplete_order)
controller.stub(:current_user).and_return(user)
controller.stub(:current_order).and_return(current_order)
current_order.should_receive(:set_distributor!).with(1)
current_order.should_receive(:merge!)
session[:order_id] = 123
spree_get :index
end
end
end

View File

@@ -15,7 +15,7 @@ describe Spree::OrdersController do
p = create(:product)
expect do
spree_put :populate, :variants => {p.id => 1}
spree_post :populate, :variants => {p.master.id => 1}
end.to change(Spree::LineItem, :count).by(0)
end
@@ -25,7 +25,7 @@ describe Spree::OrdersController do
p = create(:product, :distributors => [distributor_product])
expect do
spree_put :populate, :variants => {p.id => 1}, :distributor_id => distributor_no_product.id
spree_post :populate, :variants => {p.master.id => 1}, :distributor_id => distributor_no_product.id
end.to change(Spree::LineItem, :count).by(0)
end
@@ -39,7 +39,7 @@ describe Spree::OrdersController do
order.save!
expect do
spree_put :populate, :variants => {p.id => 1}, :distributor_id => distributor_product.id
spree_post :populate, :variants => {p.master.id => 1}, :distributor_id => distributor_product.id
end.to change(Spree::LineItem, :count).by(1)
order.reload.distributor.should == distributor_product
@@ -51,7 +51,7 @@ describe Spree::OrdersController do
p = create(:product, :distributors => [d])
# When we add the product to our cart
spree_put :populate, :variants => {p.id => 1}, :distributor_id => d.id
spree_post :populate, :variants => {p.master.id => 1}, :distributor_id => d.id
# Then our order should have its distributor set to the chosen distributor
current_order(false).distributor.should == d
@@ -65,7 +65,7 @@ describe Spree::OrdersController do
@product = create(:product, :distributors => [@distributor])
# And the product is in the cart
spree_put :populate, :variants => {@product.id => 1}, :distributor_id => @distributor.id
spree_post :populate, :variants => {@product.master.id => 1}, :distributor_id => @distributor.id
current_order(false).line_items.reload.map { |li| li.product }.should == [@product]
current_order(false).distributor.reload.should == @distributor
end
@@ -76,7 +76,7 @@ describe Spree::OrdersController do
p2 = create(:product, :distributors => [d2])
# When I attempt to add the product to the cart
spree_put :populate, :variants => {p2.id => 1}, :distributor_id => d2.id
spree_post :populate, :variants => {p2.master.id => 1}, :distributor_id => d2.id
# Then the product should not be added to the cart
current_order(false).line_items.reload.map { |li| li.product }.should == [@product]
@@ -89,7 +89,7 @@ describe Spree::OrdersController do
p2 = create(:product, :distributors => [d2])
# When I attempt to add the product to the cart with a fake distributor_id
spree_put :populate, :variants => {p2.id => 1}, :distributor_id => @distributor.id
spree_post :populate, :variants => {p2.master.id => 1}, :distributor_id => @distributor.id
# Then the product should not be added to the cart
current_order(false).line_items.reload.map { |li| li.product }.should == [@product]
@@ -102,11 +102,26 @@ describe Spree::OrdersController do
p2 = create(:product, :distributors => [@distributor, d2])
# When I attempt to add the product to the cart with the alternate distributor
spree_put :populate, :variants => {p2.id => 1}, :distributor_id => d2
spree_post :populate, :variants => {p2.master.id => 1}, :distributor_id => d2
# Then the product should not be added to the cart
current_order(false).line_items.reload.map { |li| li.product }.should == [@product]
current_order(false).distributor.reload.should == @distributor
end
end
context "adding a group buy product to the cart" do
it "sets a variant attribute for the max quantity" do
distributor_product = create(:distributor)
p = create(:product, :distributors => [distributor_product], :group_buy => true)
order = current_order(true)
order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'})
controller.stub(:current_order).and_return(order)
expect do
spree_post :populate, :variants => {p.master.id => 1}, :variant_attributes => {p.master.id => {:max_quantity => 3}}, :distributor_id => distributor_product.id
end.to change(Spree::LineItem, :count).by(1)
end
end
end

View File

@@ -5,25 +5,28 @@ FactoryGirl.define do
factory :supplier, :class => Spree::Supplier do
sequence(:name) { |n| "Supplier #{n}" }
description 'supplier'
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
email 'supplier@example.com'
address { Spree::Address.first || FactoryGirl.create(:address) }
end
factory :distributor, :class => Spree::Distributor do
sequence(:name) { |n| "Distributor #{n}" }
contact "Mr Turing"
phone "1000100100"
description 'The creator'
email 'alan@somewhere.com'
url 'http://example.com'
pickup_times "Whenever you're free"
pickup_address { Spree::Address.first || FactoryGirl.create(:address) }
sequence(:name) { |n| "Distributor #{n}" }
contact 'Mr Turing'
phone '1000100100'
description 'The creator'
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
email 'alan@somewhere.com'
url 'http://example.com'
pickup_times "Whenever you're free"
next_collection_at 'Thursday 10am'
pickup_address { Spree::Address.first || FactoryGirl.create(:address) }
end
factory :product_distribution, :class => Spree::ProductDistribution do
product { |pd| Spree::Product.first || FactoryGirl.create(:product) }
distributor { |pd| Spree::Distributor.first || FactoryGirl.create(:distributor) }
shipping_method { |pd| Spree::ShippingMethod.first || FactoryGirl.create(:shipping_method) }
shipping_method { |pd| Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method) }
end
factory :itemwise_shipping_method, :parent => :shipping_method do
@@ -38,11 +41,34 @@ end
FactoryGirl.modify do
factory :simple_product do
# Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method
# Pull request: https://github.com/spree/spree/pull/1964
# When this fix has been merged into a version of Spree that we're using, this line can be removed.
sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
supplier { Spree::Supplier.first || FactoryGirl.create(:supplier) }
on_hand 3
# before(:create) do |product, evaluator|
# product.product_distributions = [FactoryGirl.create(:product_distribution, :product => product)]
# end
# Do not create products distributed via the 'Delivery' shipping method
after(:create) do |product, evaluator|
pd = product.product_distributions.first
if pd.andand.shipping_method.andand.name == 'Delivery'
pd.shipping_method = Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method)
pd.save!
end
end
end
factory :line_item do
shipping_method { |li| li.product.shipping_method_for_distributor(li.order.distributor) }
end
factory :shipping_method do
display_on ''
end
factory :address do
@@ -50,3 +76,39 @@ FactoryGirl.modify do
country { Spree::Country.find_by_name 'Australia' || Spree::Country.first }
end
end
# -- CMS
FactoryGirl.define do
factory :cms_site, :class => Cms::Site do
identifier 'open-food-web'
label 'Open Food Web'
hostname 'localhost'
end
factory :cms_layout, :class => Cms::Layout do
site { Cms::Site.first || create(:cms_site) }
label 'layout'
identifier 'layout'
content '{{ cms:page:content:text }}'
end
factory :cms_page, :class => Cms::Page do
site { Cms::Site.first || create(:cms_site) }
label 'page'
sequence(:slug) { |n| "page-#{n}" }
layout { Cms::Layout.first || create(:cms_layout) }
# Pass content through to block, where it is stored
after(:create) do |cms_page, evaluator|
cms_page.blocks.first.update_attribute(:content, evaluator.content)
cms_page.save! # set_cached_content
end
end
factory :cms_block, :class => Cms::Block do
page { Cms::Page.first || create(:cms_page) }
identifier 'block'
content 'hello, block'
end
end

View File

@@ -0,0 +1,97 @@
require 'spec_helper'
module OpenFoodWeb
describe GroupBuyReport do
before(:each) do
@orders = []
bill_address = create(:address)
distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
distributor = create(:distributor, :pickup_address => distributor_address)
@supplier1 = create(:supplier)
@variant1 = create(:variant)
@variant1.product.supplier = @supplier1
@variant1.product.save!
shipping_method = create(:shipping_method)
product_distribution = create(:product_distribution, :product => @variant1.product, :distributor => distributor, :shipping_method => create(:shipping_method))
shipping_instructions = "pick up on thursday please!"
order1 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
line_item11 = create(:line_item, :variant => @variant1, :order => order1)
order1.line_items << line_item11
@orders << order1
order2 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
line_item21 = create(:line_item, :variant => @variant1, :order => order2)
order2.line_items << line_item21
@variant2 = create(:variant)
@variant2.product.supplier = @supplier1
@variant2.product.save!
product_distribution = create(:product_distribution, :product => @variant2.product, :distributor => distributor, :shipping_method => create(:shipping_method))
line_item22 = create(:line_item, :variant => @variant2, :order => order2)
order2.line_items << line_item22
@orders << order2
@supplier2 = create(:supplier)
@variant3 = create(:variant)
@variant3.product.supplier = @supplier2
@variant3.product.save!
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor, :shipping_method => create(:shipping_method))
order3 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
line_item31 = create(:line_item, :variant => @variant3, :order => order3)
order3.line_items << line_item31
@orders << order3
end
it "should return a header row describing the report" do
subject = GroupBuyReport.new [@order1]
header = subject.header
header.should == ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Total Ordered", "Total Max"]
end
it "should provide the required variant and quantity information in a table" do
subject = GroupBuyReport.new @orders
table = subject.table
line_items = @orders.map{ |o| o.line_items }.flatten.select{ |li| li.product.supplier == @supplier1 && li.variant == @variant1 }
sum_quantities = line_items.map { |li| li.quantity }.sum
sum_max_quantities = line_items.map { |li| li.max_quantity || 0 }.sum
table[0].should == [@variant1.product.supplier.name,@variant1.product.name,"UNITSIZE",@variant1.options_text,@variant1.weight,sum_quantities,sum_max_quantities]
end
it "should return a table wherein each rows contains the same number of columns as the heading" do
subject = GroupBuyReport.new @orders
table = subject.table
columns = subject.header.length
table.each do |r|
r.length.should == columns
end
end
it "should split and group line items from multiple suppliers and of multiple variants" do
subject = GroupBuyReport.new @orders
table_row_objects = subject.variants_and_quantities
variant_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
product_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyProductRow }
supplier_groups = variant_rows.group_by { |r| r.variant.product.supplier }
variant_groups = variant_rows.group_by{ |r| r.variant }
product_groups = product_rows.group_by{ |r| r.product }
supplier_groups.length.should == 2
variant_groups.length.should == 3
product_groups.length.should == 3
end
end
end

View File

@@ -0,0 +1,48 @@
require 'spec_helper'
module OpenFoodWeb
describe OrderAndDistributorReport do
describe "orders and distributors report" do
before(:each) do
@bill_address = create(:address)
@distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
@distributor = create(:distributor, :pickup_address => @distributor_address)
product = create(:product)
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor, :shipping_method => create(:shipping_method))
@shipping_instructions = "pick up on thursday please!"
@order = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
@payment_method = create(:payment_method)
payment = create(:payment, :payment_method => @payment_method, :order => @order )
@order.payments << payment
@line_item = create(:line_item, :product => product, :order => @order)
@order.line_items << @line_item
end
it "should return a header row describing the report" do
subject = OrderAndDistributorReport.new [@order]
header = subject.header
header.should == ["Order date", "Order Id",
"Customer Name","Customer Email", "Customer Phone", "Customer City",
"SKU", "Item name", "Variant", "Quantity", "Max Quantity", "Cost", "Shipping cost",
"Payment method",
"Distributor", "Distributor address", "Distributor city", "Distributor postcode", "Shipping instructions"]
end
it "should denormalise order and distributor details for display as csv" do
subject = OrderAndDistributorReport.new [@order]
table = subject.table
table[0].should == [@order.created_at, @order.id,
@bill_address.full_name, @order.email, @bill_address.phone, @bill_address.city,
@line_item.product.sku, @line_item.product.name, @line_item.variant.options_text, @line_item.quantity, @line_item.max_quantity, @line_item.price * @line_item.quantity, @line_item.itemwise_shipping_cost,
@payment_method.name,
@distributor.name, @distributor.pickup_address.address1, @distributor.pickup_address.city, @distributor.pickup_address.zipcode, @shipping_instructions ]
end
end
end
end

Some files were not shown because too many files have changed in this diff Show More