Sha256: d4dc6de0fbdd12175f28969ff6db4de26cf665f385d8c267ed3e40d0613e8646

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

module Harpiya
  class TaxonsController < Harpiya::StoreController
    include Harpiya::FrontendHelper
    include Harpiya::CacheHelper
    helper 'harpiya/products'

    before_action :load_taxon

    respond_to :html

    def show
      if !http_cache_enabled? || stale?(etag: etag, last_modified: last_modified, public: true)
        load_products
      end
    end

    def product_carousel
      if !http_cache_enabled? || stale?(etag: carousel_etag, last_modified: last_modified, public: true)
        load_products
        if @products.reload.any?
          render template: 'harpiya/taxons/product_carousel', layout: false
        else
          head :no_content
        end
      end
    end

    private

    def accurate_title
      @taxon.try(:seo_title) || super
    end

    def load_taxon
      @taxon = Harpiya::Taxon.friendly.find(params[:id])
    end

    def load_products
      search_params = params.merge(
        current_store: current_store,
        taxon: @taxon,
        include_images: true
      )

      @searcher = build_searcher(search_params)
      @products = @searcher.retrieve_products
    end

    def etag
      [
        store_etag,
        @taxon,
        available_option_types_cache_key,
        filtering_params_cache_key
      ]
    end

    def carousel_etag
      [
        store_etag,
        @taxon
      ]
    end

    def last_modified
      taxon_last_modified = @taxon&.updated_at&.utc
      current_store_last_modified = current_store.updated_at.utc

      [taxon_last_modified, current_store_last_modified].compact.max
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harpiya_frontend-4.3.0.alpha app/controllers/harpiya/taxons_controller.rb