solidus_starter_frontend icon indicating copy to clipboard operation
solidus_starter_frontend copied to clipboard

Swap billing/shipping address in the address step

Open kennyadsl opened this issue 5 years ago • 7 comments

We currently use a non-common use case and we should swap the addresses which is the most common use case.

kennyadsl avatar Oct 23 '20 09:10 kennyadsl

@kennyadsl @ChristianRimondi @blocknotes we should discuss if this is an issue with Solidus and if it should be addressed there. Otherwise, treating it inside this gem requires the Order model decoration.

aleph1ow avatar Nov 13 '20 14:11 aleph1ow

What's the change needed in the Order model?

kennyadsl avatar Nov 13 '20 14:11 kennyadsl

  module SwapAddressForms
    def self.prepended(base)
      base.before_validation :assign_shipping_to_billing_address, if: :use_shipping?
      attr_accessor :use_shipping
    end

    def assign_shipping_to_billing_address
      self.bill_address = ship_address if ship_address
      true
    end

    def use_shipping?
      use_shipping.in?([true, 'true', '1'])
    end

    Spree::Order.prepend self
  end
end

aleph1ow avatar Nov 13 '20 14:11 aleph1ow

👍 thanks, let's think of a way to add support for this in core.

kennyadsl avatar Nov 13 '20 14:11 kennyadsl

I had an idea here: in Solidus core, we could change the preference name from use_shipping to same_shipping_and_billing and allow this accessor to be set on both billing and shipping address, this way we could just let user's frontends to choose where to put that checkbox and adapt the backend core to work accordingly.

kennyadsl avatar Nov 16 '20 07:11 kennyadsl

This issue has been automatically marked as stale because it has not had recent activity. It might be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 11 '22 10:11 stale[bot]