Sha256: f6bac7ffc2adb14e4ebb0e2881b4593e05fb38c3641eea7d1645e9b57e09b440

Contents?: true

Size: 859 Bytes

Versions: 1

Compression:

Stored size: 859 Bytes

Contents

module Shopper
  class CartController < ShopperController
    respond_to :js, only: [:add_product]

    def show
      present CartPage::CartPresenter.new(current_order)
    end

    def update
      CartPage::UpdateCart.call(params, current_order) do
        on(:invalid_coupon)  { flash[:error] = 'Invalid coupon code' }
        on(:invalid_product) { flash[:error] = 'Invalid product quantity' }
        on(:validate) do |*attr|
          present CartPage::CartPresenter.new(*attr)
          render 'show'
        end
        on(:ok) { redirect_to cart_path, flash: { success: 'Cart was updated successfully'  } }
      end
    end

    def add_product
      CartPage::AddProduct.call(params) do
        on(:invalid_product) do
          redirect_to main_app.root_path, flash: { error: 'Invalid product' }, js: true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppper-0.1.0 app/controllers/shopper/cart_controller.rb