mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Redirecting if cart is empty and activating the empty cart link
This commit is contained in:
@@ -11,6 +11,16 @@ Spree::OrdersController.class_eval do
|
||||
include OrderCyclesHelper
|
||||
layout 'darkswarm'
|
||||
|
||||
# Patching to redirect to shop if order is empty
|
||||
def edit
|
||||
@order = current_order(true)
|
||||
if @order.line_items.empty?
|
||||
redirect_to main_app.shop_path
|
||||
else
|
||||
associate_user
|
||||
end
|
||||
end
|
||||
|
||||
# Patch Orders#populate to populate multi_cart (if enabled)
|
||||
def populate
|
||||
if OpenFoodNetwork::FeatureToggle.enabled? :multi_cart
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
%td#empty-cart
|
||||
/ This needs help from Will - would like a link not button
|
||||
%span#clear_cart_link{"data-hook" => ""}
|
||||
= form_tag empty_cart_path, :method => :put do
|
||||
= submit_tag t(:empty_cart), :class => 'button alert expand small'
|
||||
= link_to "Empty cart", empty_cart_path, method: :put
|
||||
-#= form_tag empty_cart_path, :method => :put do
|
||||
-#= submit_tag t(:empty_cart), :class => 'button alert expand small'
|
||||
|
||||
= render "spree/orders/adjustments" unless @order.adjustments.eligible.blank?
|
||||
|
||||
@@ -2,12 +2,23 @@ require 'spec_helper'
|
||||
|
||||
describe Spree::OrdersController do
|
||||
let(:distributor) { double(:distributor) }
|
||||
let(:order) { create(:order) }
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
|
||||
it "redirects home when no distributor is selected" do
|
||||
spree_get :edit
|
||||
response.should redirect_to root_path
|
||||
end
|
||||
|
||||
it "redirects to shop when order is empty" do
|
||||
controller.stub(:current_distributor).and_return(distributor)
|
||||
controller.stub(:current_order_cycle).and_return(order_cycle)
|
||||
controller.stub(:current_order).and_return order
|
||||
order.stub_chain(:line_items, :empty?).and_return true
|
||||
spree_get :edit
|
||||
response.should redirect_to shop_path
|
||||
end
|
||||
|
||||
it "redirects to the shop when no order cycle is selected" do
|
||||
controller.stub(:current_distributor).and_return(distributor)
|
||||
spree_get :edit
|
||||
|
||||
Reference in New Issue
Block a user