diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb
index eb2643820f..ed2facd86f 100644
--- a/app/helpers/shop_helper.rb
+++ b/app/helpers/shop_helper.rb
@@ -8,7 +8,7 @@ module ShopHelper
end
end
- def require_login?
- current_distributor.require_login? && spree_current_user.nil?
+ def require_customer?
+ current_distributor.require_login? and not spree_current_user.andand.customer_of current_distributor
end
end
diff --git a/app/views/enterprises/shop.html.haml b/app/views/enterprises/shop.html.haml
index 980cb2b3b0..d635f68164 100644
--- a/app/views/enterprises/shop.html.haml
+++ b/app/views/enterprises/shop.html.haml
@@ -22,7 +22,7 @@
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ofn-change-order-cycle" => true,
- "disabled" => require_login?,
+ "disabled" => require_customer?,
"ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}",
"popover-placement" => "left", "popover" => t(:enterprises_choose), "popover-trigger" => "openTrigger"}
@@ -32,7 +32,7 @@
= render partial: 'shop/messages'
- - unless require_login?
+ - unless require_customer?
.row= render partial: "shop/products/form"
= render partial: "shared/footer"
diff --git a/app/views/shop/_messages.html.haml b/app/views/shop/_messages.html.haml
index 5d98d142c5..7f5451334b 100644
--- a/app/views/shop/_messages.html.haml
+++ b/app/views/shop/_messages.html.haml
@@ -1,11 +1,17 @@
-- if require_login?
+- if require_customer?
.row.footer-pad
.small-12.columns
.shopfront_closed_message
- = t '.require_login_html',
- {login: ('' + t('.login') + '').html_safe,
- register: ('' + t('.register') + '').html_safe}
+ = t '.require_customer_login'
+ - if spree_current_user.nil?
+ = t '.require_login_html',
+ {login: ('' + t('.login') + '').html_safe,
+ register: ('' + t('.register') + '').html_safe}
+ - else
+ = t '.require_customer_html',
+ {contact: ('' + t('.contact') + '').html_safe,
+ enterprise: current_distributor.name}
- elsif @order_cycles and @order_cycles.empty?
- if current_distributor.preferred_shopfront_closed_message.present?
.row
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 6db986d7b5..40abae6dd2 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -117,7 +117,10 @@ en:
messages:
login: "login"
register: "register"
+ contact: "contact"
+ require_customer_login: "This shop is for customers only."
require_login_html: "Please %{login} if you have an account already. Otherwise, %{register} to become a customer."
+ require_customer_html: "Please %{contact} %{enterprise} to become a customer."
# Printable Invoice Columns
invoice_column_item: "Item"
diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb
index 5b8bb5881f..fe706c24ab 100644
--- a/spec/features/consumer/shopping/shopping_spec.rb
+++ b/spec/features/consumer/shopping/shopping_spec.rb
@@ -254,7 +254,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
end
end
- context "when shopping requires to login" do
+ context "when shopping requires a customer" do
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
let(:product) { create(:simple_product) }
let(:variant) { create(:variant, product: product) }
@@ -264,14 +264,43 @@ feature "As a consumer I want to shop with a distributor", js: true do
set_order_cycle(order, oc1)
distributor.require_login = true
distributor.save!
- visit shop_path
end
- it "tells us to login" do
- expect(page).to have_content "Please login"
+ context "when not logged in" do
+ it "tells us to login" do
+ visit shop_path
+ expect(page).to have_content "This shop is for customers only."
+ expect(page).to have_content "Please login"
+ expect(page).to have_no_content product.name
+ end
end
- it "does not show products" do
- expect(page).to have_no_content product.name
+
+ context "when logged in" do
+ let(:address) { create(:address, firstname: "Foo", lastname: "Bar") }
+ let(:user) { create(:user, bill_address: address, ship_address: address) }
+
+ before do
+ quick_login_as user
+ end
+
+ context "as non-customer" do
+ it "tells us to contact enterprise" do
+ visit shop_path
+ expect(page).to have_content "This shop is for customers only."
+ expect(page).to have_content "Please contact #{distributor.name}"
+ expect(page).to have_no_content product.name
+ end
+ end
+
+ context "as customer" do
+ let!(:customer) { create(:customer, user: user, enterprise: distributor) }
+
+ it "shows just products" do
+ visit shop_path
+ expect(page).to have_no_content "This shop is for customers only."
+ expect(page).to have_content product.name
+ end
+ end
end
end
end