Sha256: 80a2abb510aea4563e222f597049ed07a7bbb650529cb2d0a58f82316c36f312

Contents?: true

Size: 672 Bytes

Versions: 2

Compression:

Stored size: 672 Bytes

Contents

module Workarea
  class UpdateKitInventory
    include Sidekiq::Worker
    include Sidekiq::CallbacksWorker

    sidekiq_options(
      enqueue_on: {
        Catalog::Variant => :save,
        only_if: -> { components.present? },
        with: -> { [product.id, id] }
      },
      unique: :until_executing
    )

    def perform(product_id, id)
      product = Catalog::Product.find(product_id) rescue nil
      variant = product&.variants&.detect { |v| v.id.to_s == id.to_s }

      return unless variant.present?

      sku = Inventory::Sku.find_or_initialize_by(id: variant.sku)
      sku.update!(component_quantities: variant.component_quantities)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-product_bundles-1.0.1 app/workers/workarea/update_kit_inventory.rb
workarea-product_bundles-1.0.0 app/workers/workarea/update_kit_inventory.rb