mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding preferences to enterprises for sorting of order cycles in shopfront list
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user