magento 0.5.4 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b72b82d90a790c3b51e3c10b258a07e6f6d7630f778df450e911d0afaaa29ef2
4
- data.tar.gz: 1731e64391522147e55c3d1ccf32db889e00eff87781f2cf6014c0992a5e6e14
3
+ metadata.gz: 01b9ac4283305e36500f008a3344c2287efc72e1b56e8fb996161fa7e5d658a7
4
+ data.tar.gz: 6ce8510dfb9ed0977f50cb78977b98028cc2d34e205272447160d738acac56eb
5
5
  SHA512:
6
- metadata.gz: 1edc622046179fa4184261444683a344399c661a57435982fe4056bafdecbf34e07342fb6cb1bac648b384536ec9f85c6d36c00182aa522c356cf1098774a2ca
7
- data.tar.gz: 6fc45ab1a225819d6122265d21c64115c9a0008284be48f05cde90c976bfda1671a0b0a1f2c586a0af0aeac46bc61bdc95a42f388a92e482ad66469e9dd900f8
6
+ metadata.gz: 27a5885f9ede8d3ce9a2c078a6319dd04d0f1a6e74c0b1569da3525f0ca3e229fef1df0b9753e49331a667b21bfe1590575d3466c59d42b56a5349f294a01c09
7
+ data.tar.gz: 124ab9fbb4ec50b80f1117c2b0ed2af64055a0dbf7304e9ad3b410f1db6e8714be3267229625ec03cc60fdfa9ac98c3df7d4dc21eb660688aa57a1c512cc5869
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.5.4'
8
+ gem 'magento', '~> 0.8.2'
9
9
  ```
10
10
 
11
11
  or run
@@ -288,6 +288,140 @@ 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(refund_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
+ ## Other Invoice methods
365
+
366
+ ```rb
367
+ invoice = Magento::Invoice.find(invoice_id)
368
+
369
+ invoice.capture # or
370
+ Magento::Invoice.capture(invoice_id)
371
+
372
+ invoice.void # or
373
+ Magento::Invoice.void(invoice_id)
374
+
375
+ invoice.send_email # or
376
+ Magento::Invoice.send_email(invoice_id)
377
+
378
+ Magento::Invoice.comments(invoice_id).all
379
+ Magento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all
380
+ ```
381
+
382
+ ## Creates new Shipment for given Order.
383
+
384
+ ```rb
385
+ Magento::Order.ship(order_id)
386
+ >> 25 # return shipment id
387
+
388
+ # or from instance
389
+
390
+ order = Magento::Order.find(order_id)
391
+
392
+ order.ship
393
+
394
+ # you can pass parameters too
395
+
396
+ order.ship(
397
+ capture: false,
398
+ appendComment: true,
399
+ items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
400
+ tracks: [
401
+ {
402
+ extension_attributes: { },
403
+ track_number: "string",
404
+ title: "string",
405
+ carrier_code: "string"
406
+ }
407
+ ]
408
+ notify: true
409
+ )
410
+ ```
411
+
412
+ [Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
413
+
414
+
415
+ ## Cancel an Order
416
+
417
+ ```rb
418
+ order = Magento::Order.find(order_id)
419
+
420
+ order.cancel # or
421
+
422
+ Magento::Order.cancel(order_id)
423
+ ```
424
+
291
425
  ___
292
426
 
293
427
  ##TODO:
@@ -296,3 +430,31 @@ ___
296
430
  ```rb
297
431
  Magento::Product.search('tshort')
298
432
  ```
433
+
434
+ ### First result
435
+ ```rb
436
+ Magento::Product.first
437
+ >> <Magento::Product @sku="some-sku" ...>
438
+
439
+ Magento::Product.where(name_like: 'some name%').first
440
+ >> <Magento::Product @sku="some-sku" ...>
441
+ ```
442
+
443
+ ### Last result
444
+ ```rb
445
+ Magento::Product.last
446
+ >> <Magento::Product @sku="some-sku" ...>
447
+
448
+ Magento::Product.where(name_like: 'some name%').last
449
+ >> <Magento::Product @sku="some-sku" ...>
450
+ ```
451
+
452
+ ### Count result
453
+ ```rb
454
+ Magento::Product.count
455
+ >> 7855
456
+ Magento::Product.where(name_like: 'some name%').count
457
+ >> 15
458
+ ```
459
+
460
+ ### 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.invoice(notify: false) # 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,103 @@ 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
+ # Creates new Shipment for given Order.
38
+ #
39
+ # order = Magento::Order.find(order_id)
40
+ #
41
+ # order.ship # or you can pass parameters
42
+ # order.ship(notify: false) # See the shipment class method for more information
43
+ #
44
+ # Return the shipment id
45
+ def ship(params=nil)
46
+ self.class.ship(id, params)
47
+ end
48
+
19
49
  class << self
20
50
  def update(attributes)
21
51
  hash = request.put('orders/create', { entity_key => attributes }).parse
22
52
  build(hash)
23
53
  end
54
+
55
+ # @return {Boolean}
56
+ def cancel(order_id)
57
+ request.post("orders/#{order_id}/cancel").parse
58
+ end
59
+
60
+ #
61
+ # Invoice an order
62
+ #
63
+ # Magento::Order.invoice(order_id)
64
+ #
65
+ # or
66
+ #
67
+ # Magento::Order.invoice(
68
+ # order_id,
69
+ # capture: false,
70
+ # appendComment: true,
71
+ # items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
72
+ # comment: {
73
+ # extension_attributes: { },
74
+ # comment: "string",
75
+ # is_visible_on_front: 0
76
+ # },
77
+ # notify: true
78
+ # )
79
+ #
80
+ # to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
81
+ #
82
+ # @return String: return the invoice id
83
+ def invoice(order_id, invoice_params=nil)
84
+ request.post("order/#{order_id}/invoice", invoice_params).parse
85
+ end
86
+
87
+ #
88
+ # Creates new Shipment for given Order.
89
+ #
90
+ # Magento::Order.ship(order_id)
91
+ #
92
+ # or
93
+ #
94
+ # Magento::Order.ship(
95
+ # order_id,
96
+ # capture: false,
97
+ # appendComment: true,
98
+ # items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
99
+ # tracks: [
100
+ # {
101
+ # extension_attributes: { },
102
+ # track_number: "string",
103
+ # title: "string",
104
+ # carrier_code: "string"
105
+ # }
106
+ # ]
107
+ # notify: true
108
+ # )
109
+ #
110
+ # to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
111
+ #
112
+ # @return {String}: return the shipment id
113
+ def ship(order_id, shipment_params = nil)
114
+ request.post("order/#{order_id}/ship", shipment_params).parse
115
+ end
24
116
  end
25
117
  end
26
118
  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.5.4'
2
+ VERSION = '0.8.2'
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.5.4
4
+ version: 0.8.2
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