Class: Spree::Api::V2::Storefront::PreviewSectionsController

Inherits:
HomepageSectionsController show all
Defined in:
app/controllers/spree/api/v2/storefront/preview_sections_controller.rb

Instance Method Summary collapse

Methods inherited from HomepageSectionsController

#collection_serializer, #model_class, #resource_serializer

Instance Method Details

#collectionObject

override



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/spree/api/v2/storefront/preview_sections_controller.rb', line 9

def collection
  allowed_ids = spree_current_user.preview_roles.where(previewable_type: Spree::Taxon.polymorphic_name).pluck(:previewable_id)

  section_ids = SpreeCmCommissioner::HomepageSectionRelatable
                .where(relatable_type: 'Spree::Taxon', relatable_id: allowed_ids.presence || [])
                .select(:homepage_section_id)

  @collection ||= model_class.filter_by_segment(params[:homepage_id] || :general)
                             .active
                             .where(tenant_id: nil)
                             .where(preview: true)
                             .where(id: section_ids)
                             .order(position: :asc)
end