Class: Solidus::Fulfillment::AmazonFulfillment
- Inherits:
-
Object
- Object
- Solidus::Fulfillment::AmazonFulfillment
- Defined in:
- lib/solidus/fulfillment/amazon_fulfillment.rb
Instance Method Summary collapse
-
#fetch_stock_levels(skus) ⇒ Object
Returns the stock levels for the given skus.
-
#fetch_tracking_data ⇒ Object
Returns the tracking number if there is one, else :error if there’s a problem with the shipment that will result in a permanent failure to fulfill, else nil.
-
#fulfill ⇒ Object
Runs inside a state_machine callback.
-
#initialize(shipment = nil) ⇒ AmazonFulfillment
constructor
A new instance of AmazonFulfillment.
Constructor Details
#initialize(shipment = nil) ⇒ AmazonFulfillment
Returns a new instance of AmazonFulfillment.
43 44 45 |
# File 'lib/solidus/fulfillment/amazon_fulfillment.rb', line 43 def initialize(shipment = nil) @shipment = shipment end |
Instance Method Details
#fetch_stock_levels(skus) ⇒ Object
Returns the stock levels for the given skus
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/solidus/fulfillment/amazon_fulfillment.rb', line 82 def fetch_stock_levels(skus) sleep 1 # avoid throttle from Amazon response = begin remote.fetch_stock_levels(skus: skus) rescue => ex Spree::Fulfillment.log 'Spree::AmazonFulfillment#fetch_stock_levels: Failed to get ' \ "stock levels" Spree::Fulfillment.log "Spree::AmazonFulfillment#fetch_stock_levels: #{ex}" Airbrake.notify(e) if defined?(Airbrake) return nil end Spree::Fulfillment.log "Spree::AmazonFulfillment#fetch_stock_levels: #{response.params}" response end |
#fetch_tracking_data ⇒ Object
Returns the tracking number if there is one, else :error if there’s a problem with the shipment that will result in a permanent failure to fulfill, else nil.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/solidus/fulfillment/amazon_fulfillment.rb', line 62 def fetch_tracking_data sleep 1 # avoid throttle from Amazon response = begin remote.fetch_tracking_data([order_id]) rescue => ex Spree::Fulfillment.log 'Spree::AmazonFulfillment#fetch_tracking_data: Failed to get ' \ "tracking info for shipment #{@shipment.id} (order ID: #{order_id})" Spree::Fulfillment.log "Spree::AmazonFulfillment#fetch_tracking_data: #{ex}" Airbrake.notify(e) if defined?(Airbrake) return nil end Spree::Fulfillment.log "Spree::AmazonFulfillment#fetch_tracking_data: #{response.params}" response end |
#fulfill ⇒ Object
Runs inside a state_machine callback. So throwing :halt is how we abort things.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/solidus/fulfillment/amazon_fulfillment.rb', line 48 def fulfill sleep 1 # avoid throttle from Amazon response = remote.fulfill(order_id, address, line_items, ) Spree::Fulfillment.log "Spree::AmazonFulfillment#fulfill: order_id: " \ "#{order_id}\naddress: #{address}\nline_items: #{line_items}\noptions: " \ "#{}\nresponse: #{response.params}" response end |