mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Set default addresses for user or customer
This commit is contained in:
@@ -38,20 +38,21 @@ class CheckoutController < Spree::CheckoutController
|
||||
end
|
||||
end
|
||||
if @order.state == "complete" || @order.completed?
|
||||
set_default_bill_address
|
||||
set_default_ship_address
|
||||
|
||||
flash[:success] = t(:order_processed_successfully)
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
respond_with(@order, :location => order_path(@order))
|
||||
end
|
||||
format.js do
|
||||
render json: {path: order_path(@order)}, status: 200
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
respond_with(@order, :location => order_path(@order))
|
||||
end
|
||||
format.js do
|
||||
render json: {path: order_path(@order)}, status: 200
|
||||
end
|
||||
end
|
||||
else
|
||||
update_failed
|
||||
end
|
||||
|
||||
set_default_address_for_user
|
||||
else
|
||||
update_failed
|
||||
end
|
||||
@@ -60,11 +61,22 @@ class CheckoutController < Spree::CheckoutController
|
||||
|
||||
private
|
||||
|
||||
def set_default_address_for_user
|
||||
spree_current_user.set_bill_address(@order.bill_address.clone) if params[:order][:default_bill_address] == 'YES'
|
||||
spree_current_user.set_ship_address(@order.ship_address.clone) if params[:order][:default_ship_address] == 'YES'
|
||||
def set_default_bill_address
|
||||
if params[:order][:default_bill_address] == 'YES'
|
||||
new_bill_address = @order.bill_address.clone
|
||||
spree_current_user.set_bill_address(new_bill_address)
|
||||
@order.customer.update_attribute(:bill_address, new_bill_address) unless @order.customer.bill_address
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def set_default_ship_address
|
||||
if params[:order][:default_ship_address] == 'YES'
|
||||
new_ship_address = @order.ship_address.clone
|
||||
spree_current_user.set_ship_address(new_ship_address)
|
||||
@order.customer.update_attribute(:ship_address, new_ship_address) unless @order.customer.ship_address
|
||||
end
|
||||
end
|
||||
|
||||
def check_order_for_phantom_fees
|
||||
phantom_fees = @order.adjustments.joins('LEFT OUTER JOIN spree_line_items ON spree_line_items.id = spree_adjustments.source_id').
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
= t :checkout_address_same
|
||||
|
||||
- if spree_current_user
|
||||
%label
|
||||
%label{"ng-if" => "Checkout.requireShipAddress()"}
|
||||
%input{type: :checkbox, "ng-model" => "Checkout.default_ship_address", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
|
||||
= t :checkout_default_ship_address
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
within "#billing" do
|
||||
fill_in "City", with: "Melbourne"
|
||||
fill_in "Postcode", with: "3066"
|
||||
fill_in "Address", with: "123 Your Face"
|
||||
fill_in "Address", with: "123 Your Head"
|
||||
select "Australia", from: "Country"
|
||||
select "Victoria", from: "State"
|
||||
end
|
||||
@@ -98,11 +98,20 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
user.bill_address.should be_nil
|
||||
user.ship_address.should be_nil
|
||||
|
||||
order.bill_address.should be_nil
|
||||
order.ship_address.should be_nil
|
||||
|
||||
place_order
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
|
||||
user.reload.bill_address.address1.should eq '123 Your Face'
|
||||
user.reload.ship_address.address1.should eq '123 Your Face'
|
||||
order.reload.bill_address.address1.should eq '123 Your Head'
|
||||
order.reload.ship_address.address1.should eq '123 Your Head'
|
||||
|
||||
order.customer.bill_address.address1.should eq '123 Your Head'
|
||||
order.customer.ship_address.address1.should eq '123 Your Head'
|
||||
|
||||
user.reload.bill_address.address1.should eq '123 Your Head'
|
||||
user.reload.ship_address.address1.should eq '123 Your Head'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -293,10 +302,6 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
page.should have_content "Your order has been processed successfully"
|
||||
end
|
||||
|
||||
it 'sets default billing and shipping address after the order processed successfully' do
|
||||
|
||||
end
|
||||
|
||||
it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do
|
||||
Spree::Config.set allow_backorders: false
|
||||
variant.on_hand = 0
|
||||
|
||||
Reference in New Issue
Block a user