diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 392e2fef64..9d2c3cff85 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -17,6 +17,7 @@ class BaseController < ApplicationController def set_order_cycles @order_cycles = OrderCycle.with_distributor(@distributor).active + .order(@distributor.preferred_shopfront_order_cycle_order) # And default to the only order cycle if there's only the one if @order_cycles.count == 1 diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 5afa2eece8..34a5d22f5b 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -6,6 +6,7 @@ class Enterprise < ActiveRecord::Base preference :shopfront_message, :text, default: "" preference :shopfront_closed_message, :text, default: "" preference :shopfront_taxon_order, :string, default: "" + preference :shopfront_order_cycle_order, :string, default: "orders_close_at" devise :confirmable, reconfirmable: true, confirmation_keys: [ :id, :email ] handle_asynchronously :send_confirmation_instructions diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index c686aa9f69..8f955bdae2 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -1,7 +1,7 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids attributes :producer_profile_only, :email, :long_description, :permalink - attributes :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order + attributes :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order attributes :owner, :users has_one :owner, serializer: Api::Admin::UserSerializer diff --git a/app/views/admin/enterprises/form/_shop_preferences.html.haml b/app/views/admin/enterprises/form/_shop_preferences.html.haml index f528bb35f0..3085727f85 100644 --- a/app/views/admin/enterprises/form/_shop_preferences.html.haml +++ b/app/views/admin/enterprises/form/_shop_preferences.html.haml @@ -22,3 +22,14 @@ (top to bottom) .eight.columns.omega %textarea.fullwidth{ id: 'enterprise_preferred_shopfront_taxon_order', name: 'enterprise[preferred_shopfront_taxon_order]', rows: 6, 'ng-model' => 'Enterprise.preferred_shopfront_taxon_order', 'ofn-taxon-autocomplete' => '', 'multiple-selection' => 'true', placeholder: 'Category' } + +.row + .alpha.eleven.columns + .three.columns.alpha + = f.label "enterprise_preferred_shopfront_order_cycle_order", t(:sort_order_cycles_on_shopfront_by) + .three.columns + = radio_button :enterprise, :preferred_shopfront_order_cycle_order, :orders_open_at, { 'ng-model' => 'Enterprise.preferred_shopfront_order_cycle_order' } + = label :enterprise, :preferred_shopfront_order_cycle_order_orders_open_at, "Open Date" + .five.columns.omega + = radio_button :enterprise, :preferred_shopfront_order_cycle_order, :orders_close_at, { 'ng-model' => 'Enterprise.preferred_shopfront_order_cycle_order' } + = label :enterprise, :preferred_shopfront_order_cycle_order_orders_close_at, "Close Date" diff --git a/config/locales/en.yml b/config/locales/en.yml index 368ae4b273..373440ebfe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,6 +31,8 @@ en: confirm_resend_order_confirmation: "Are you sure you want to resend the order confirmation email?" must_have_valid_business_number: "%{enterprise_name} must have a valid ABN before invoices can be sent." + sort_order_cycles_on_shopfront_by: "Sort Order Cycles On Shopfront By" + # Printable Invoice Columns invoice_column_item: "Item" invoice_column_qty: "Qty" diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 1d9cb2eb9c..b3cb6b5e32 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -6,8 +6,8 @@ describe EnterprisesController do before(:each) do @current_distributor = create(:distributor_enterprise, with_payment_and_shipping: true) @distributor = create(:distributor_enterprise, with_payment_and_shipping: true) - @order_cycle1 = create(:simple_order_cycle, distributors: [@distributor]) - @order_cycle2 = create(:simple_order_cycle, distributors: [@distributor]) + @order_cycle1 = create(:simple_order_cycle, distributors: [@distributor], orders_open_at: 2.days.ago, orders_close_at: 3.days.from_now ) + @order_cycle2 = create(:simple_order_cycle, distributors: [@distributor], orders_open_at: 3.days.ago, orders_close_at: 4.days.from_now ) controller.current_order(true).distributor = @current_distributor end @@ -18,6 +18,16 @@ describe EnterprisesController do controller.current_order.order_cycle.should be_nil end + it "sorts order cycles by the distributor's preferred ordering attr" do + @distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_close_at') + spree_get :shop, {id: @distributor} + assigns(:order_cycles).should == [@order_cycle1, @order_cycle2].sort_by(&:orders_close_at) + + @distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_open_at') + spree_get :shop, {id: @distributor} + assigns(:order_cycles).should == [@order_cycle1, @order_cycle2].sort_by(&:orders_open_at) + end + it "empties an order that was set for a previous distributor, when shopping at a new distributor" do line_item = create(:line_item) controller.current_order.line_items << line_item diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index d96eda7bfc..aed96b5a91 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -153,6 +153,8 @@ feature %q{ # shopfront_message = find :css, "text-angular#enterprise_preferred_shopfront_message div.ta-scroll-window div.ta-bind" # shopfront_message.set 'This is my shopfront message.' page.first("input[name='enterprise\[preferred_shopfront_message\]']", visible: false).set('This is my shopfront message.') + page.should have_checked_field "enterprise_preferred_shopfront_order_cycle_order_orders_close_at" + choose "enterprise_preferred_shopfront_order_cycle_order_orders_open_at" click_button 'Update' @@ -178,6 +180,7 @@ feature %q{ click_link "Shop Preferences" page.should have_content 'This is my shopfront message.' + page.should have_checked_field "enterprise_preferred_shopfront_order_cycle_order_orders_open_at" end describe "producer properties" do