Sha256: fd9a973d3c0ff48fc696a7835d3c26d4ba33c3a90b91d37c8f2bdbf53c774aad

Contents?: true

Size: 896 Bytes

Versions: 2

Compression:

Stored size: 896 Bytes

Contents

Spree::Product.class_eval do

  # before_create :add_supplier_to_product
  has_many :suppliers, through: :master


  def add_supplier!(supplier_or_id)
    supplier = supplier_or_id.is_a?(Spree::Supplier) ? supplier_or_id : Spree::Supplier.find(supplier_or_id)
    populate_for_supplier! supplier if supplier
  end

  def add_suppliers!(supplier_ids)
    Spree::Supplier.where(id: supplier_ids).each do |supplier|
      populate_for_supplier! supplier
    end
  end

  # Returns true if the product has a drop shipping supplier.
  def supplier?
    suppliers.present?
  end

  # private

  def populate_for_supplier!(supplier)
    variants_including_master.each do |variant|
      unless variant.suppliers.pluck(:id).include?(supplier.id)
        variant.suppliers << supplier
        # supplier.stock_locations.each { |location| location.propagate_variant(variant) }
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_drop_ship-3.1.3 app/models/spree/product_decorator.rb
spree_drop_ship-3.1.2 app/models/spree/product_decorator.rb