mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Set default billing address and shipping address
This commit is contained in:
@@ -14,6 +14,14 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu
|
||||
storeName: "#{prefix}_sameasbilling"
|
||||
defaultValue: 'YES'
|
||||
|
||||
storage.bind $scope, "Checkout.default_bill_address",
|
||||
storeName: "#{prefix}_defaultasbilladdress"
|
||||
defaultValue: 'NO'
|
||||
|
||||
storage.bind $scope, "Checkout.default_ship_address",
|
||||
storeName: "#{prefix}_defaultasshipaddress"
|
||||
defaultValue: 'NO'
|
||||
|
||||
$scope.order = Checkout.order # Ordering is important
|
||||
$scope.secrets = Checkout.secrets
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
|
||||
secrets: {}
|
||||
order: CurrentOrder.order
|
||||
ship_address_same_as_billing: 'YES'
|
||||
default_bill_address: 'NO'
|
||||
default_ship_address: 'NO'
|
||||
|
||||
|
||||
submit: ->
|
||||
Loading.message = t 'submitting_order'
|
||||
@@ -19,7 +22,10 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
munged_order = {}
|
||||
munged_order =
|
||||
default_bill_address: @default_bill_address
|
||||
default_ship_address: @default_ship_address
|
||||
|
||||
for name, value of @order # Clone all data from the order JSON object
|
||||
switch name
|
||||
when "bill_address"
|
||||
|
||||
@@ -50,6 +50,8 @@ class CheckoutController < Spree::CheckoutController
|
||||
else
|
||||
update_failed
|
||||
end
|
||||
|
||||
set_default_address_for_user
|
||||
else
|
||||
update_failed
|
||||
end
|
||||
@@ -58,6 +60,12 @@ 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'
|
||||
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').
|
||||
where("originator_type = 'EnterpriseFee' AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL")
|
||||
|
||||
@@ -76,6 +76,16 @@ Spree.user_class.class_eval do
|
||||
data_array.sort! { |a, b| b.distributed_orders.length <=> a.distributed_orders.length }
|
||||
end
|
||||
|
||||
def set_bill_address(address)
|
||||
self.bill_address = address
|
||||
self.save
|
||||
end
|
||||
|
||||
def set_ship_address(address)
|
||||
self.ship_address = address
|
||||
self.save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def limit_owned_enterprises
|
||||
|
||||
@@ -12,7 +12,13 @@
|
||||
%accordion-group{"is-open" => "accordion.billing",
|
||||
"ng-class" => "{valid: billing.$valid, open: accordion.billing}"}
|
||||
= render 'checkout/accordion_heading'
|
||||
|
||||
|
||||
- if spree_current_user
|
||||
.small-12.columns
|
||||
%label
|
||||
%input{type: :checkbox, "ng-model" => "Checkout.default_bill_address", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
|
||||
= t :checkout_default_bill_address
|
||||
|
||||
= f.fields_for :bill_address, @order.bill_address do |ba|
|
||||
.row
|
||||
.small-12.columns
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"ng-class" => "{valid: shipping.$valid, open: accordion.shipping}"}
|
||||
= render 'checkout/accordion_heading'
|
||||
|
||||
.small-12.columns
|
||||
.small-12.columns.medium-6.columns.large-6.columns
|
||||
%label{"ng-repeat" => "method in ShippingMethods.shipping_methods"}
|
||||
%input{type: :radio,
|
||||
required: true,
|
||||
@@ -33,6 +33,11 @@
|
||||
%input{type: :checkbox, "ng-model" => "Checkout.ship_address_same_as_billing", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
|
||||
= t :checkout_address_same
|
||||
|
||||
- if spree_current_user
|
||||
%label
|
||||
%input{type: :checkbox, "ng-model" => "Checkout.default_ship_address", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
|
||||
= t :checkout_default_ship_address
|
||||
|
||||
.small-12.columns.medium-6.columns.large-6.columns
|
||||
#distributor_address.panel{"ng-show" => "Checkout.shippingMethod().description"}
|
||||
%span{ style: "white-space: pre-wrap;" }{{ Checkout.shippingMethod().description }}
|
||||
|
||||
@@ -380,7 +380,9 @@ en:
|
||||
checkout_as_guest: "Checkout as guest"
|
||||
checkout_details: "Your details"
|
||||
checkout_billing: "Billing info"
|
||||
checkout_default_bill_address: "Save as default billing address"
|
||||
checkout_shipping: Shipping info
|
||||
checkout_default_ship_address: "Save as default shipping address"
|
||||
checkout_method_free: Free
|
||||
checkout_address_same: Shipping address same as billing address?
|
||||
checkout_ready_for: "Ready for:"
|
||||
|
||||
@@ -61,6 +61,50 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
page.should have_content "An item in your cart has become unavailable"
|
||||
end
|
||||
end
|
||||
context 'login in as user' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
quick_login_as(user)
|
||||
visit checkout_path
|
||||
|
||||
toggle_shipping
|
||||
choose sm1.name
|
||||
toggle_payment
|
||||
choose pm1.name
|
||||
toggle_details
|
||||
within "#details" do
|
||||
fill_in "First Name", with: "Will"
|
||||
fill_in "Last Name", with: "Marshall"
|
||||
fill_in "Email", with: "test@test.com"
|
||||
fill_in "Phone", with: "0468363090"
|
||||
end
|
||||
toggle_billing
|
||||
check "Save as default billing address"
|
||||
within "#billing" do
|
||||
fill_in "City", with: "Melbourne"
|
||||
fill_in "Postcode", with: "3066"
|
||||
fill_in "Address", with: "123 Your Face"
|
||||
select "Australia", from: "Country"
|
||||
select "Victoria", from: "State"
|
||||
end
|
||||
|
||||
toggle_shipping
|
||||
check "Shipping address same as billing address?"
|
||||
check "Save as default shipping address"
|
||||
end
|
||||
|
||||
it "sets user's default billing address and shipping address" do
|
||||
user.bill_address.should be_nil
|
||||
user.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'
|
||||
end
|
||||
end
|
||||
|
||||
context "on the checkout page" do
|
||||
before do
|
||||
@@ -73,6 +117,11 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
page.should have_content distributor.name
|
||||
end
|
||||
|
||||
it 'does not show the save as defalut address checkbox' do
|
||||
page.should_not have_content "Save as default billing address"
|
||||
page.should_not have_content "Save as default shipping address"
|
||||
end
|
||||
|
||||
it "shows a breakdown of the order price" do
|
||||
toggle_shipping
|
||||
choose sm2.name
|
||||
@@ -244,6 +293,10 @@ 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
|
||||
|
||||
@@ -59,10 +59,13 @@ describe "CheckoutCtrl", ->
|
||||
describe "Local storage", ->
|
||||
it "binds to localStorage when given a scope", ->
|
||||
prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}"
|
||||
console.log prefix
|
||||
|
||||
field = scope.fieldsToBind[0]
|
||||
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.order.#{field}", {storeName: "#{prefix}_#{field}"})
|
||||
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: 'YES'})
|
||||
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.default_bill_address", {storeName: "#{prefix}_defaultasbilladdress", defaultValue: 'NO'})
|
||||
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.default_ship_address", {storeName: "#{prefix}_defaultasshipaddress", defaultValue: 'NO'})
|
||||
|
||||
|
||||
it "it can retrieve data from localstorage", ->
|
||||
prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}"
|
||||
|
||||
@@ -131,6 +131,16 @@ describe 'Checkout service', ->
|
||||
Checkout.ship_address_same_as_billing = 'YES'
|
||||
expect(Checkout.preprocess().ship_address_attributes).toEqual(orderData.bill_address)
|
||||
|
||||
it "munges the default as billing address and shipping address", ->
|
||||
expect(Checkout.preprocess().default_bill_address).toEqual('NO')
|
||||
expect(Checkout.preprocess().default_ship_address).toEqual('NO')
|
||||
|
||||
Checkout.default_bill_address = 'YES'
|
||||
Checkout.default_ship_address = 'YES'
|
||||
|
||||
expect(Checkout.preprocess().default_bill_address).toEqual('YES')
|
||||
expect(Checkout.preprocess().default_ship_address).toEqual('YES')
|
||||
|
||||
it "creates attributes for card fields", ->
|
||||
source_attributes = Checkout.preprocess().payments_attributes[0].source_attributes
|
||||
expect(source_attributes).toBeDefined()
|
||||
|
||||
Reference in New Issue
Block a user