Sha256: d32c341c8b7bdb15a86f45708cba2e72c6934781c01c103b07d65947620ae51c

Contents?: true

Size: 805 Bytes

Versions: 19

Compression:

Stored size: 805 Bytes

Contents

# frozen_string_literal: true

module FlowcommerceSpree
  class InventoryController < ActionController::Base
    def online_stock_availability
      items = params['items'] || []
      response = items.inject([]) { |result, item| result << check_stock(item[:id], item[:qty].to_i) }
      render json: { items: response }, status: :ok
    end

    private

    def check_stock(flow_number, quantity)
      variant = Spree::Variant.find_by(sku: flow_number)
      return { id: flow_number, has_inventory: false } unless variant

      { id: flow_number, has_inventory: variant.available_online?(quantity) }
    rescue StandardError
      Rails.logger.error "[!] FlowcommerceSpree::InventoryController#stock unexpected Error: #{$ERROR_INFO}"
      { id: flow_number, has_inventory: false }
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
flowcommerce_spree-0.0.22 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.21 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.20 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.19 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.18 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.17 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.16 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.15 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.14 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.13 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.12 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.11 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.10 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.9 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.8 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.7 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.6 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.5 app/controllers/flowcommerce_spree/inventory_controller.rb
flowcommerce_spree-0.0.4 app/controllers/flowcommerce_spree/inventory_controller.rb