magento 0.5.3 → 0.8.1

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: aec02bf72da9b4812e5adbc2a2a8fd9d66b3ad31c287feff93b337de98aa8a65
4
- data.tar.gz: cef460b2b97f8d8d1af44f0bbfdf02f7f871f259b2128c79a7c446594390f33c
3
+ metadata.gz: 8ad71d2a627ff149bce29e8ad50d8f71926a19079c2af86000db29109d305c65
4
+ data.tar.gz: bc2f85e76ff1da204aa8d613a770401763bee486e6dd045af6b4e97df8758f62
5
5
  SHA512:
6
- metadata.gz: 579fe0607e167da30ef2a7b96ad6211a5adbfe7ffcfd6d9bf0460dc21bf1b9636910f1d05180ab5630975d782cec2b2ee556d7d23d37cb264163e8e243fd1f79
7
- data.tar.gz: a279b99945260866c161ed5720113efbcd9e3571be2cf8a35be742a7acf1f3fb8398c9b1d58a68727daa35874a40de715291350304f5d889e8b4cd49ca8d0bc2
6
+ metadata.gz: 2166a5412b4f41a7298efe838d5ad927d60905206af025a745420109ff87700c56d0adaaea49da0d2a4519fb34b2abafcedbabb810bfc6972fe28c92bd29c61a
7
+ data.tar.gz: 400d5d6ef1669fb147a0281312a9504ee252d7d1a46debab0bb61cdc51286d6c0c4956dfeb355a691d49bd4d0f06e044f9fe0f9968a0d3529dcdde8b36ebd732
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.5.3'
8
+ gem 'magento', '~> 0.8.1'
9
9
  ```
10
10
 
11
11
  or run
@@ -155,6 +155,12 @@ products.size
155
155
  products.current_page
156
156
  >> 1
157
157
 
158
+ products.next_page
159
+ >> 2
160
+
161
+ products.last_page?
162
+ >> false
163
+
158
164
  products.page_size
159
165
  >> 5
160
166
 
@@ -170,6 +176,8 @@ All Methods:
170
176
  ```rb
171
177
  # Information about search criteria
172
178
  :current_page
179
+ :next_page
180
+ :last_page?
173
181
  :page_size
174
182
  :total_count
175
183
  :filter_groups
@@ -280,6 +288,140 @@ cart.payment_information(
280
288
  >> "234575" # return the order id
281
289
  ```
282
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
+
283
425
  ___
284
426
 
285
427
  ##TODO:
@@ -288,3 +430,31 @@ ___
288
430
  ```rb
289
431
  Magento::Product.search('tshort')
290
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", invoice_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
@@ -23,6 +23,17 @@ module Magento
23
23
 
24
24
  alias per page_size
25
25
 
26
+ def last_page?
27
+ current_page * page_size >= total_count
28
+ end
29
+
30
+ #
31
+ # Returns the {number} of the next page or {nil}
32
+ # when the current_page is the last page
33
+ def next_page
34
+ current_page + 1 unless last_page?
35
+ end
36
+
26
37
  class << self
27
38
  def from_magento_response(response, model:, iterable_field: 'items')
28
39
  Magento::RecordCollection.new(
@@ -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.3'
2
+ VERSION = '0.8.1'
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.3
4
+ version: 0.8.1
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