Module: SpreeCmCommissioner::StockItemDecorator

Defined in:
app/models/spree_cm_commissioner/stock_item_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/models/spree_cm_commissioner/stock_item_decorator.rb', line 3

def self.prepended(base)
  base.has_one :vendor, through: :variant
  base.after_save :update_vendor_total_inventory, if: :saved_change_to_count_on_hand?

  base.after_commit :create_inventory_items, on: :create
  base.after_commit :adjust_inventory_items_async, on: :destroy

  # Create maintaining task to purge product related caches
  base.after_commit { SpreeCmCommissioner::MaintenanceTasks::CacheInvalidation.pending.create_or_find_by(maintainable: variant.product) }
end

Instance Method Details

#update_vendor_total_inventoryObject



14
15
16
# File 'app/models/spree_cm_commissioner/stock_item_decorator.rb', line 14

def update_vendor_total_inventory
  SpreeCmCommissioner::VendorJob.perform_later(vendor_id: vendor.id) if vendor.present?
end