magento 0.6.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f899948f7690202bfadf8b2d0afbb066a864fd85f3e7d0c591df07b4f631d7bb
4
- data.tar.gz: 63585fc1f5b5ba321a065e2796c253b52f544b3b057b941b933c027a04d63d07
3
+ metadata.gz: 84ae0187402170a5d338e8fe19f7ffa07211be073592c36aff70a5edef16e008
4
+ data.tar.gz: 7eed987d9b42e2ec86f9394c088c363658cb27cfcb664a8d2192ada23c0ee5b8
5
5
  SHA512:
6
- metadata.gz: 0142acdd5ef93981d5170c39fecd73852458d8ea4a01d8b3c2ee28fd01c82ae26f2f16c533219908d8110648f50a99188b89a0f8537750b187fe62f003ff04c3
7
- data.tar.gz: 39092a61524a5f09cc61ead86e66917f5833f2b30ca6a7155479c41af471a88394ccdbd233341a03ef6a8fadbd3e3dbd6b222d554b9eee590f0fec1b3b1f7006
6
+ metadata.gz: beef9d8552c025b306ad434b33701030e032b8a603545bfcfbc407be1b141f36625075ab4f873e8bac78b6369fd5334239af3da8cff0de04ebc445ed4f1fde3d
7
+ data.tar.gz: b8e897978815efe0416471903a3d398b5d4ed8593a59353852cda2d33b3843ae861929f168425072ab69caeb7dec0d360ba5c1345919a2ab81990f368134c744
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.6.0'
8
+ gem 'magento', '~> 0.9.0'
9
9
  ```
10
10
 
11
11
  or run
@@ -288,6 +288,182 @@ cart.payment_information(
288
288
  >> "234575" # return the order id
289
289
  ```
290
290
 
