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.4.27 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.5.4 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.26 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.5.3 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.25 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.5.2 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.24 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.5.1 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.23 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.22 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.5.0 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.21 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.5.0.beta.1 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.20 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.19 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.18 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.17 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.16 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.15 app/controllers/workarea/storefront/carts_controller.rb
workarea-storefront-3.4.14 app/controllers/workarea/storefront/carts_controller.rb