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