Sha256: 1326aa39d3facaf0007f3e253f4f3339cef53915836f883d32edbf0b2ee98db7

Contents?: true

Size: 647 Bytes

Versions: 4

Compression:

Stored size: 647 Bytes

Contents

Spree::StockLocation.class_eval do

  belongs_to :supplier, class_name: 'Spree::Supplier'

  scope :by_supplier, -> (supplier_id) { where(supplier_id: supplier_id) }

  # Wrapper for creating a new stock item respecting the backorderable config and supplier
  durably_decorate :propagate_variant, mode: 'soft', sha: 'f35b0d8a811311d4886d53024a9aa34e3aa5f8cb' do |variant|
    if self.supplier_id.blank? || variant.suppliers.pluck(:id).include?(self.supplier_id)
      self.stock_items.create!(variant: variant, backorderable: self.backorderable_default)
    end
  end

  def available?(variant)
    stock_item(variant).try(:available?)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_drop_ship-3.1.3 app/models/spree/stock_location_decorator.rb
spree_drop_ship-3.1.2 app/models/spree/stock_location_decorator.rb
spree_drop_ship-3.1.1 app/models/spree/stock_location_decorator.rb
spree_drop_ship-3.1.0.1 app/models/spree/stock_location_decorator.rb