Sha256: b2735d4ac164b3c821ddaf28e76d6a0facb42f869f05681e6153f75ad1eefc2c

Contents?: true

Size: 872 Bytes

Versions: 30

Compression:

Stored size: 872 Bytes

Contents

module Spree
  module Filters
    class PropertyPresenter
      def initialize(property:, product_properties:)
        @property = property
        @product_properties = product_properties
      end

      attr_reader :product_properties

      delegate_missing_to :property

      def uniq_values
        property.uniq_values(product_properties_scope: product_properties)
      end

      def to_h
        {
          id: property.id,
          name: property.name,
          presentation: property.presentation,
          values: values_hash
        }
      end

      private

      attr_reader :property

      def values_hash
        value_hashes = uniq_values.map do |filter_param, value|
          {
            value: value,
            filter_param: filter_param
          }
        end

        value_hashes.sort_by { |e| e[:value] }
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/presenters/spree/filters/property_presenter.rb
spree_core-4.10.0 app/presenters/spree/filters/property_presenter.rb
spree_core-4.9.0 app/presenters/spree/filters/property_presenter.rb
spree_core-4.8.3 app/presenters/spree/filters/property_presenter.rb
spree_core-4.8.2 app/presenters/spree/filters/property_presenter.rb
spree_core-4.7.3 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.6 app/presenters/spree/filters/property_presenter.rb
spree_core-4.5.5 app/presenters/spree/filters/property_presenter.rb
spree_core-4.3.3 app/presenters/spree/filters/property_presenter.rb
spree_core-4.4.1 app/presenters/spree/filters/property_presenter.rb
spree_core-4.5.4 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.5 app/presenters/spree/filters/property_presenter.rb
spree_core-4.7.2 app/presenters/spree/filters/property_presenter.rb
spree_core-4.7.1 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.4 app/presenters/spree/filters/property_presenter.rb
spree_core-4.7.0 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.3 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.2 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.1 app/presenters/spree/filters/property_presenter.rb
spree_core-4.6.0 app/presenters/spree/filters/property_presenter.rb