Class: Spree::VariantPresenter
- Inherits:
-
Object
- Object
- Spree::VariantPresenter
- Includes:
- BaseHelper, ProductsHelper
- Defined in:
- app/presenters/spree/variant_presenter.rb
Instance Attribute Summary collapse
-
#current_currency ⇒ Object
readonly
Returns the value of attribute current_currency.
-
#current_price_options ⇒ Object
readonly
Returns the value of attribute current_price_options.
-
#current_store ⇒ Object
readonly
Returns the value of attribute current_store.
Instance Method Summary collapse
- #call ⇒ Object
- #images(variant) ⇒ Object
-
#initialize(opts = {}) ⇒ VariantPresenter
constructor
A new instance of VariantPresenter.
- #option_values(variant) ⇒ Object
Methods included from ProductsHelper
#available_status, #cache_key_for_product, #cache_key_for_products, #common_product_cache_keys, #default_variant, #limit_description, #line_item_description_text, #product_available_in_currency?, #product_images, #product_relation_types, #product_relations_by_type, #product_variants_matrix, #related_products, #should_display_compare_at_price?, #used_variants_options, #variant_full_price, #variant_price, #variant_price_diff
Methods included from BaseHelper
#all_countries, #available_countries, #base_cache_key, #default_image_for_product, #default_image_for_product_or_variant, #display_compare_at_price, #display_price, #frontend_available?, #link_to_tracking, #logo, #maximum_quantity, #meta_data, #meta_data_tags, #method_missing, #object, #og_meta_data, #og_meta_data_tags, #pretty_date, #pretty_time, #seo_url, #spree_class_name_as_path, #spree_favicon_path, #spree_resource_path, #spree_storefront_resource_url
Constructor Details
#initialize(opts = {}) ⇒ VariantPresenter
Returns a new instance of VariantPresenter.
9 10 11 12 13 14 15 |
# File 'app/presenters/spree/variant_presenter.rb', line 9 def initialize(opts = {}) @variants = opts[:variants] @is_product_available_in_currency = opts[:is_product_available_in_currency] @current_currency = opts[:current_currency] @current_price_options = opts[:current_price_options] @current_store = opts[:current_store] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Spree::BaseHelper
Instance Attribute Details
#current_currency ⇒ Object (readonly)
Returns the value of attribute current_currency.
7 8 9 |
# File 'app/presenters/spree/variant_presenter.rb', line 7 def current_currency @current_currency end |
#current_price_options ⇒ Object (readonly)
Returns the value of attribute current_price_options.
7 8 9 |
# File 'app/presenters/spree/variant_presenter.rb', line 7 def @current_price_options end |
#current_store ⇒ Object (readonly)
Returns the value of attribute current_store.
7 8 9 |
# File 'app/presenters/spree/variant_presenter.rb', line 7 def current_store @current_store end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/presenters/spree/variant_presenter.rb', line 17 def call @variants.map do |variant| { display_price: display_price(variant), price: variant.price_in(current_currency), display_compare_at_price: display_compare_at_price(variant), should_display_compare_at_price: should_display_compare_at_price?(variant), is_product_available_in_currency: @is_product_available_in_currency, backorderable: backorderable?(variant), in_stock: in_stock?(variant), images: images(variant), option_values: option_values(variant), }.merge( variant_attributes(variant) ) end end |
#images(variant) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/presenters/spree/variant_presenter.rb', line 35 def images(variant) variant.images.map do |image| { alt: image.alt, url_product: rails_representation_url(image.url(:product), only_path: true) } end end |
#option_values(variant) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/presenters/spree/variant_presenter.rb', line 44 def option_values(variant) variant.option_values.map do |option_value| { id: option_value.id, name: option_value.name, presentation: option_value.presentation, } end end |