Class: MagentoTwo::Order
Constant Summary collapse
- PENDING =
'pending'
- PROCESSING =
'processing'
- COMPLETE =
'complete'
Instance Attribute Summary
Attributes inherited from Client
Instance Method Summary collapse
-
#all ⇒ Hash
Returns All Orders.
-
#complete ⇒ OpenStruct
Returns Completed (Shipped) Orders.
-
#pending ⇒ OpenStruct
Returns Pending (New) Orders.
-
#processing ⇒ OpenStruct
Returns Processing (Invoiced) Orders.
-
#ship(order_id: nil, notify: true, carrier_code: nil, title: nil, track_number: nil) ⇒ String
Update Order shipment and save shipment details on order.
Methods inherited from Client
Constructor Details
This class inherits a constructor from MagentoTwo::Client
Instance Method Details
#all ⇒ Hash
Returns All Orders
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/MagentoTwo/order.rb', line 11 def all begin response = @connection.get('orders', query_params(value: PENDING, index: 0) .merge!(query_params(value: PROCESSING, index: 1)) .merge!(query_params(value: COMPLETE, index: 2))) JSON.parse(response.body, object_class: OpenStruct) rescue JSON::ParserError, TypeError => e puts e end end |
#complete ⇒ OpenStruct
Returns Completed (Shipped) Orders
37 38 39 40 41 42 43 44 |
# File 'lib/MagentoTwo/order.rb', line 37 def complete begin response = @connection.get('orders', query_params(value: COMPLETE)) JSON.parse(response.body, object_class: OpenStruct) rescue JSON::ParserError, TypeError => e puts e end end |
#pending ⇒ OpenStruct
Returns Pending (New) Orders
25 26 27 28 29 30 31 32 |
# File 'lib/MagentoTwo/order.rb', line 25 def pending begin response = @connection.get('orders', query_params(value: PENDING)) JSON.parse(response.body, object_class: OpenStruct) rescue JSON::ParserError, TypeError => e puts e end end |
#processing ⇒ OpenStruct
Returns Processing (Invoiced) Orders
49 50 51 52 53 54 55 56 |
# File 'lib/MagentoTwo/order.rb', line 49 def processing begin response = @connection.get('orders', query_params(value: PROCESSING)) JSON.parse(response.body, object_class: OpenStruct) rescue JSON::ParserError, TypeError => e puts e end end |
#ship(order_id: nil, notify: true, carrier_code: nil, title: nil, track_number: nil) ⇒ String
Update Order shipment and save shipment details on order
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/MagentoTwo/order.rb', line 65 def ship(order_id: nil, notify: true, carrier_code: nil, title: nil, track_number: nil) object = tracking_params( order_id: order_id, notify: true, carrier_code: carrier_code, title: title, track_number: track_number) begin response = @connection.post("order/#{order_id}/ship") do |req| req.body = object.to_json end puts JSON.parse(response.body) response.body rescue JSON::ParserError, TypeError => e puts e end end |