Class: Spree::ShipwireWebhooks::StockController

Inherits:
Spree::ShipwireWebhookController show all
Defined in:
app/controllers/spree/shipwire_webhooks/stock_controller.rb

Instance Method Summary collapse

Methods inherited from Spree::ShipwireWebhookController

#subscribe

Instance Method Details

#createObject

stock.transition



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/spree/shipwire_webhooks/stock_controller.rb', line 5

def create
  if body['toState'].inquiry.good?
    stock_item.tap do |si|
      si.stock_movements.create(quantity: delta)
      si.set_count_on_hand stock_quantity
    end
  end

  render json: :ok
rescue ActiveRecord::RecordNotFound => e
  render json: e.message, status: 404
rescue StandardError => e
  render json: e.message, status: 500
end