Sha256: 5cda6860d0ab936ae95dbd3497bcbde50bdb0cb82bf36988ccfc0fca2bbc7308

Contents?: true

Size: 493 Bytes

Versions: 4

Compression:

Stored size: 493 Bytes

Contents

# frozen_string_literal: true

module SolidusProductAssembly
  module Spree
    module InventoryUnitDecorator
      def percentage_of_line_item
        product = line_item.product
        if product.assembly?
          total_value = line_item.quantity_by_variant.map { |part, quantity| part.price * quantity }.sum
          variant.price / total_value
        else
          1 / BigDecimal(line_item.quantity)
        end
      end

      ::Spree::InventoryUnit.prepend self
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_product_assembly-1.4.0 app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb
solidus_product_assembly-1.3.0 app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb
solidus_product_assembly-1.2.0 app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb
solidus_product_assembly-1.1.0 app/decorators/models/solidus_product_assembly/spree/inventory_unit_decorator.rb