Sha256: 0573f2aefcde31689d984e355972e12496586766fd1295f4b08b59d97cff0c8a

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

module Gemgento::Api::V1::ProductFilters
  extend ActiveSupport::Concern

  def basic_filters
    default_filters.merge(filter_params)
  end

  def default_filters
    {
        status: 1, # enabled
        visibility: [2, 4], # catalog visible
    }
  end

  def attribute_filters
    attribute_filters = []
    all_attribute_codes = Gemgento::ProductAttribute.pluck(:code).uniq.map(&:to_sym)
    filterable_attribute_codes = all_attribute_codes - default_filters.keys
    attribute_filter_params = params.permit(filterable_attribute_codes)

    attribute_filter_params.each do |code, value|
      attribute = Gemgento::ProductAttribute.find_by!(code: code)
      attribute_filters << { attribute: attribute, value: value }
    end

    return attribute_filters
  end

  def filter_params
    params.permit(:status, :visibility, :magento_type, :sku)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemgento-2.8.0 app/controllers/concerns/gemgento/api/v1/product_filters.rb