Sha256: e24bfb7e941120b9ad5abee496b3d33f89be949dda29069467fc99e6507f0507

Contents?: true

Size: 1.63 KB

Versions: 26

Compression:

Stored size: 1.63 KB

Contents

module Workarea
  module Storefront
    module Checkout
      class AddressesController < CheckoutsController
        after_action :validate_shipping_options, only: :update_addresses

        # GET /checkout/addresses
        def addresses
          @step ||= Storefront::Checkout::AddressesViewModel.new(
            addresses_step,
            view_model_options
          )
        end

        # PATCH /checkout/addresses
        def update_addresses
          addresses_step.update(params)

          if addresses_step.complete?
            completed_addresses_step
          else
            incomplete_addresses_step
          end
        end

        private

        def addresses_step
          @addresses_step ||= Workarea::Checkout::Steps::Addresses.new(current_checkout)
        end

        def completed_addresses_step
          flash[:success] = t('workarea.storefront.flash_messages.addresses_saved')

          if current_order.requires_shipping?
            redirect_to checkout_shipping_path
          else
            Workarea::Checkout::Steps::Shipping.new(current_checkout).update
            redirect_to checkout_payment_path
          end
        end

        def incomplete_addresses_step
          addresses
          render :addresses
        end

        def validate_shipping_options
          return unless current_order.requires_shipping?

          available_options = Workarea::Storefront::CartViewModel.new(current_order).shipping_options

          if available_options.empty?
            flash[:error] = t('workarea.storefront.flash_messages.no_available_shipping_options')
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
workarea-storefront-3.5.27 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.26 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.45 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.25 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.23 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.44 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.22 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.43 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.21 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.42 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.20 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.41 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.19 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.40 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.18 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.39 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.17 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.38 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.5.16 app/controllers/workarea/storefront/checkout/addresses_controller.rb
workarea-storefront-3.4.37 app/controllers/workarea/storefront/checkout/addresses_controller.rb