Sha256: 2d8b9f0afb7a6a1e4db7fd4d50f3d408f55781b7833e924c25c8558e8674d241

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

module ShopVariants
  module Tags
    module ProductVariant
      include Radiant::Taggable
      
      tag 'shop:product:variants' do |tag|
        tag.locals.shop_product_variants = Helpers.current_product_variants(tag)
        
        tag.expand
      end
      
      tag 'shop:product:variants:if_variants' do |tag|
        tag.expand if tag.locals.shop_product_variants.present?
      end
      
      tag 'shop:product:variants:unless_variants' do |tag|
        tag.expand if tag.locals.shop_product_variants.empty?
      end

      tag 'shop:product:variants:each' do |tag|
        content = ''
        
        tag.locals.shop_product_variants.each do |variant|
          tag.locals.shop_product_variant = variant
          content << tag.expand
        end
        
        content
      end
      
      tag 'shop:product:variant' do |tag|
        tag.locals.shop_product_variant = Helpers.current_product_variant(tag)
        tag.expand if tag.locals.shop_product_variant.present?
      end
      
      [:id, :name, :sku].each do |symbol|
        desc %{ outputs the #{symbol} of the current shop variant }
        tag "shop:product:variant:#{symbol}" do |tag|
          tag.locals.shop_product_variant.send(symbol)
        end
      end
      
      desc %{ output price of variant }
      tag 'shop:product:variant:price' do |tag|
        attr = tag.attr.symbolize_keys
        
        Shop::Tags::Helpers.currency(tag.locals.shop_product_variant.price,attr)
      end
      
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
radiant-shop_variants-extension-0.1.2 lib/shop_variants/tags/product_variant.rb
radiant-shop_variants-extension-0.1.1 lib/shop_variants/tags/product_variant.rb
radiant-shop_variants-extension-0.1.0 lib/shop_variants/tags/product_variant.rb
radiant-shop_variants-extension-0.0.4 lib/shop_variants/tags/product_variant.rb
radiant-shop_variants-extension-0.0.3 lib/shop_variants/tags/product_variant.rb
radiant-shop_variants-extension-0.0.1 lib/shop_variants/tags/product_variant.rb