Sha256: ec10062ef18d5eb4520e45f7169a0e0c10a557f5e3cfbd7f44fdbee80e3bd287

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

module Shop
  module Tags
    module Cart
      include Radiant::Taggable
      include ActionView::Helpers::NumberHelper
      
      # Expand the shopping cart instance
      # @param [Integer] id Id of the shopping cart (ShopOrder)
      tag 'shop:cart' do |tag|
        tag.locals.shop_order = Helpers.current_order(tag)
        tag.expand
      end
      
      # Expand if a user has started a cart
      desc %{ Expand if a user has started a cart }
      tag 'shop:cart:if_cart' do |tag|
        tag.expand if tag.locals.shop_order.present?
      end
      
      # Expand unless a user has started a cart
      desc %{ Expand unless a user has started a cart }
      tag 'shop:cart:unless_cart' do |tag|
        tag.expand unless tag.locals.shop_order.present?
      end
      
      # Display the cart id / status
      [:id, :status, :quantity, :weight].each do |symbol|
        desc %{ outputs the #{symbol} to the cart }
        tag "shop:cart:#{symbol}" do |tag|
          tag.locals.shop_order.send(symbol)
        end
      end
      
      # Display the total price of the items in the shopping basket.
      desc %{ Output the total price of the items in the shopping basket. }
      tag 'shop:cart:price' do |tag|
        attr = tag.attr.symbolize_keys
        order = tag.locals.shop_order
        
        Helpers.currency(order.price,attr)
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
radiant-shop-extension-0.11.5 lib/shop/tags/cart.rb
radiant-shop-extension-0.11.4 lib/shop/tags/cart.rb
radiant-shop-extension-0.11.3 lib/shop/tags/cart.rb
radiant-shop-extension-0.11.1 lib/shop/tags/cart.rb
radiant-shop-extension-0.11.0 lib/shop/tags/cart.rb