Sha256: 0cad94cd1a5204c5b99a77b7d91225454db9f5854b13f1909a3b3781a8a66e6a

Contents?: true

Size: 1.78 KB

Versions: 62

Compression:

Stored size: 1.78 KB

Contents

module Workarea
  module Storefront
    class CartsController < Storefront::ApplicationController
      include CheckInventory
      include CheckPricingOverride

      before_action :remove_unpurchasable_items
      before_action :check_pricing_override, only: :add_promo_code
      after_action :check_inventory, except: :show

      def show
        Pricing.perform(current_order, current_shippings)
        @cart = CartViewModel.new(current_order, view_model_options)
      end

      def add_promo_code
        if Pricing.valid_promo_code?(params[:promo_code], current_checkout.email)
          current_order.add_promo_code(params[:promo_code])
          flash[:success] = t(
            'workarea.storefront.flash_messages.promo_code_added',
            promo_code: params[:promo_code]
          )

          redirect_to promo_code_destination
        else
          flash[:error] = t('workarea.storefront.flash_messages.promo_code_error')
          redirect_to "#{promo_code_destination}?#{params[:promo_code].to_query(:promo_code)}"
        end
      end

      def resume
        if order = Order.find_by(token: params[:token]) rescue nil
          self.current_order = order
          flash[:success] = t('workarea.storefront.flash_messages.order_resumed')
        else
          flash[:error] = t('workarea.storefront.flash_messages.order_not_resumed')
        end

        redirect_to cart_path
      end

      private

      def remove_unpurchasable_items
        cleaner = CartCleaner.new(current_order)
        cleaner.clean
        flash[:info] = cleaner.messages if cleaner.message?
      end

      def promo_code_destination
        uri = URI.parse(
          params[:return_to].presence ||
          request.referer.presence ||
          cart_path
        )

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