diff --git a/.gitignore b/.gitignore index a765d6d558..9914e44161 100644 --- a/.gitignore +++ b/.gitignore @@ -31,5 +31,6 @@ public/images public/spree config/abr.yml config/heroku_env.rb +config/initializers/feature_toggle.rb NERD_tree* coverage diff --git a/Gemfile b/Gemfile index e08a434ca3..a59a16918c 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,6 @@ gem 'simple_form', :git => 'git://github.com/RohanM/simple_form.git' gem 'unicorn' gem 'bugsnag' gem 'newrelic_rpm' -gem 'spree_heroku', :git => 'git://github.com/eaterprises/spree-heroku.git' gem 'haml' gem 'sass' gem 'aws-sdk' @@ -29,6 +28,8 @@ gem 'truncate_html' gem 'representative_view' gem 'rabl' gem 'oj' +gem 'chili', :github => 'eaterprises/chili' +gem 'deface', :github => 'spree/deface' # Gems used only for assets and not required # in production environments by default. @@ -59,7 +60,14 @@ group :test, :development do gem 'database_cleaner', '0.7.1', :require => false gem 'simplecov', :require => false gem 'awesome_print' - gem "letter_opener" + gem 'letter_opener' + gem 'timecop' +end + +group :chili do + gem 'enterprises_distributor_info_rich_text_feature', path: 'lib/chili/enterprises_distributor_info_rich_text_feature' + gem 'eaterprises_feature', path: 'lib/chili/eaterprises_feature' + gem 'local_organics_feature', path: 'lib/chili/local_organics_feature' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 67067d1d8e..f61ec7a842 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,12 +7,12 @@ GIT activemodel (~> 3.0) GIT - remote: git://github.com/eaterprises/spree-heroku.git - revision: a1e07bf7a22fc0c07a1be9148f477d20b557dbf6 + remote: git://github.com/eaterprises/chili.git + revision: b82608623d504eb39f852115b138a53af5f89505 specs: - spree_heroku (1.0) - aws-sdk (~> 1.3.4) - spree_core (>= 0.70.0) + chili (3.1.0) + deface (~> 1.0.0.rc2) + rails (~> 3.2) GIT remote: git://github.com/eaterprises/spree-last-address.git @@ -22,6 +22,15 @@ GIT spree_last_address (1.1.0) spree_core (>= 1.1) +GIT + remote: git://github.com/spree/deface.git + revision: 1110a1336252109bce7f98f9182042e0bc2930ae + specs: + deface (1.0.0.rc3) + colorize (>= 0.5.8) + nokogiri (~> 1.6.0) + rails (>= 3.1) + GIT remote: git://github.com/spree/spree.git revision: 94566bf1b7d50f474333d10844534e570b6edf5a @@ -74,7 +83,7 @@ GIT GIT remote: git://github.com/spree/spree_paypal_express.git - revision: 483f6ababa9c8a1c574aad0a948c96cc21a591db + revision: 9d70ab6d537420ff41468d05d6d2ac3c8d2ff3bf branch: 1-3-stable specs: spree_paypal_express (1.2.0) @@ -91,6 +100,27 @@ GIT devise-encryptable (= 0.1.2) spree_core +PATH + remote: lib/chili/eaterprises_feature + specs: + eaterprises_feature (0.0.1) + chili (~> 3.1) + rails (~> 3.2.11) + +PATH + remote: lib/chili/enterprises_distributor_info_rich_text_feature + specs: + enterprises_distributor_info_rich_text_feature (0.0.1) + chili (~> 3.1) + rails (~> 3.2.11) + +PATH + remote: lib/chili/local_organics_feature + specs: + local_organics_feature (0.0.1) + chili (~> 3.1) + rails (~> 3.2.11) + GEM remote: https://rubygems.org/ specs: @@ -111,14 +141,14 @@ GEM active_utils (1.0.5) activesupport (>= 2.3.11) i18n - activemerchant (1.34.1) + activemerchant (1.34.0) active_utils (>= 1.0.2) activesupport (>= 2.3.14) builder (>= 2.0.0) i18n json (>= 1.5.1) money - nokogiri (< 1.6.0) + nokogiri activemodel (3.2.13) activesupport (= 3.2.13) builder (~> 3.0.0) @@ -173,6 +203,7 @@ GEM coffee-script-source execjs coffee-script-source (1.3.3) + colorize (0.5.8) columnize (0.3.6) comfortable_mexican_sofa (1.6.24) active_link_to (~> 1.0.0) @@ -189,9 +220,6 @@ GEM debugger-ruby_core_source (~> 1.2.3) debugger-linecache (1.2.0) debugger-ruby_core_source (1.2.3) - deface (0.9.1) - nokogiri (~> 1.5.0) - rails (~> 3.1) devise (2.2.4) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -251,6 +279,7 @@ GEM treetop (~> 1.4.8) method_source (0.8.1) mime-types (1.23) + mini_portile (0.5.1) money (5.0.0) i18n (~> 0.4) json @@ -260,7 +289,8 @@ GEM net-ssh (>= 2.6.5) net-ssh (2.6.8) newrelic_rpm (3.6.5.130) - nokogiri (1.5.10) + nokogiri (1.6.0) + mini_portile (~> 0.5.0) oj (2.1.2) orm_adapter (0.4.0) paperclip (2.8.0) @@ -365,6 +395,7 @@ GEM libv8 (~> 3.3.10) thor (0.18.1) tilt (1.4.1) + timecop (0.6.2.2) treetop (1.4.14) polyglot polyglot (>= 0.3.1) @@ -402,16 +433,21 @@ DEPENDENCIES aws-sdk bugsnag capybara + chili! coffee-rails (~> 3.2.1) comfortable_mexican_sofa database_cleaner (= 0.7.1) db2fog debugger-linecache + deface! + eaterprises_feature! + enterprises_distributor_info_rich_text_feature! factory_girl_rails faker haml jquery-rails letter_opener + local_organics_feature! newrelic_rpm oj pg @@ -427,11 +463,11 @@ DEPENDENCIES simplecov spree! spree_auth_devise! - spree_heroku! spree_i18n! spree_last_address! spree_paypal_express! therubyracer + timecop truncate_html turbo-sprockets-rails3 turn (~> 0.8.3) diff --git a/app/assets/images/ofw.png b/app/assets/images/ofw.png new file mode 100644 index 0000000000..ac571bacd0 Binary files /dev/null and b/app/assets/images/ofw.png differ diff --git a/app/assets/stylesheets/store/openfoodweb.css.scss b/app/assets/stylesheets/store/openfoodweb.css.scss index bf08508f82..0836ce2f07 100644 --- a/app/assets/stylesheets/store/openfoodweb.css.scss +++ b/app/assets/stylesheets/store/openfoodweb.css.scss @@ -192,6 +192,11 @@ fieldset#product-distributor-details { } } +/* Checkout address page */ +#checkout .alternative-available-distributors { + padding-top: 30px; +} + /* Delivery fees table on checkout page */ #delivery-fees { diff --git a/app/assets/stylesheets/store/variables.css.scss b/app/assets/stylesheets/store/variables.css.scss index 1332e9b238..f33a4318e9 100644 --- a/app/assets/stylesheets/store/variables.css.scss +++ b/app/assets/stylesheets/store/variables.css.scss @@ -7,7 +7,7 @@ $c_red: #e45353 !default; /* Error red */ $layout_background_color: #FFFFFF !default; $title_text_color: #404042 !default; $body_text_color: #404042 !default; -$link_text_color: #006066 !default; +$link_text_color: #00ADEE !default; $product_background_color: #FFFFFF !default; $product_title_text_color: #404042 !default; @@ -60,3 +60,5 @@ $ff_base: 'Ubuntu', sans-serif !default; $button_border_color: rgba(0, 138, 189, .75) !default; $table_head_color: lighten($body_text_color, 60) !default; + +@import "./variables_changes.css.scss"; diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 6de3fc1575..f922f39453 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -333,11 +333,11 @@ Spree::Admin::ReportsController.class_eval do if params[:q][:completed_at_gt].blank? params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month else - params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month + params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]) rescue Time.zone.now.beginning_of_month end if params[:q] && !params[:q][:completed_at_lt].blank? - params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue "" + params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]) rescue "" end params[:q][:meta_sort] ||= "completed_at.desc" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 49612546b4..938f2ee566 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -5,6 +5,31 @@ Spree::OrdersController.class_eval do before_filter :populate_order_count_on_hand, :only => :populate after_filter :populate_variant_attributes, :only => :populate + def select_distributor + distributor = Enterprise.is_distributor.find params[:id] + + order = current_order(true) + order.distributor = distributor + order.save! + + redirect_to main_app.enterprise_path(distributor) + end + + def deselect_distributor + order = current_order(true) + + order.distributor = nil + order.save! + + redirect_to root_path + end + + + private + + + # -- Callbacks + def populate_order_distributor @distributor = params[:distributor_id].present? ? Enterprise.is_distributor.find(params[:distributor_id]) : nil @@ -51,26 +76,8 @@ Spree::OrdersController.class_eval do end end - def select_distributor - distributor = Enterprise.is_distributor.find params[:id] - order = current_order(true) - order.distributor = distributor - order.save! - - redirect_to main_app.enterprise_path(distributor) - end - - def deselect_distributor - order = current_order(true) - - order.distributor = nil - order.save! - - redirect_to root_path - end - - private + # -- Utils def populate_valid? distributor # -- Distributor must be specified diff --git a/app/helpers/html_helper.rb b/app/helpers/html_helper.rb new file mode 100644 index 0000000000..85dc5b1c53 --- /dev/null +++ b/app/helpers/html_helper.rb @@ -0,0 +1,5 @@ +module HtmlHelper + def strip_html(html) + strip_tags(html).gsub(/ /i, ' ').gsub(/&/i, '&') + end +end diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb new file mode 100644 index 0000000000..1ce563ad56 --- /dev/null +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -0,0 +1,3 @@ +Spree::OrderMailer.class_eval do + helper HtmlHelper +end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 17c9380097..96f48aa111 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -27,9 +27,9 @@ class Enterprise < ActiveRecord::Base def to_param "#{id}-#{name.parameterize}" end - + def available_variants - ProductDistribution.find_all_by_distributor_id( self.id ).map{ |pd| pd.product.variants + [pd.product.master] }.flatten + Spree::Variant.joins(:product => :product_distributions).where('product_distributions.distributor_id=?', self.id) end diff --git a/app/models/spree/gateway/migs.rb b/app/models/spree/gateway/migs.rb new file mode 100644 index 0000000000..bfffc6de12 --- /dev/null +++ b/app/models/spree/gateway/migs.rb @@ -0,0 +1,19 @@ +module Spree + class Gateway::Migs < Gateway + preference :login, :string + preference :password, :string + + attr_accessible :preferred_login, :preferred_password + + + def provider_class + ActiveMerchant::Billing::MigsGateway + end + + def options_with_test_preference + options_without_test_preference.merge(:test => self.preferred_test_mode) + end + + alias_method_chain :options, :test_preference + end +end diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index aac21c1225..ec4f83e5e2 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -5,11 +5,16 @@ Spree::LineItem.class_eval do before_create :set_itemwise_shipping_method + def itemwise_shipping_cost order = OpenStruct.new :line_items => [self] shipping_method.compute_amount(order) end + def update_itemwise_shipping_method_without_callbacks!(distributor) + update_column(:shipping_method_id, self.product.shipping_method_for_distributor(distributor).id) + end + private diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 85c75771b3..f49fa307c8 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -3,13 +3,20 @@ require 'open_food_web/distributor_change_validator' Spree::Order.class_eval do belongs_to :distributor, :class_name => 'Enterprise' - before_validation :shipping_address_from_distributor validate :products_available_from_new_distributor, :if => :distributor_id_changed? attr_accessible :distributor_id + before_validation :shipping_address_from_distributor + before_save :update_line_item_shipping_methods after_create :set_default_shipping_method + def empty! + line_items.destroy_all + adjustments.destroy_all + set_default_shipping_method + end + def products_available_from_new_distributor # Check that the line_items in the current order are available from a newly selected distributor errors.add(:distributor_id, "cannot supply the products in your cart") unless DistributorChangeValidator.new(self).can_change_to_distributor?(distributor) @@ -32,7 +39,7 @@ Spree::Order.class_eval do end def line_item_variants - line_items.map{ |li| li.variant } + line_items.map { |li| li.variant } end @@ -66,4 +73,11 @@ Spree::Order.class_eval do end end end + + def update_line_item_shipping_methods + if %w(cart address delivery resumed).include? state + self.line_items.each { |li| li.update_itemwise_shipping_method_without_callbacks!(distributor) } + self.update! + end + end end diff --git a/app/overrides/add_feedback_script.rb b/app/overrides/add_feedback_script.rb deleted file mode 100644 index 1bfb854c10..0000000000 --- a/app/overrides/add_feedback_script.rb +++ /dev/null @@ -1,5 +0,0 @@ -Deface::Override.new(:virtual_path => "spree/layouts/spree_application", - :insert_bottom => "[data-hook='inside_head']", - :partial => "layouts/feedback_script", - :name => "add_feedback_script", - :original => '429dfd9824ee588f51fb1b69013933424f149592') \ No newline at end of file diff --git a/app/views/admin/enterprises/show.html.haml b/app/views/admin/enterprises/show.html.haml index a2eb9027fa..d4a4ed0743 100644 --- a/app/views/admin/enterprises/show.html.haml +++ b/app/views/admin/enterprises/show.html.haml @@ -6,7 +6,7 @@ %tr %th Description: %td= @enterprise.description - %tr + %tr{"data-hook" => "long_description"} %th Extended Description: %td= @enterprise.long_description.andand.html_safe %tr diff --git a/app/views/enterprises/_distributor_details.html.haml b/app/views/enterprises/_distributor_details.html.haml index 950ba1e7f2..a3f070b451 100644 --- a/app/views/enterprises/_distributor_details.html.haml +++ b/app/views/enterprises/_distributor_details.html.haml @@ -1,23 +1,24 @@ -%h2= distributor.name -%p - %strong Address: - %br/ - = render 'spree/shared/address', :address => distributor.address -%p - %strong Next collection time: - %br/ - = distributor.next_collection_at -%p - %strong Regular collection times: - %br/ - = distributor.pickup_times -%p - %strong Contact: - %br/ - = distributor.contact - %br/ - = "Phone: #{distributor.phone}" - %br/ - = "Email: #{distributor.email}" -%p= distributor.description -%p= link_to distributor.website, distributor.website if distributor.website +.distributor-details{'data-hook' => 'distributor-details'} + %h2= distributor.name + %p + %strong Address: + %br/ + = render 'spree/shared/address', :address => distributor.address + %p + %strong Next collection time: + %br/ + = distributor.next_collection_at + %p + %strong Regular collection times: + %br/ + = distributor.pickup_times + %p + %strong Contact: + %br/ + = distributor.contact + %br/ + = "Phone: #{distributor.phone}" + %br/ + = "Email: #{distributor.email}" + %p= distributor.description + %p= link_to distributor.website, distributor.website if distributor.website diff --git a/app/views/spree/admin/reports/order_cycles.html.haml b/app/views/spree/admin/reports/order_cycles.html.haml index 4468f1d183..e8fb54c069 100644 --- a/app/views/spree/admin/reports/order_cycles.html.haml +++ b/app/views/spree/admin/reports/order_cycles.html.haml @@ -3,11 +3,11 @@ %br .date-range-filter %div{"class" => "left sub-field"} - = f.text_field :completed_at_gt, :class => 'datepicker' + = f.text_field :completed_at_gt, :class => 'datetimepicker' %br = label_tag nil, t(:start), :class => 'sub' %div{"class" => "right sub-field"} - = f.text_field :completed_at_lt, :class => 'datepicker' + = f.text_field :completed_at_lt, :class => 'datetimepicker' %br = label_tag nil, t(:stop) %br diff --git a/app/views/spree/checkout/_other_available_distributors.html.erb b/app/views/spree/checkout/_other_available_distributors.html.erb index d9f4560cb7..358441c878 100644 --- a/app/views/spree/checkout/_other_available_distributors.html.erb +++ b/app/views/spree/checkout/_other_available_distributors.html.erb @@ -1,5 +1,5 @@ <% unless @order.state != 'address' %> -