Class: Spree::Api::V2::Storefront::HomepageSectionsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



18
19
20
21
22
23
24
# File 'app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb', line 18

def collection
  @collection = model_class.filter_by_segment(params[:homepage_id] || :general)
                           .active
                           .where(tenant_id: nil)
                           .order(position: :asc)
                           .includes(preload_associations)
end

#collection_serializerObject



10
11
12
# File 'app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb', line 10

def collection_serializer
  Spree::V2::Storefront::HomepageSectionSerializer
end

#model_classObject



6
7
8
# File 'app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb', line 6

def model_class
  SpreeCmCommissioner::HomepageSection
end

#preload_associationsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb', line 26

def preload_associations
  {
    homepage_section_relatables: {
      relatable: [
        :icon,
        {
          home_banner: { attachment_attachment: :blob }
        },
        {
          category_icon: { attachment_attachment: :blob }
        },
        {
          video_banner: { attachment_attachment: :blob }
        },
        {
          app_banner: { attachment_attachment: :blob }
        },
        {
          web_banner: { attachment_attachment: :blob }
        },
        {
          children: [
            :icon,
            {
              vendors: [
                { photos: { attachment_attachment: :blob } },
                :default_state
              ]
            }
          ]
        }
      ]
    }
  }
end

#resource_serializerObject



14
15
16
# File 'app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb', line 14

def resource_serializer
  Spree::V2::Storefront::HomepageSectionSerializer
end