Sha256: e53574d1764692766a9fa0b377ecff2f6e2f112c65e461959222deca2b6e5d04

Contents?: true

Size: 817 Bytes

Versions: 1

Compression:

Stored size: 817 Bytes

Contents

module Trade
  module Controller::Application
    extend ActiveSupport::Concern

    included do
      helper_method :current_cart, :current_cart_count, :current_card
    end

    def current_cart
      return @current_cart if @current_cart

      if current_user
        @current_cart = current_user.carts.find_or_create_by(default_form_params)
      end
      logger.debug "  \e[35mCurrent Trade cart: #{@current_cart&.id}\e[0m"
      @current_cart
    end

    def current_card
      platform = request.headers['OS'].to_s.downcase
      if defined?(current_user) && current_user
        current_user.init_wallet(platform)
      end
    end

    def current_cart_count
      if current_cart
        current_cart.trade_items.where(status: ['init', 'checked']).count
      else
        0
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_trade-0.0.3 app/controllers/trade/controller/application.rb