mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Show hubs as unavailable when they do not have available payment and shipping methods
This commit is contained in:
@@ -13,6 +13,6 @@ class BaseController < ApplicationController
|
||||
before_filter :check_order_cycle_expiry
|
||||
|
||||
def load_active_distributors
|
||||
@active_distributors ||= Enterprise.distributors_with_active_order_cycles
|
||||
@active_distributors ||= Enterprise.distributors_with_active_order_cycles.ready_for_checkout
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,7 +65,13 @@ class Enterprise < ActiveRecord::Base
|
||||
scope :visible, where(:visible => true)
|
||||
scope :confirmed, where('confirmed_at IS NOT NULL')
|
||||
scope :unconfirmed, where('confirmed_at IS NULL')
|
||||
scope :activated, where('confirmed_at IS NOT NULL AND sells <> \'unspecified\'')
|
||||
scope :activated, where("confirmed_at IS NOT NULL AND sells != 'unspecified'")
|
||||
scope :ready_for_checkout, lambda {
|
||||
joins(:shipping_methods).
|
||||
joins(:payment_methods).
|
||||
merge(Spree::PaymentMethod.available).
|
||||
select('DISTINCT enterprises.*')
|
||||
}
|
||||
scope :is_primary_producer, where(:is_primary_producer => true)
|
||||
scope :is_distributor, where('sells != ?', 'none')
|
||||
scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') }
|
||||
|
||||
@@ -24,6 +24,13 @@ Spree::PaymentMethod.class_eval do
|
||||
|
||||
scope :by_name, order('spree_payment_methods.name ASC')
|
||||
|
||||
# Rewrite Spree's ruby-land class method as a scope
|
||||
scope :available, lambda { |display_on='both'|
|
||||
where(active: true).
|
||||
where('spree_payment_methods.display_on=? OR spree_payment_methods.display_on=? OR spree_payment_methods.display_on IS NULL', display_on, '').
|
||||
where('spree_payment_methods.environment=? OR spree_payment_methods.environment=? OR spree_payment_methods.environment IS NULL', Rails.env, '')
|
||||
}
|
||||
|
||||
def has_distributor?(distributor)
|
||||
self.distributors.include?(distributor)
|
||||
end
|
||||
|
||||
@@ -167,6 +167,32 @@ describe Enterprise do
|
||||
end
|
||||
end
|
||||
|
||||
describe "ready_for_checkout" do
|
||||
let!(:e) { create(:enterprise) }
|
||||
|
||||
it "does not show enterprises with no payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
Enterprise.ready_for_checkout.should_not include e
|
||||
end
|
||||
|
||||
it "does not show enterprises with no shipping methods" do
|
||||
create(:payment_method, distributors: [e])
|
||||
Enterprise.ready_for_checkout.should_not include e
|
||||
end
|
||||
|
||||
it "does not show enterprises with unavailable payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e], active: false)
|
||||
Enterprise.ready_for_checkout.should_not include e
|
||||
end
|
||||
|
||||
it "shows enterprises with available payment and shipping methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e])
|
||||
Enterprise.ready_for_checkout.should include e
|
||||
end
|
||||
end
|
||||
|
||||
describe "distributors_with_active_order_cycles" do
|
||||
it "finds active distributors by order cycles" do
|
||||
s = create(:supplier_enterprise)
|
||||
|
||||
Reference in New Issue
Block a user