diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee index a0ba6f4e29..accfcaec9a 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee @@ -1,16 +1,11 @@ -Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout) -> +Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout, CurrentHub) -> $scope.accordion = details: true shipping: false payment: false billing: false - storage.bind $scope, "accordion", {storeName: "accordion_#{$scope.order.id}"} + storage.bind $scope, "accordion", {storeName: "accordion_#{$scope.order.id}#{CurrentHub.id}#{$scope.order.user_id}"} $scope.show = (name)-> $scope.accordion[name] = true - #$timeout => - #if $scope.checkout.$valid - #for k, v of $scope.accordion - #$scope.accordion[k] = false - diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee index dcc397396c..b8dec8b190 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/billing_controller.js.coffee @@ -8,4 +8,4 @@ Darkswarm.controller "BillingCtrl", ($scope, $timeout) -> $scope.order.bill_address.city, $scope.order.bill_address.zipcode] - #$timeout $scope.onTimeout + $timeout $scope.onTimeout diff --git a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee index b2e93b5c9b..0b29180b57 100644 --- a/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/empties_cart.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation) -> +Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation, storage) -> restrict: "A" scope: hub: '=ofnEmptiesCart' @@ -10,6 +10,7 @@ Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation) -> elm.bind 'click', (ev)-> ev.preventDefault() if confirm "Are you sure? This will change your selected Hub and remove any items in you shopping cart." + storage.clearAll() # One day this will have to be moar GRANULAR Navigation.go scope.hub.path else scope.action = attr.shop diff --git a/app/assets/javascripts/darkswarm/directives/flash.js.coffee b/app/assets/javascripts/darkswarm/directives/flash.js.coffee index 454c3304bd..a302a2a891 100644 --- a/app/assets/javascripts/darkswarm/directives/flash.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/flash.js.coffee @@ -1,10 +1,11 @@ -Darkswarm.directive "ofnFlash", (flash, $timeout)-> +Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)-> + # Mappings between flash types (left) and Foundation classes typePairings = - info: "standard" + info: "info" error: "alert" success: "success" scope: {} - restrict: 'AE' + restrict: 'E' templateUrl: "flash.html" controller: ($scope)-> $scope.closeAlert = (index)-> @@ -21,3 +22,4 @@ Darkswarm.directive "ofnFlash", (flash, $timeout)-> $scope.flashes.shift() flash.subscribe(show) + RailsFlashLoader.initFlash() diff --git a/app/assets/javascripts/darkswarm/services/current_order.js.coffee b/app/assets/javascripts/darkswarm/services/current_order.js.coffee index 9d8cbda9ef..03c9e2819c 100644 --- a/app/assets/javascripts/darkswarm/services/current_order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/current_order.js.coffee @@ -2,5 +2,7 @@ Darkswarm.factory 'CurrentOrder', (currentOrder) -> new class CurrentOrder constructor: -> @[k] = v for k, v of currentOrder + @cart_count ?= 0 + empty: => @line_items.length == 0 diff --git a/app/assets/javascripts/darkswarm/services/flash.js.coffee b/app/assets/javascripts/darkswarm/services/flash.js.coffee deleted file mode 100644 index 2be131da1d..0000000000 --- a/app/assets/javascripts/darkswarm/services/flash.js.coffee +++ /dev/null @@ -1,9 +0,0 @@ -Darkswarm.factory 'Flash', (flash)-> - new class Flash - loadFlash: (rails_flash)-> - for type, message of rails_flash - switch type - when "notice" - flash.info = message - else - flash[type] = message diff --git a/app/assets/javascripts/darkswarm/services/map.js.coffee b/app/assets/javascripts/darkswarm/services/map.js.coffee index a59631a741..3405db592d 100644 --- a/app/assets/javascripts/darkswarm/services/map.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map.js.coffee @@ -6,6 +6,7 @@ Darkswarm.factory "OfnMap", (enterprisesForMap, MapModal)-> # Adding methods to each enterprise extend: (enterprise)-> new class MapMarker +<<<<<<< HEAD icon: "/test.opng" constructor: -> @[k] = v for k, v of enterprise @@ -13,4 +14,9 @@ Darkswarm.factory "OfnMap", (enterprisesForMap, MapModal)-> reveal: => console.log @ +======= + constructor: -> + @[k] = v for k, v of enterprise + reveal: => +>>>>>>> master MapModal.open @ diff --git a/app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee b/app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee new file mode 100644 index 0000000000..9398b5f5cc --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee @@ -0,0 +1,7 @@ +Darkswarm.factory 'RailsFlashLoader', (flash, railsFlash)-> + new class RailsFlashLoader + initFlash: -> + @loadFlash railsFlash + loadFlash: (rails_flash)-> + for type, message of rails_flash + flash[type] = message diff --git a/app/assets/javascripts/templates/map_modal.html.haml b/app/assets/javascripts/templates/map_modal.html.haml index 4e2067f7d0..54c834253a 100644 --- a/app/assets/javascripts/templates/map_modal.html.haml +++ b/app/assets/javascripts/templates/map_modal.html.haml @@ -2,7 +2,8 @@ .small-12.columns.producer-hero %h3.producer-name %i.ofn-i_036-producers - {{ producer.name }} + {{ enterprise.name }} + {{ enterprise.id }} %img.producer-hero-img{"ng-src" => "{{enterprise.promo_image}}"} .row diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a19f92c918..07e1029991 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,7 +37,7 @@ class ApplicationController < ActionController::Base session[:expired_order_cycle_id] = current_order_cycle.id current_order.empty! current_order.set_order_cycle! nil - flash[:notice] = "The order cycle you've selected has just closed. Please try again!" + flash[:info] = "The order cycle you've selected has just closed. Please try again!" redirect_to root_url end end diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index b0cdeebba2..998f0ceeea 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -35,7 +35,7 @@ class CheckoutController < Spree::CheckoutController end end if @order.state == "complete" || @order.completed? - flash.notice = t(:order_processed_successfully) + flash[:success] = t(:order_processed_successfully) respond_to do |format| format.html do respond_with(@order, :location => order_path(@order)) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 31ea232976..038b5dd1b0 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -356,19 +356,12 @@ Spree::Admin::ReportsController.class_eval do end params[:q][:meta_sort] ||= "completed_at.desc" - q = params[:q].dup - if q[:order_cycle_id_eq] == '-1' - q[:order_cycle_id_null] = true - q[:order_cycle_id_eq] = nil - end - # -- Search - @search = Spree::Order.complete.not_state(:canceled).managed_by(spree_current_user).search(q) - + @search = Spree::Order.complete.not_state(:canceled).managed_by(spree_current_user).search(params[:q]) orders = @search.result @line_items = orders.map do |o| lis = o.line_items.managed_by(spree_current_user) - lis = lis.supplied_by(params[:supplier_id]) if params[:supplier_id].present? + lis = lis.supplied_by_any(params[:supplier_id_in]) if params[:supplier_id_in].present? lis end.flatten #payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments @@ -393,7 +386,7 @@ Spree::Admin::ReportsController.class_eval do table_items = @line_items @include_blank = 'All' - header = ["Supplier", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Status", "Incoming Transport"] + header = ["Producer", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Status", "Incoming Transport"] columns = [ proc { |line_items| line_items.first.variant.product.supplier.name }, proc { |line_items| line_items.first.variant.product.name }, @@ -415,7 +408,7 @@ Spree::Admin::ReportsController.class_eval do table_items = @line_items @include_blank = 'All' - header = ["Supplier", "Product", "Variant", "To Distributor", "Amount", "Curr. Cost per Unit", "Total Cost", "Shipping Method"] + header = ["Producer", "Product", "Variant", "To Hub", "Amount", "Curr. Cost per Unit", "Total Cost", "Shipping Method"] columns = [ proc { |line_items| line_items.first.variant.product.supplier.name }, proc { |line_items| line_items.first.variant.product.name }, @@ -447,7 +440,7 @@ Spree::Admin::ReportsController.class_eval do table_items = @line_items @include_blank = 'All' - header = ["Distributor", "Supplier", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Total Shipping Cost", "Shipping Method"] + header = ["Hub", "Producer", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Total Shipping Cost", "Shipping Method"] columns = [ proc { |line_items| line_items.first.order.distributor.name }, proc { |line_items| line_items.first.variant.product.supplier.name }, @@ -481,12 +474,16 @@ Spree::Admin::ReportsController.class_eval do table_items = @line_items @include_blank = 'All' - header = ["Distributor", "Customer", "Email", "Phone", "Product", "Variant", "Amount", "Item ($)", "Ship ($)", "Total ($)", "Paid?", "Packed?", "Shipped?"] + header = ["Hub", "Customer", "Email", "Phone", "Producer", "Product", "Variant", "Amount", "Item ($)", "Dist ($)", "Ship ($)", "Total ($)", "Paid?", + "Shipping", "Delivery?", "Ship street", "Ship street 2", "Ship city", "Ship postcode", "Ship state"] + + rsa = proc { |line_items| line_items.first.order.shipping_method.andand.require_ship_address } columns = [ proc { |line_items| line_items.first.order.distributor.name }, proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname }, proc { |line_items| line_items.first.order.email }, proc { |line_items| line_items.first.order.bill_address.phone }, + proc { |line_items| line_items.first.variant.product.supplier.name }, proc { |line_items| line_items.first.variant.product.name }, proc { |line_items| line_items.first.variant.options_text }, proc { |line_items| line_items.sum { |li| li.quantity } }, @@ -495,13 +492,21 @@ Spree::Admin::ReportsController.class_eval do proc { |line_items| "" }, proc { |line_items| "" }, proc { |line_items| "" }, - proc { |line_items| "" } ] + + proc { |line_items| line_items.first.order.shipping_method.andand.name }, + proc { |line_items| rsa.call(line_items) ? 'Y' : 'N' }, + proc { |line_items| line_items.first.order.ship_address.andand.address1 if rsa.call(line_items) }, + proc { |line_items| line_items.first.order.ship_address.andand.address2 if rsa.call(line_items) }, + proc { |line_items| line_items.first.order.ship_address.andand.city if rsa.call(line_items) }, + proc { |line_items| line_items.first.order.ship_address.andand.zipcode if rsa.call(line_items) }, + proc { |line_items| line_items.first.order.ship_address.andand.state if rsa.call(line_items) }] rules = [ { group_by: proc { |line_item| line_item.order.distributor }, sort_by: proc { |distributor| distributor.name } }, { group_by: proc { |line_item| line_item.order }, sort_by: proc { |order| order.bill_address.lastname + " " + order.bill_address.firstname }, - summary_columns: [ proc { |line_items| "" }, + summary_columns: [ proc { |line_items| line_items.first.order.distributor.name }, + proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname }, proc { |line_items| "" }, proc { |line_items| "" }, proc { |line_items| "" }, @@ -509,11 +514,19 @@ Spree::Admin::ReportsController.class_eval do proc { |line_items| "" }, proc { |line_items| "" }, proc { |line_items| line_items.sum { |li| li.quantity * li.price } }, + proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.distribution_total } }, proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } }, proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.total } }, - proc { |line_items| line_items.map { |li| li.order.paid? }.all? { |paid| paid == true } ? "Yes" : "No" }, + proc { |line_items| line_items.all? { |li| li.order.paid? } ? "Yes" : "No" }, + + proc { |line_items| "" }, + proc { |line_items| "" }, + proc { |line_items| "" }, + proc { |line_items| "" }, + proc { |line_items| "" }, proc { |line_items| "" }, proc { |line_items| "" } ] }, + { group_by: proc { |line_item| line_item.variant.product }, sort_by: proc { |product| product.name } }, { group_by: proc { |line_item| line_item.variant }, @@ -523,7 +536,7 @@ Spree::Admin::ReportsController.class_eval do table_items = @line_items @include_blank = 'All' - header = ["Supplier", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Status", "Incoming Transport"] + header = ["Producer", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Status", "Incoming Transport"] columns = [ proc { |line_items| line_items.first.variant.product.supplier.name }, proc { |line_items| line_items.first.variant.product.name }, diff --git a/app/controllers/user_passwords_controller.rb b/app/controllers/user_passwords_controller.rb index c46d294457..ed3be07f35 100644 --- a/app/controllers/user_passwords_controller.rb +++ b/app/controllers/user_passwords_controller.rb @@ -5,7 +5,7 @@ class UserPasswordsController < Spree::UserPasswordsController self.resource = resource_class.send_reset_password_instructions(params[resource_name]) if resource.errors.empty? - set_flash_message(:notice, :send_instructions) if is_navigational_format? + set_flash_message(:success, :send_instructions) if is_navigational_format? respond_with resource, :location => spree.login_path else respond_to do |format| diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index 3d106bbc96..a6a0074553 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -4,7 +4,7 @@ class UserRegistrationsController < Spree::UserRegistrationsController def create @user = build_resource(params[:spree_user]) if resource.save - set_flash_message(:notice, :signed_up) + set_flash_message(:success, :signed_up) sign_in(:spree_user, @user) session[:spree_user_signup] = true associate_user diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 32e25bdfc5..e5e721454a 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -1,8 +1,10 @@ module CheckoutHelper - def checkout_adjustments_for_summary(order) + def checkout_adjustments_for_summary(order, opts={}) adjustments = order.adjustments.eligible + # Remove empty tax adjustments and (optionally) shipping fees adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 } + adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if opts[:exclude_shipping] enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' } adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' } diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 32e54b6175..ba12d366be 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -18,4 +18,8 @@ Spree::LineItem.class_eval do joins(:product). where('spree_products.supplier_id = ?', enterprise) } + scope :supplied_by_any, lambda { |enterprises| + joins(:product). + where('spree_products.supplier_id IN (?)', enterprises) + } end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index d37a84ce1d..c0f4a8fb4f 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -75,6 +75,13 @@ Spree::Order.class_eval do errors.add(:distributor_id, "cannot supply the products in your cart") unless DistributionChangeValidator.new(self).can_change_to_distributor?(distributor) end end + + def empty_with_clear_shipping_and_payments! + empty_without_clear_shipping_and_payments! + payments.clear + update_attributes(shipping_method_id: nil) + end + alias_method_chain :empty!, :clear_shipping_and_payments def set_order_cycle!(order_cycle) unless self.order_cycle == order_cycle @@ -127,7 +134,11 @@ Spree::Order.class_eval do end def line_item_variants - line_items.map { |li| li.variant } + line_items.map(&:variant) + end + + def distribution_total + adjustments.eligible.where(originator_type: 'EnterpriseFee').sum(&:amount) end # Show payment methods for this distributor @@ -140,6 +151,8 @@ Spree::Order.class_eval do def available_shipping_methods(display_on = nil) Spree::ShippingMethod.all_available(self, display_on) end + + private def shipping_address_from_distributor diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index 045882ade3..bf1c20cac5 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -31,7 +31,7 @@ required: true, "ng-model" => "order.payment_method_id" = method.name - .row{"ng-show" => "order.payment_method_id == #{method.id}"} + .row{"ng-if" => "order.payment_method_id == #{method.id}"} .small-12.columns = render partial: "spree/checkout/payment/#{method.method_type}", :locals => { :payment_method => method } diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index c943964a9f..47f9239839 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -7,7 +7,7 @@ %th Produce %td= current_order.display_item_total - - checkout_adjustments_for_summary(current_order).each do |adjustment| + - checkout_adjustments_for_summary(current_order, exclude_shipping: true).each do |adjustment| %tr %th= adjustment.label %td= adjustment.display_amount.to_html diff --git a/app/views/json/_flash.rabl b/app/views/json/_flash.rabl new file mode 100644 index 0000000000..dce07f849a --- /dev/null +++ b/app/views/json/_flash.rabl @@ -0,0 +1,2 @@ +object OpenStruct.new(flash) +attributes :info, :success, :error diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 3f216e4263..8911d0a492 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -21,12 +21,12 @@ = inject_json "currentHub", "current_hub" = inject_json "currentOrder", "current_order" = inject_json "user", "current_user" + = inject_json "railsFlash", "flash" .off-canvas-wrap{offcanvas: true} .inner-wrap = render partial: "shared/menu/menu" - = display_flash_messages %ofn-flash %section{ role: "main" } diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index 70a1745e5e..49e82d2632 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -13,7 +13,7 @@ %span.nav-primary Hubs %li.divider %li - %a{href: map_path} + %a{href: main_app.map_path} %span.nav-primary Map %li.divider %li diff --git a/app/views/shared/menu/_mobile_menu.html.haml b/app/views/shared/menu/_mobile_menu.html.haml index e038c19eaf..22e65030b0 100644 --- a/app/views/shared/menu/_mobile_menu.html.haml +++ b/app/views/shared/menu/_mobile_menu.html.haml @@ -36,7 +36,7 @@ %i.ofn-i_040-hub Hubs %li - %a{href: ""} + %a{href: main_app.map_path} %span.nav-primary %i.ofn-i_037-map Map diff --git a/app/views/shopping_shared/_about.html.haml b/app/views/shopping_shared/_about.html.haml index 5e630b4d7f..232c70b519 100644 --- a/app/views/shopping_shared/_about.html.haml +++ b/app/views/shopping_shared/_about.html.haml @@ -3,7 +3,7 @@ .small-12.large-9.columns %p= current_distributor.long_description.andand.html_safe - - if current_distributor.promo_image.exists? - .small-12.large-3.columns - %img.about.right{src: current_distributor.promo_image.url(:large)} + -#- if current_distributor.promo_image.exists? + -#.small-12.large-3.columns + -#%img.about.right{src: current_distributor.promo_image.url(:large)} diff --git a/app/views/spree/admin/reports/orders_and_fulfillment.html.haml b/app/views/spree/admin/reports/orders_and_fulfillment.html.haml index 9d30ac445b..0935c24cc7 100644 --- a/app/views/spree/admin/reports/orders_and_fulfillment.html.haml +++ b/app/views/spree/admin/reports/orders_and_fulfillment.html.haml @@ -1,33 +1,39 @@ = form_for @search, :url => spree.orders_and_fulfillment_admin_reports_path do |f| - = label_tag nil, t(:date_range) - %br - .date-range-filter + .row.date-range-filter + = label_tag nil, t(:date_range) + %br = label_tag nil, t(:start), :class => 'inline' = f.text_field :completed_at_gt, :class => 'datetimepicker datepicker-from' %span.range-divider %i.icon-arrow-right = f.text_field :completed_at_lt, :class => 'datetimepicker datepicker-to' = label_tag nil, t(:end), :class => 'inline' - %br - = label_tag nil, "Distributor: " - = f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => @include_blank) - %br - = label_tag nil, "Supplier: " - = select_tag(:supplier_id, options_from_collection_for_select(@suppliers, :id, :name, params[:supplier_id]), :prompt => @include_blank) - %br - = label_tag nil, "Order Cycle: " - - order_cycles_select = [['No Order Cycle', '-1']] - - order_cycles_select += @order_cycles.collect {|oc| [ "#{oc.name}   (#{oc.orders_open_at.to_s(:short)} - #{oc.orders_close_at.to_s(:short)})".html_safe, oc.id ] } - = f.select(:order_cycle_id_eq, order_cycles_select, include_blank: @include_blank, selected: params[:q][:order_cycle_id_eq]) - %br - = label_tag nil, "Report Type: " - = select_tag(:report_type, options_for_select(@report_types, @report_type)) - %br - %br - = check_box_tag :csv - = label_tag :csv, "Download as csv" - %br + + .row + .alpha.two.columns= label_tag nil, "Hubs: " + .omega.fourteen.columns= f.collection_select(:distributor_id_in, @distributors, :id, :name, {}, {class: "select2 fullwidth", multiple: true}) + + .row + .alpha.two.columns= label_tag nil, "Producers: " + .omega.fourteen.columns= select_tag(:supplier_id_in, options_from_collection_for_select(@suppliers, :id, :name, params[:supplier_id_in]), {class: "select2 fullwidth", multiple: true}) + + .row + .alpha.two.columns= label_tag nil, "Order Cycles: " + .omega.fourteen.columns + - order_cycles_select = @order_cycles.collect {|oc| [ "#{oc.name}   (#{oc.orders_open_at.to_s(:short)} - #{oc.orders_close_at.to_s(:short)})".html_safe, oc.id ] } + = f.select(:order_cycle_id_in, order_cycles_select, {selected: params[:q][:order_cycle_id_in]}, {class: "select2 fullwidth", multiple: true}) + + .row + .alpha.two.columns= label_tag nil, "Report Type: " + .omega.fourteen.columns= select_tag(:report_type, options_for_select(@report_types, @report_type)) + + .row + = check_box_tag :csv + = label_tag :csv, "Download as csv" + + .row = button t(:search) + %br %br %table#listing_orders.index diff --git a/app/views/spree/checkout/payment/_gateway.html.haml b/app/views/spree/checkout/payment/_gateway.html.haml index 79e6725427..66b189f39b 100644 --- a/app/views/spree/checkout/payment/_gateway.html.haml +++ b/app/views/spree/checkout/payment/_gateway.html.haml @@ -1,4 +1,14 @@ .row + .small-6.columns + %label + First Name + %input{type: :text, disabled: true, "ng-value" => "order.bill_address.firstname"} + + .small-6.columns + %label + Last Name + %input{type: :text, disabled: true, "ng-value" => "order.bill_address.lastname"} + .small-6.columns = validated_input "Card Number", "secrets.card_number", required: true, maxlength: 19, autocomplete: "off" .small-6.columns @@ -13,4 +23,3 @@ %select{"ng-model" => "secrets.card_month", "ng-options" => "number as name for (number, name) in months", name: "secrets.card_month", required: true} .small-6.columns %select{"ng-model" => "secrets.card_year", "ng-options" => "year for year in years", name: "secrets.card_year", required: true} - diff --git a/config/routes.rb b/config/routes.rb index b0cf6c6f15..250bed1a5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,11 @@ Openfoodnetwork::Application.routes.draw do get "/#/login", to: "home#index", as: :spree_login - get "/map", to: "map#index", as: :map + if Rails.env.production? + get "/map", to: "home#index", as: :map + else + get "/map", to: "map#index", as: :map + end resource :shop, controller: "shop" do get :products diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb index 140259555a..8269c9374d 100644 --- a/spec/controllers/base_controller_spec.rb +++ b/spec/controllers/base_controller_spec.rb @@ -16,6 +16,6 @@ describe BaseController do oc.stub(:closed?).and_return true get :index response.should redirect_to root_url - flash[:notice].should == "The order cycle you've selected has just closed. Please try again!" + flash[:info].should == "The order cycle you've selected has just closed. Please try again!" end end diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb index 8b4d80fcab..0afe63c634 100644 --- a/spec/controllers/spree/admin/reports_controller_spec.rb +++ b/spec/controllers/spree/admin/reports_controller_spec.rb @@ -107,7 +107,7 @@ describe Spree::Admin::ReportsController do end it "only shows the selected order cycle" do - spree_get :orders_and_fulfillment, q: {order_cycle_id_eq: ocA.id} + spree_get :orders_and_fulfillment, q: {order_cycle_id_in: [ocA.id.to_s]} assigns(:search).result.should include(orderA1) assigns(:search).result.should_not include(orderB1) diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb index 8f639d94fb..bf96f9eda2 100644 --- a/spec/features/admin/enterprise_user_spec.rb +++ b/spec/features/admin/enterprise_user_spec.rb @@ -91,12 +91,12 @@ feature %q{ scenario "should not be able to see system configuration" do visit '/admin/general_settings/edit' - page.should have_content 'Authorization Failure' + page.should have_content 'Unauthorized' end scenario "should not be able to see user management" do visit '/admin/users' - page.should have_content 'Authorization Failure' + page.should have_content 'Unauthorized' end end end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index fddda4e199..8b0efea314 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -146,6 +146,21 @@ feature "As a consumer I want to check out my cart", js: true do place_order page.should have_content "Your order has been processed successfully" end + + it "shows the payment processing failed message when submitted with an invalid credit card" do + toggle_payment + fill_in 'Card Number', with: "9999999988887777" + select 'February', from: 'secrets.card_month' + select (Date.today.year+1).to_s, from: 'secrets.card_year' + fill_in 'Security Code', with: '123' + + place_order + page.should have_content "Payment could not be processed, please check the details you entered" + + # Does not show duplicate shipping fee + visit checkout_path + page.all("th", text: "Shipping").count.should == 1 + end end end end diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index 1486b92aeb..ef25d139ac 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -3,21 +3,27 @@ require 'spec_helper' module Spree describe LineItem do describe "scopes" do + let(:o) { create(:order) } + + let(:s1) { create(:supplier_enterprise) } + let(:s2) { create(:supplier_enterprise) } + + let(:p1) { create(:simple_product, supplier: s1) } + let(:p2) { create(:simple_product, supplier: s2) } + + let(:li1) { create(:line_item, order: o, product: p1) } + let(:li2) { create(:line_item, order: o, product: p2) } + it "finds line items for products supplied by a particular enterprise" do - o = create(:order) - - s1 = create(:supplier_enterprise) - s2 = create(:supplier_enterprise) - - p1 = create(:simple_product, supplier: s1) - p2 = create(:simple_product, supplier: s2) - - li1 = create(:line_item, order: o, product: p1) - li2 = create(:line_item, order: o, product: p2) - LineItem.supplied_by(s1).should == [li1] LineItem.supplied_by(s2).should == [li2] end + + it "finds line items for products supplied by one of a number of enterprises" do + LineItem.supplied_by_any([s1]).should == [li1] + LineItem.supplied_by_any([s2]).should == [li2] + LineItem.supplied_by_any([s1, s2]).sort.should == [li1, li2].sort + end end end end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 4fe1eb4f64..3a7c19d775 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -141,6 +141,37 @@ describe Spree::Order do end end + describe "getting the distribution charge" do + let(:o) { create(:order) } + let(:li) { create(:line_item, order: o) } + + it "returns the sum of eligible enterprise fee adjustments" do + ef = create(:enterprise_fee) + ef.calculator.set_preference :amount, 123.45 + a = ef.create_locked_adjustment("adjustment", li.order, li, true) + + o.distribution_total.should == 123.45 + end + + it "does not include ineligible adjustments" do + ef = create(:enterprise_fee) + ef.calculator.set_preference :amount, 123.45 + a = ef.create_locked_adjustment("adjustment", li.order, li, true) + + a.update_column :eligible, false + + o.distribution_total.should == 0 + end + + it "does not include adjustments that do not originate from enterprise fees" do + sm = create(:shipping_method) + sm.calculator.set_preference :amount, 123.45 + sm.create_adjustment("adjustment", li.order, li, true) + + o.distribution_total.should == 0 + end + end + describe "setting the distributor" do it "sets the distributor when no order cycle is set" do d = create(:distributor_enterprise) @@ -180,6 +211,22 @@ describe Spree::Order do end end + describe "emptying the order" do + it "removes shipping method" do + subject.shipping_method = create(:shipping_method) + subject.save! + subject.empty! + subject.shipping_method.should == nil + end + + it "removes payments" do + subject.payments << create(:payment) + subject.save! + subject.empty! + subject.payments.should == [] + end + end + describe "setting the order cycle" do let(:oc) { create(:simple_order_cycle) }