Class: Magento::Order

Inherits:
Model
  • Object
show all
Defined in:
lib/magento/order.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

api_resource, create, delete, #delete, entity_name, find, #id

Methods included from ModelParser

included, #to_h

Class Method Details

.add_comment(order_id, comment, comment_params = nil) ⇒ Boolean

Creates a comment on the given Order

Magento::Order.add_comment(

order_id,
'comment',
is_customer_notified: 0,
is_visible_on_front: 1

)

to complete [documentation](magento.redoc.ly/2.4.2-admin/tag/ordersidcomments#operation/salesOrderManagementV1AddCommentPost)

Returns:

  • (Boolean)

    : return true on success



211
212
213
214
215
216
217
218
219
# File 'lib/magento/order.rb', line 211

def add_comment(order_id, comment, comment_params = nil)
  request.post(
    "orders/#{order_id}/comments",
    statusHistory: {
      comment: comment,
      **comment_params
    }
  ).parse
end

.cancel(order_id) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/magento/order.rb', line 91

def cancel(order_id)
  request.post("orders/#{order_id}/cancel").parse
end

.invoice(order_id, invoice_params = nil) ⇒ Object

Invoice an order

Magento::Order.invoice(order_id)

or

Magento::Order.invoice(

order_id,
capture: false,
appendComment: true,
items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
comment: {
  extension_attributes: { },
  comment: "string",
  is_visible_on_front: 0
},
notify: true

)

to complete [documentation](magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)

Returns:

  • String: return the invoice id



118
119
120
# File 'lib/magento/order.rb', line 118

def invoice(order_id, invoice_params=nil)
  request.post("order/#{order_id}/invoice", invoice_params).parse
end

.refund(order_id, refund_params = nil) ⇒ Integer

Create offline refund for order

Magento::Order.refund(order_id)

or

Magento::Order.refund(

order_id,
items: [
  {
    extension_attributes: {},
    order_item_id: 0,
    qty: 0
  }
],
notify: true,
appendComment: true,
comment: {
  extension_attributes: {},
  comment: string,
  is_visible_on_front: 0
},
arguments: {
  shipping_amount: 0,
  adjustment_positive: 0,
  adjustment_negative: 0,
  extension_attributes: {
    return_to_stock_items: [
      0
    ]
  }
}

)

to complete [documentation](magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)

Returns:

  • (Integer)

    return the refund id



160
161
162
# File 'lib/magento/order.rb', line 160

def refund(order_id, refund_params = nil)
  request.post("order/#{order_id}/refund", refund_params).parse
end

.send_email(order_id) ⇒ Object



194
195
196
# File 'lib/magento/order.rb', line 194

def send_email(order_id)
  request.post("orders/#{order_id}/emails").parse
end

.ship(order_id, shipment_params = nil) ⇒ String

Creates new Shipment for given Order.

Magento::Order.ship(order_id)

or

Magento::Order.ship(

order_id,
capture: false,
appendComment: true,
items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
tracks: [
  {
    extension_attributes: { },
    track_number: "string",
    title: "string",
    carrier_code: "string"
  }
]
notify: true

)

to complete [documentation](magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)

Returns:

  • (String)

    : return the shipment id



190
191
192
# File 'lib/magento/order.rb', line 190

def ship(order_id, shipment_params = nil)
  request.post("order/#{order_id}/ship", shipment_params).parse
end

.update(entity_id, attributes) ⇒ Object



84
85
86
87
88
# File 'lib/magento/order.rb', line 84

def update(entity_id, attributes)
  attributes[:entity_id] = entity_id
  hash = request.put('orders/create', { entity_key => attributes }).parse
  block_given? ? yield(hash) : build(hash)
end

Instance Method Details

#add_comment(comment, comment_params = nil) ⇒ Object

Creates a comment on the given Order

order = Magento::Order.find(order_id)

order.add_comment(

'comment',
is_customer_notified: 0,
is_visible_on_front: 1

)

Return true on success



79
80
81
# File 'lib/magento/order.rb', line 79

def add_comment(comment, comment_params = nil)
  self.class.add_comment(id, comment, comment_params)
end

#cancelObject



20
21
22
# File 'lib/magento/order.rb', line 20

def cancel
  self.class.cancel(id)
end

#invoice(params = nil) ⇒ Object

Invoice current order

order = Magento::Order.find(order_id)

order.invoice # or you can pass parameters order.invoice(capture: false) # See the invoice class method for more information

Returns:

  • String: return the invoice id



33
34
35
# File 'lib/magento/order.rb', line 33

def invoice(params=nil)
  self.class.invoice(id, params)
end

#refund(refund_params = nil) ⇒ Integer

Create offline refund for order

order = Magento::Order.find(order_id)

order.refund # or you can pass parameters order.invoice(notify: false) # See the refund class method for more information

Returns:

  • (Integer)

    return the refund id



46
47
48
# File 'lib/magento/order.rb', line 46

def refund(refund_params = nil)
  self.class.refund(id, refund_params)
end

#saveObject

Raises:

  • (NotImplementedError)


8
9
10
# File 'lib/magento/order.rb', line 8

def save
  raise NotImplementedError
end

#send_emailObject



63
64
65
# File 'lib/magento/order.rb', line 63

def send_email
  self.class.send_email(id)
end

#ship(params = nil) ⇒ Object

Creates new Shipment for given Order.

order = Magento::Order.find(order_id)

order.ship # or you can pass parameters order.ship(notify: false) # See the shipment class method for more information

Return the shipment id



59
60
61
# File 'lib/magento/order.rb', line 59

def ship(params=nil)
  self.class.ship(id, params)
end

#update(attrs) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/magento/order.rb', line 12

def update(attrs)
  raise "'entity_id' not found" if @entity_id.nil?

  self.class.update(@entity_id, attrs) do |hash|
    update_attributes(hash)
  end
end