Require customer instead of user

If a shop requires a login, then a customer needs to be logged in, not
just any user.
This commit is contained in:
Maikel Linke
2016-03-24 18:24:46 +11:00
parent 41970ecf07
commit df36386757
5 changed files with 52 additions and 14 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -1,11 +1,17 @@
- if require_login?
- if require_customer?
.row.footer-pad
.small-12.columns
.shopfront_closed_message
= t '.require_login_html',
{login: ('<a auth="login">' + t('.login') + '</a>').html_safe,
register: ('<a auth="signup">' + t('.register') + '</a>').html_safe}
= t '.require_customer_login'
- if spree_current_user.nil?
= t '.require_login_html',
{login: ('<a auth="login">' + t('.login') + '</a>').html_safe,
register: ('<a auth="signup">' + t('.register') + '</a>').html_safe}
- else
= t '.require_customer_html',
{contact: ('<a href="##contact">' + t('.contact') + '</a>').html_safe,
enterprise: current_distributor.name}
- elsif @order_cycles and @order_cycles.empty?
- if current_distributor.preferred_shopfront_closed_message.present?
.row

View File

@@ -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"

View File

@@ -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