291
+ ## Invoice an Order
292
+
293
+ ```rb
294
+ Magento::Order.invoice(order_id)
295
+ >> 25 # return incoice id
296
+
297
+ # or from instance
298
+
299
+ order = Magento::Order.find(order_id)
300
+
301
+ invoice_id = order.invoice
302
+
303
+ # you can pass parameters too
304
+
305
+ invoice_id = order.invoice(
306
+ capture: false,
307
+ appendComment: true,
308
+ items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
309
+ comment: {
310
+ extension_attributes: { },
311
+ comment: "string",
312
+ is_visible_on_front: 0
313
+ },
314
+ notify: true
315
+ )
316
+ ```
317
+
318
+ [Complete Invoice Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
319
+
320
+ ## Create refund for invoice
321
+
322
+ ```rb
323
+ Magento::Invoice.invoice(invoice_id)
324
+ >> 12 # return refund id
325
+
326
+ # or from instance
327
+
328
+ invoice = Magento::Invoice.find(invoice_id)
329
+
330
+ refund_id = invoice.refund
331
+
332
+ # you can pass parameters too
333
+
334
+ invoice.refund(
335
+ items: [
336
+ {
337
+ extension_attributes: {},
338
+ order_item_id: 0,
339
+ qty: 0
340
+ }
341
+ ],
342
+ isOnline: true,
343
+ notify: true,
344
+ appendComment: true,
345
+ comment: {
346
+ extension_attributes: {},
347
+ comment: string,
348
+ is_visible_on_front: 0
349
+ },
350
+ arguments: {
351
+ shipping_amount: 0,
352
+ adjustment_positive: 0,
353
+ adjustment_negative: 0,
354
+ extension_attributes: {
355
+ return_to_stock_items: [0]
356
+ }
357
+ }
358
+ )
359
+ ```
360
+
361
+ [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
362
+
363
+
364
+ ## Create offline refund for order
365
+
366
+ ```rb
367
+ Magento::Order.refund(order_id)
368
+ >> 12 # return refund id
369
+
370
+ # or from instance
371
+
372
+ order = Magento::Order.find(order_id)
373
+
374
+ order.refund
375
+
376
+ # you can pass parameters too
377
+
378
+ order.refund(
379
+ items: [
380
+ {
381
+ extension_attributes: {},
382
+ order_item_id: 0,
383
+ qty: 0
384
+ }
385
+ ],
386
+ notify: true,
387
+ appendComment: true,
388
+ comment: {
389
+ extension_attributes: {},
390
+ comment: string,
391
+ is_visible_on_front: 0
392
+ },
393
+ arguments: {
394
+ shipping_amount: 0,
395
+ adjustment_positive: 0,
396
+ adjustment_negative: 0,
397
+ extension_attributes: {
398
+ return_to_stock_items: [0]
399
+ }
400
+ }
401
+ )
402
+ ```
403
+
404
+ [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
405
+
406
+ ## Other Invoice methods
407
+
408
+ ```rb
409
+ invoice = Magento::Invoice.find(invoice_id)
410
+
411
+ invoice.capture # or
412
+ Magento::Invoice.capture(invoice_id)
413
+
414
+ invoice.void # or
415
+ Magento::Invoice.void(invoice_id)
416
+
417
+ invoice.send_email # or
418
+ Magento::Invoice.send_email(invoice_id)
419
+
420
+ Magento::Invoice.comments(invoice_id).all
421
+ Magento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all
422
+ ```
423
+
424
+ ## Creates new Shipment for given Order.
425
+
426
+ ```rb
427
+ Magento::Order.ship(order_id)
428
+ >> 25 # return shipment id
429
+
430
+ # or from instance
431
+
432
+ order = Magento::Order.find(order_id)
433
+
434
+ order.ship
435
+
436
+ # you can pass parameters too
437
+
438
+ order.ship(
439
+ capture: false,
440
+ appendComment: true,
441
+ items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
442
+ tracks: [
443
+ {
444
+ extension_attributes: { },
445
+ track_number: "string",
446
+ title: "string",
447
+ carrier_code: "string"
448
+ }
449
+ ]
450
+ notify: true
451
+ )
452
+ ```
453
+
454
+ [Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
455
+
456
+
457
+ ## Cancel an Order
458
+
459
+ ```rb
460
+ order = Magento::Order.find(order_id)
461
+
462
+ order.cancel # or
463
+
464
+ Magento::Order.cancel(order_id)
465
+ ```
466
+
291
467
  ___
292
468
 
293
469
  ##TODO:
@@ -296,3 +472,31 @@ ___
296
472
  ```rb
297
473
  Magento::Product.search('tshort')
298
474
  ```
475
+
476
+ ### First result
477
+ ```rb
478
+ Magento::Product.first
479
+ >> <Magento::Product @sku="some-sku" ...>
480
+
481
+ Magento::Product.where(name_like: 'some name%').first
482
+ >> <Magento::Product @sku="some-sku" ...>
483
+ ```
484
+
485
+ ### Last result
486
+ ```rb
487
+ Magento::Product.last
488
+ >> <Magento::Product @sku="some-sku" ...>
489
+
490
+ Magento::Product.where(name_like: 'some name%').last
491
+ >> <Magento::Product @sku="some-sku" ...>
492
+ ```
493
+
494
+ ### Count result
495
+ ```rb
496
+ Magento::Product.count
497
+ >> 7855
498
+ Magento::Product.where(name_like: 'some name%').count
499
+ >> 15
500
+ ```
501
+
502
+ ### Tests
@@ -6,6 +6,7 @@ require 'dry/inflector'
6
6
  require_relative 'magento/errors'
7
7
  require_relative 'magento/request'
8
8
  require_relative 'magento/model_mapper'
9
+ require_relative 'magento/polymorphic_model'
9
10
  require_relative 'magento/model'
10
11
  require_relative 'magento/record_collection'
11
12
  require_relative 'magento/query'
@@ -14,6 +15,7 @@ require_relative 'magento/product'
14
15
  require_relative 'magento/country'
15
16
  require_relative 'magento/customer'
16
17
  require_relative 'magento/order'
18
+ require_relative 'magento/invoice'
17
19
  require_relative 'magento/guest_cart'
18
20
 
19
21
  Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magento
4
+ class Invoice < Model
5
+ self.primary_key = :entity_id
6
+ self.entity_key = :entity
7
+
8
+ #
9
+ # Sets invoice capture.
10
+ def capture
11
+ self.class.capture(id)
12
+ end
13
+
14
+ #
15
+ # Voids a specified invoice.
16
+ #
17
+ # @return {Boolean}
18
+ def void
19
+ self.class.void(id)
20
+ end
21
+
22
+ #
23
+ # Emails a user a specified invoice.
24
+ #
25
+ # @return {Boolean}
26
+ def send_email
27
+ self.class.send_email(id)
28
+ end
29
+
30
+ #
31
+ # Create refund for invoice
32
+ #
33
+ # invoice = Magento::Invoice.find(invoice_id)
34
+ #
35
+ # invoice.refund # or you can pass parameters
36
+ # invoice.refund(isOnline: true) # See the refund class method for more information
37
+ #
38
+ # @return {Integer} return the refund id
39
+ def refund(refund_params = nil)
40
+ self.class.refund(id, refund_params)
41
+ end
42
+
43
+ class << self
44
+ def save
45
+ raise NotImplementedError
46
+ end
47
+
48
+ def update(_attributes)
49
+ raise NotImplementedError
50
+ end
51
+
52
+ def create(_attributes)
53
+ raise NotImplementedError
54
+ end
55
+
56
+ #
57
+ # Sets invoice capture.
58
+ def capture(invoice_id)
59
+ request.post("invoices/#{invoice_id}/capture").parse
60
+ end
61
+
62
+ #
63
+ # Voids a specified invoice.
64
+ #
65
+ # @return {Boolean}
66
+ def void(invoice_id)
67
+ request.post("invoices/#{invoice_id}/avoid").parse
68
+ end
69
+
70
+ #
71
+ # Emails a user a specified invoice.
72
+ #
73
+ # @return {Boolean}
74
+ def send_email(invoice_id)
75
+ request.post("invoices/#{invoice_id}/emails").parse
76
+ end
77
+
78
+ #
79
+ # Lists comments for a specified invoice.
80
+ #
81
+ # Magento::Invoice.comments(invoice_id).all
82
+ # Magento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all
83
+ def comments(invoice_id)
84
+ api_resource = "invoices/#{invoice_id}/comments"
85
+ Query.new(PolymorphicModel.new(Comment, api_resource))
86
+ end
87
+
88
+ #
89
+ # Create refund for invoice
90
+ #
91
+ # Magento::Invoice.refund(invoice_id)
92
+ #
93
+ # or
94
+ #
95
+ # Magento::Invoice.refund(
96
+ # invoice_id,
97
+ # items: [
98
+ # {
99
+ # extension_attributes: {},
100
+ # order_item_id: 0,
101
+ # qty: 0
102
+ # }
103
+ # ],
104
+ # isOnline: true,
105
+ # notify: true,
106
+ # appendComment: true,
107
+ # comment: {
108
+ # extension_attributes: {},
109
+ # comment: string,
110
+ # is_visible_on_front: 0
111
+ # },
112
+ # arguments: {
113
+ # shipping_amount: 0,
114
+ # adjustment_positive: 0,
115
+ # adjustment_negative: 0,
116
+ # extension_attributes: {
117
+ # return_to_stock_items: [
118
+ # 0
119
+ # ]
120
+ # }
121
+ # }
122
+ # )
123
+ #
124
+ # to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
125
+ #
126
+ # @return {Integer} return the refund id
127
+ def refund(invoice_id, refund_params=nil)
128
+ request.post("invoice/#{invoice_id}/refund", refund_params).parse
129
+ end
130
+ end
131
+ end
132
+ end
@@ -16,11 +16,160 @@ module Magento
16
16
  self.class.update(attrs)
17
17
  end
18
18
 
19
+ def cancel
20
+ self.class.cancel(id)
21
+ end
22
+
23
+ #
24
+ # Invoice current order
25
+ #
26
+ # order = Magento::Order.find(order_id)
27
+ #
28
+ # order.invoice # or you can pass parameters
29
+ # order.invoice(capture: false) # See the invoice class method for more information
30
+ #
31
+ # @return String: return the invoice id
32
+ def invoice(params=nil)
33
+ self.class.invoice(id, params)
34
+ end
35
+
36
+
37
+ #
38
+ # Create offline refund for order
39
+ #
40
+ # order = Magento::Order.find(order_id)
41
+ #
42
+ # order.refund # or you can pass parameters
43
+ # order.invoice(notify: false) # See the refund class method for more information
44
+ #
45
+ # @return {Integer} return the refund id
46
+ def refund(refund_params = nil)
47
+ self.class.refund(id, refund_params)
48
+ end
49
+
50
+ #
51
+ # Creates new Shipment for given Order.
52
+ #
53
+ # order = Magento::Order.find(order_id)
54
+ #
55
+ # order.ship # or you can pass parameters
56
+ # order.ship(notify: false) # See the shipment class method for more information
57
+ #
58
+ # Return the shipment id
59
+ def ship(params=nil)
60
+ self.class.ship(id, params)
61
+ end
62
+
19
63
  class << self
20
64
  def update(attributes)
21
65
  hash = request.put('orders/create', { entity_key => attributes }).parse
22
66
  build(hash)
23
67
  end
68
+
69
+ # @return {Boolean}
70
+ def cancel(order_id)
71
+ request.post("orders/#{order_id}/cancel").parse
72
+ end
73
+
74
+ #
75
+ # Invoice an order
76
+ #
77
+ # Magento::Order.invoice(order_id)
78
+ #
79
+ # or
80
+ #
81
+ # Magento::Order.invoice(
82
+ # order_id,
83
+ # capture: false,
84
+ # appendComment: true,
85
+ # items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
86
+ # comment: {
87
+ # extension_attributes: { },
88
+ # comment: "string",
89
+ # is_visible_on_front: 0
90
+ # },
91
+ # notify: true
92
+ # )
93
+ #
94
+ # to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
95
+ #
96
+ # @return String: return the invoice id
97
+ def invoice(order_id, invoice_params=nil)
98
+ request.post("order/#{order_id}/invoice", invoice_params).parse
99
+ end
100
+
101
+
102
+ #
103
+ # Create offline refund for order
104
+ #
105
+ # Magento::Order.refund(order_id)
106
+ #
107
+ # or
108
+ #
109
+ # Magento::Order.refund(
110
+ # order_id,
111
+ # items: [
112
+ # {
113
+ # extension_attributes: {},
114
+ # order_item_id: 0,
115
+ # qty: 0
116
+ # }
117
+ # ],
118
+ # notify: true,
119
+ # appendComment: true,
120
+ # comment: {
121
+ # extension_attributes: {},
122
+ # comment: string,
123
+ # is_visible_on_front: 0
124
+ # },
125
+ # arguments: {
126
+ # shipping_amount: 0,
127
+ # adjustment_positive: 0,
128
+ # adjustment_negative: 0,
129
+ # extension_attributes: {
130
+ # return_to_stock_items: [
131
+ # 0
132
+ # ]
133
+ # }
134
+ # }
135
+ # )
136
+ #
137
+ # to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
138
+ #
139
+ # @return {Integer} return the refund id
140
+ def refund(order_id, refund_params = nil)
141
+ request.post("order/#{order_id}/refund", refund_params).parse
142
+ end
143
+
144
+ #
145
+ # Creates new Shipment for given Order.
146
+ #
147
+ # Magento::Order.ship(order_id)
148
+ #
149
+ # or
150
+ #
151
+ # Magento::Order.ship(
152
+ # order_id,
153
+ # capture: false,
154
+ # appendComment: true,
155
+ # items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
156
+ # tracks: [
157
+ # {
158
+ # extension_attributes: { },
159
+ # track_number: "string",
160
+ # title: "string",
161
+ # carrier_code: "string"
162
+ # }
163
+ # ]
164
+ # notify: true
165
+ # )
166
+ #
167
+ # to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
168
+ #
169
+ # @return {String}: return the shipment id
170
+ def ship(order_id, shipment_params = nil)
171
+ request.post("order/#{order_id}/ship", shipment_params).parse
172
+ end
24
173
  end
25
174
  end
26
175
  end
@@ -0,0 +1,18 @@
1
+ module Magento
2
+ class PolymorphicModel
3
+ attr_reader :api_resource
4
+
5
+ def initialize(model, api_resource)
6
+ @model = model
7
+ @api_resource = api_resource
8
+ end
9
+
10
+ def new
11
+ @model.new
12
+ end
13
+
14
+ def build(attributes)
15
+ @model.build(attributes)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Magento
2
+ class Comment
3
+ include Magento::ModelParser
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.6.0'
2
+ VERSION = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria
@@ -54,9 +54,11 @@ files:
54
54
  - lib/magento/customer.rb
55
55
  - lib/magento/errors.rb
56
56
  - lib/magento/guest_cart.rb
57
+ - lib/magento/invoice.rb
57
58
  - lib/magento/model.rb
58
59
  - lib/magento/model_mapper.rb
59
60
  - lib/magento/order.rb
61
+ - lib/magento/polymorphic_model.rb
60
62
  - lib/magento/product.rb
61
63
  - lib/magento/query.rb
62
64
  - lib/magento/record_collection.rb
@@ -66,6 +68,7 @@ files:
66
68
  - lib/magento/shared/billing_address.rb
67
69
  - lib/magento/shared/bundle_product_option.rb
68
70
  - lib/magento/shared/category_link.rb
71
+ - lib/magento/shared/comment.rb
69
72
  - lib/magento/shared/configurable_product_option.rb
70
73
  - lib/magento/shared/currency.rb
71
74
  - lib/magento/shared/custom_attribute.rb