Class: MagentoTwo::Order

Inherits:
Client
  • Object
show all
Defined in:
lib/MagentoTwo/order.rb

Constant Summary collapse

PENDING =
'pending'
PROCESSING =
'processing'
COMPLETE =
'complete'

Instance Attribute Summary

Attributes inherited from Client

#endpoint

Instance Method Summary collapse

Methods inherited from Client

#initialize

Constructor Details

This class inherits a constructor from MagentoTwo::Client

Instance Method Details

#allHash

Returns All Orders

Returns:

  • (Hash)

    Orders Items



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

#completeOpenStruct

Returns Completed (Shipped) Orders

Returns:

  • (OpenStruct)

    Orders Items



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

#pendingOpenStruct

Returns Pending (New) Orders

Returns:

  • (OpenStruct)

    Array Orders Items



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

#processingOpenStruct

Returns Processing (Invoiced) Orders

Returns:

  • (OpenStruct)

    Orders Items



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

Parameters:

  • Carrier (String, title)

    Name

  • Shipment (String, track_number)

    Tracking Number

  • Magento (String, carrier_code)

    Carrier Code

  • Magento (Integer, order_id)

    Order ID

Returns:

  • (String)

    Order ID



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