Sha256: e479b4bf687bd6f5c6f8f69fdd930834c6fa42437670f87edf23ac4ace80e692

Contents?: true

Size: 566 Bytes

Versions: 2

Compression:

Stored size: 566 Bytes

Contents

module Workarea
  decorate Catalog::Variant, with: :product_bundles do
    decorated do
      embeds_many :components,
        class_name: 'Workarea::Catalog::VariantComponent',
        inverse_of: :variant
    end

    def component_quantities
      components.each_with_object({}) do |component, qty|
        qty[component.sku] = component.quantity
      end
    end

    def admin_filter_value
      [
        sku,
        *details.to_a.flatten,
        *components.flat_map { |c| [c.sku, c.product_id] }
      ].compact.uniq.join(' ').downcase
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-product_bundles-1.0.1 app/models/workarea/catalog/variant.decorator
workarea-product_bundles-1.0.0 app/models/workarea/catalog/variant.decorator