Sha256: 8c47e94a697851a24bb4ac939c99e7a7e7d65c603fe8ea466c1948df106dba0e

Contents?: true

Size: 1.78 KB

Versions: 62

Compression:

Stored size: 1.78 KB

Contents

module Workarea
  module Storefront
    module Checkout
      class PlaceOrderController < PaymentController
        # PATCH /checkout/place_order
        def place_order
          payment_step.update(params)

          if payment_step.complete?
            try_place_order
          else
            incomplete_place_order
          end
        end

        # GET /checkout/confirmation
        def confirmation
          redirect_to cart_path and return unless completed_order.present?

          @content = Storefront::Checkout::ConfirmationViewModel.new
          @order = Storefront::OrderViewModel.new(completed_order)
        end

        private

        def try_place_order
          if current_checkout.place_order
            completed_place_order
          else
            incomplete_place_order
          end
        end

        def completed_place_order
          OrderMailer.confirmation(current_order.id).deliver_later
          self.completed_order = current_order
          clear_current_order

          flash[:success] = t('workarea.storefront.flash_messages.order_placed')
          redirect_to finished_checkout_destination
        end

        def incomplete_place_order
          if current_checkout.shipping.try(:errors).present?
            flash[:error] = current_checkout.shipping.errors.to_a.to_sentence
            redirect_to checkout_shipping_path
          else
            flash[:error] = t('workarea.storefront.flash_messages.order_place_error')

            payment
            render :payment
          end
        end

        def finished_checkout_destination
          if current_admin.present? && current_admin.orders_access?
            admin.order_path(completed_order)
          else
            checkout_confirmation_path
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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