Sha256: 2ee8f700a15345d0bd18181beb7aaa725a9981d179a10c7b6babc6f12a23b5b5

Contents?: true

Size: 865 Bytes

Versions: 5

Compression:

Stored size: 865 Bytes

Contents

module Workarea
  decorate Search::RelatedProducts, with: :browse_option do
    def search_product_ids
      @search_product_ids ||= products.flat_map { |p| search_model_for(p) }.map(&:id)
    end

    def exclude_search_product_ids
      @exclude_search_product_ids ||=
        begin
          catalog_ids = Array(params[:exclude_product_ids])
          products = Catalog::Product.any_in(id: catalog_ids).to_a
          products.flat_map { |p| search_model_for(p) }.map(&:id)
        end
    end

    def search_model_for(product)
      if product.browses_by_option?
        product.browse_options.map do |value|
          Search::Storefront::ProductOption.new(
            product,
            option: product.browse_option,
            value: value
          )
        end
      else
        Search::Storefront::Product.new(product)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-browse_option-2.2.0 app/queries/workarea/search/related_products.decorator
workarea-browse_option-2.1.9 app/queries/workarea/search/related_products.decorator
workarea-browse_option-2.1.8 app/queries/workarea/search/related_products.decorator
workarea-browse_option-2.1.7 app/queries/workarea/search/related_products.decorator
workarea-browse_option-2.1.6 app/queries/workarea/search/related_products.decorator