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.15 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.36 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.14 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.35 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.13 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.34 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.12 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.33 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.11 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.10 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.32 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.9 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.31 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.8 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.30 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.7 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.29 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.6 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.4.28 app/controllers/workarea/storefront/checkout/place_order_controller.rb
workarea-storefront-3.5.5 app/controllers/workarea/storefront/checkout/place_order_controller.rb