Class: SpreeCmCommissioner::HomepageDataLoader
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::HomepageDataLoader
- Includes:
- ActiveModel::Serialization
- Defined in:
- app/services/spree_cm_commissioner/homepage_data_loader.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#display_product_ids ⇒ Object
Returns the value of attribute display_product_ids.
-
#display_products ⇒ Object
Returns the value of attribute display_products.
-
#featured_brand_ids ⇒ Object
Returns the value of attribute featured_brand_ids.
-
#featured_brands ⇒ Object
Returns the value of attribute featured_brands.
-
#featured_vendor_ids ⇒ Object
Returns the value of attribute featured_vendor_ids.
-
#featured_vendors ⇒ Object
Returns the value of attribute featured_vendors.
-
#homepage_background_ids ⇒ Object
Returns the value of attribute homepage_background_ids.
-
#homepage_backgrounds ⇒ Object
Returns the value of attribute homepage_backgrounds.
-
#homepage_banner_ids ⇒ Object
Returns the value of attribute homepage_banner_ids.
-
#homepage_banners ⇒ Object
Returns the value of attribute homepage_banners.
-
#id ⇒ Object
Returns the value of attribute id.
-
#top_categories ⇒ Object
Returns the value of attribute top_categories.
-
#top_category_ids ⇒ Object
Returns the value of attribute top_category_ids.
-
#trending_categories ⇒ Object
Returns the value of attribute trending_categories.
-
#trending_category_ids ⇒ Object
Returns the value of attribute trending_category_ids.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize ⇒ HomepageDataLoader
constructor
A new instance of HomepageDataLoader.
- #set_display_products ⇒ Object
- #set_featured_brands ⇒ Object
- #set_featured_vendors ⇒ Object
- #set_homepage_backgrounds ⇒ Object
- #set_homepage_banners ⇒ Object
- #set_record_id ⇒ Object
- #set_top_catgories ⇒ Object
- #set_trending_categories ⇒ Object
Constructor Details
#initialize ⇒ HomepageDataLoader
Returns a new instance of HomepageDataLoader.
15 16 17 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 15 def initialize @config = SpreeCmCommissioner::Configuration.new end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def config @config end |
#display_product_ids ⇒ Object
Returns the value of attribute display_product_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def display_product_ids @display_product_ids end |
#display_products ⇒ Object
Returns the value of attribute display_products.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def display_products @display_products end |
#featured_brand_ids ⇒ Object
Returns the value of attribute featured_brand_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def featured_brand_ids @featured_brand_ids end |
#featured_brands ⇒ Object
Returns the value of attribute featured_brands.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def featured_brands @featured_brands end |
#featured_vendor_ids ⇒ Object
Returns the value of attribute featured_vendor_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def featured_vendor_ids @featured_vendor_ids end |
#featured_vendors ⇒ Object
Returns the value of attribute featured_vendors.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def featured_vendors @featured_vendors end |
#homepage_background_ids ⇒ Object
Returns the value of attribute homepage_background_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def homepage_background_ids @homepage_background_ids end |
#homepage_backgrounds ⇒ Object
Returns the value of attribute homepage_backgrounds.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def homepage_backgrounds @homepage_backgrounds end |
#homepage_banner_ids ⇒ Object
Returns the value of attribute homepage_banner_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def @homepage_banner_ids end |
#homepage_banners ⇒ Object
Returns the value of attribute homepage_banners.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def @homepage_banners end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def id @id end |
#top_categories ⇒ Object
Returns the value of attribute top_categories.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def top_categories @top_categories end |
#top_category_ids ⇒ Object
Returns the value of attribute top_category_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def top_category_ids @top_category_ids end |
#trending_categories ⇒ Object
Returns the value of attribute trending_categories.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def trending_categories @trending_categories end |
#trending_category_ids ⇒ Object
Returns the value of attribute trending_category_ids.
5 6 7 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 5 def trending_category_ids @trending_category_ids end |
Class Method Details
.cache_key(_options = {}) ⇒ Object
19 20 21 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 19 def self.cache_key( = {}) 'homepage_data_loader' end |
.clear_cache(_options = {}) ⇒ Object
23 24 25 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 23 def self.clear_cache( = {}) Rails.cache.delete(cache_key) end |
.with_cache ⇒ Object
27 28 29 30 31 32 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 27 def self.with_cache Rails.cache.fetch(cache_key) do data_loader = new data_loader.call end end |
Instance Method Details
#call ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 34 def call set_record_id set_homepage_backgrounds set_featured_vendors # set_trending_categories # set_top_catgories # set_display_products # set_featured_brands self end |
#set_display_products ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 102 def set_display_products config_taxon_ids = @config.displayed_product_taxon_ids taxon_ids = config_taxon_ids.present? ? config_taxon_ids.split(',') : [] return @display_products = Spree::Taxon.none if taxon_ids.blank? @display_products = SpreeCmCommissioner::Feed::TaxonProduct.call(taxon_ids, limit: 6, serialize_data: true) @display_product_ids = @display_products.map(&:id) end |
#set_featured_brands ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 82 def set_featured_brands config_taxon_ids = @config.featured_brand_taxon_ids taxon_ids = config_taxon_ids.present? ? config_taxon_ids.split(',') : [] return @featured_brands = Spree::Taxon.none if taxon_ids.blank? @featured_brands = Spree::Taxon.where(id: taxon_ids).limit(12).order(:lft) @featured_brand_ids = @featured_brands.map(&:id) end |
#set_featured_vendors ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 92 def set_featured_vendors config_vendor_ids = @config.featured_vendor_ids vendor_ids = config_vendor_ids.present? ? config_vendor_ids.split(',') : [] return @featured_vendors = Spree::Vendor.none if vendor_ids.blank? @featured_vendors = Spree::Vendor.where(id: vendor_ids) @featured_vendor_ids = @featured_vendors.pluck(:id) end |
#set_homepage_backgrounds ⇒ Object
52 53 54 55 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 52 def set_homepage_backgrounds @homepage_backgrounds = SpreeCmCommissioner::HomepageBackground.active.includes(app_image: :attachment_blob).order(:priority) @homepage_background_ids = @homepage_backgrounds.pluck(:id) end |
#set_homepage_banners ⇒ Object
57 58 59 60 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 57 def @homepage_banners = SpreeCmCommissioner::HomepageBanner.active.includes(app_image: :attachment_blob).order(:priority) @homepage_banner_ids = @homepage_banners.pluck(:id) end |
#set_record_id ⇒ Object
48 49 50 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 48 def set_record_id @id = SecureRandom.hex end |
#set_top_catgories ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 62 def set_top_catgories config_taxon_ids = @config.top_category_taxon_ids taxon_ids = config_taxon_ids.present? ? config_taxon_ids.split(',') : [] return @trending_categories = Spree::Taxon.none if taxon_ids.blank? @top_categories = Spree::Taxon.where(id: taxon_ids).limit(4).order(:lft) @top_category_ids = @top_categories.map(&:id) end |
#set_trending_categories ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/services/spree_cm_commissioner/homepage_data_loader.rb', line 72 def set_trending_categories config_taxon_ids = @config.trending_category_taxon_ids taxon_ids = config_taxon_ids.present? ? config_taxon_ids.split(',') : [] return @trending_categories = Spree::Taxon.none if taxon_ids.blank? @trending_categories = Spree::Taxon.where(id: taxon_ids).limit(5).order(:lft) @trending_category_ids = @trending_categories.map(&:id) end |