magento 0.11.0 → 0.15.0

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: ba575ef3ae90104d8c2fab63e96762478536391becc467892d0feee3ff9a15ad
4
- data.tar.gz: 655504007fb8ff01db537e8d7fa51641fba248ce0fdee9a0b153418b95dce688
3
+ metadata.gz: 0d7a340d50d7233fcb8e0eb877d49e1c29e0785fb76413c2216bf79c86bb420b
4
+ data.tar.gz: 6c1ad15d2b246e145d7d83082749431d89303f9c82a6fe74dd525ed52615fe28
5
5
  SHA512:
6
- metadata.gz: 720efc55bf0754e8a13dae1230208536743bc6939f53ba7ccf4d116e325e257486e4522188fee86bc1383a11c92c49692e4f193cd6d402ce23f687086549a5d2
7
- data.tar.gz: 7984a5870e45ebcd220d0426918bd5b616ae545112fd68bc0ca6ac4cb2e60b1e1891ae2e46ed233a06be9f9ae399b5de9a02e8608400ed668336903f34c71472
6
+ metadata.gz: a1e2e8fc442888fc6cd2e45f16d10186a1abf86ca990517cd0b9dbba60b2a57d015c9af2dc25e93d492413491cc4e7e1c37efa479c8e74581ce319b5d623a1ec
7
+ data.tar.gz: 219111f025c6189e6c83605e6a08f0479e1080e7ae40ff8f740aa0190df298ab71ef3b1c6c8a3757466e5a74b4d78e64c50827ad84da0a7b1a47774e6571aff8
data/.gitignore CHANGED
@@ -25,4 +25,4 @@ test/vcr_cassettes
25
25
 
26
26
  .vscode
27
27
  .byebug_history
28
- /*test.rb
28
+ /manual_test
data/Gemfile CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in pagarme.gemspec
5
+ # Specify your gem's dependencies in magento.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -1,522 +1,616 @@
1
- # Magento Ruby library
2
-
3
- ## Install
4
-
5
- Add in your Gemfile
6
-
7
- ```rb
8
- gem 'magento', '~> 0.11.0'
9
- ```
10
-
11
- or run
12
-
13
- ```sh
14
- gem install magento
15
- ```
16
-
17
- ### Setup
18
-
19
- ```rb
20
- Magento.url = 'https://yourstore.com'
21
- Magento.token = 'MAGENTO_API_KEY'
22
- Magento.store = :default # optional, Default is :all
23
-
24
- Magento.with_config(store: :other_store) do # accepts store, url and token parameters
25
- Magento::Product.find('sku')
26
- end
27
- ```
28
-
29
- ## Models
30
- ```rb
31
- Magento::Product
32
- Magento::Order
33
- Magento::Country
34
- Magento::Category
35
- Magento::Customer
36
- ```
37
-
38
- ## Get details
39
-
40
- ```rb
41
- Magento::Product.find('sku-test')
42
- Magento::Order.find(25)
43
- Magento::Country.find('BR')
44
- ```
45
- \* _same pattern to all models_
46
-
47
- **Outside pattern**
48
-
49
- Get customer by token
50
-
51
- ```rb
52
- Magento::Customer.find_by_token('user_token')
53
- ```
54
-
55
- ## Get List
56
-
57
- ```rb
58
- Magento::Product.all
59
- ```
60
-
61
- #### Select fields:
62
- ```rb
63
- Magento::Product.select(:id, :sku, :name).all
64
- Magento::Product.select(:id, :sku, :name, extension_attributes: :category_links).all
65
- Magento::Product.select(:id, :sku, :name, extension_attributes: [:category_links, :website_ids]).all
66
- Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, { category_links: :category_id }]).all
67
- ```
68
-
69
- #### Filters:
70
-
71
- ```rb
72
- Magento::Product.where(visibility: 4).all
73
- Magento::Product.where(name_like: 'IPhone%').all
74
- Magento::Product.where(price_gt: 100).all
75
-
76
- # price > 10 AND price < 20
77
- Magento::Product.where(price_gt: 10)
78
- .where(price_lt: 20).all
79
-
80
- # price < 1 OR price > 100
81
- Magento::Product.where(price_lt: 1, price_gt: 100).all
82
-
83
- Magento::Order.where(status_in: [:canceled, :complete]).all
84
- ```
85
-
86
- | Condition | Notes |
87
- | --------- | ----- |
88
- |eq | Equals. |
89
- |finset | A value within a set of values |
90
- |from | The beginning of a range. Must be used with to |
91
- |gt | Greater than |
92
- |gteq | Greater than or equal |
93
- |in | In. The value is an array |
94
- |like | Like. The value can contain the SQL wildcard characters when like is specified. |
95
- |lt | Less than |
96
- |lteq | Less than or equal |
97
- |moreq | More or equal |
98
- |neq | Not equal |
99
- |nfinset | A value that is not within a set of values |
100
- |nin | Not in. The value is an array |
101
- |notnull | Not null |
102
- |null | Null |
103
- |to | The end of a range. Must be used with from |
104
-
105
-
106
- #### SortOrder:
107
-
108
- ```rb
109
- Magento::Product.order(:sku).all
110
- Magento::Product.order(sku: :desc).all
111
- Magento::Product.order(status: :desc, name: :asc).all
112
- ```
113
-
114
- #### Pagination:
115
-
116
- ```rb
117
- # Set page and quantity per page
118
- Magento::Product.page(1) # Current page, Default is 1
119
- .page_size(25) # Default is 50
120
- .all
121
-
122
- # per is an alias to page_size
123
- Magento::Product.per(25).all
124
- ```
125
-
126
- #### Example of several options together:
127
- ```rb
128
- products = Magento::Product.select(:sku, :name)
129
- .where(name_like: 'biscoito%')
130
- .page(1)
131
- .page_size(5)
132
- .all
133
- ```
134
-
135
- ## Get one
136
-
137
- ```rb
138
- Magento::Order.where(increment_id: '000013457').first
139
- # or
140
- Magento::Order.find_by(increment_id: '000013457')
141
- ```
142
-
143
- ## Count
144
- ```rb
145
- Magento::Order.count
146
- Magento::Order.where(status: :pending).count
147
- ```
148
-
149
- \* _same pattern to all models_
150
-
151
- ### Response
152
-
153
- The `all` method retorns a `Magento::RecordCollection` instance
154
-
155
- ```rb
156
- products.first
157
- >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
158
-
159
- products[0]
160
- >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
161
-
162
- products.last
163
- >> <Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
164
-
165
- products.map(&:sku)
166
- >> ["2100", "792", "836", "913", "964"]
167
-
168
- products.size
169
- >> 5
170
-
171
- products.current_page
172
- >> 1
173
-
174
- products.next_page
175
- >> 2
176
-
177
- products.last_page?
178
- >> false
179
-
180
- products.page_size
181
- >> 5
182
-
183
- products.total_count
184
- >> 307
185
-
186
- products.filter_groups
187
- >> [<Magento::FilterGroup @filters=[<Magento::Filter @field="name", @value="biscoito%", @condition_type="like">]>]
188
- ```
189
-
190
- All Methods:
191
-
192
- ```rb
193
- # Information about search criteria
194
- :current_page
195
- :next_page
196
- :last_page?
197
- :page_size
198
- :total_count
199
- :filter_groups
200
-
201
- # Iterating with the list of items
202
- :count
203
- :length
204
- :size
205
-
206
- :first
207
- :last
208
- :[]
209
- :find
210
-
211
- :each
212
- :each_with_index
213
- :sample
214
-
215
- :map
216
- :select
217
- :filter
218
- :reject
219
- :collect
220
- :take
221
- :take_while
222
-
223
- :sort
224
- :sort_by
225
- :reverse_each
226
- :reverse
227
-
228
- :all?
229
- :any?
230
- :none?
231
- :one?
232
- :empty?
233
- ```
234
-
235
- ## Create
236
-
237
- ```rb
238
- Magento::Order.create(
239
- customer_firstname: '',
240
- customer_lastname: '',
241
- customer_email: '',
242
- # others attrbutes ...,
243
- items: [
244
- {
245
- sku: '',
246
- price: '',
247
- qty_ordered: 1,
248
- # others attrbutes ...,
249
- }
250
- ],
251
- billing_address: {
252
- # attrbutes...
253
- },
254
- payment: {
255
- # attrbutes...
256
- },
257
- extension_attributes: {
258
- # attrbutes...
259
- }
260
- )
261
- ```
262
-
263
- ### Update
264
-
265
- ```rb
266
- product = Magento::Product.find('sku-teste')
267
-
268
- product.name = 'Updated name'
269
- product.save
270
-
271
- # or
272
-
273
- product.update(name: 'Updated name')
274
-
275
- # or
276
-
277
- Magento::Product.update('sku-teste', name: 'Updated name')
278
- ```
279
-
280
- ### Delete
281
-
282
- ```rb
283
- product = Magento::Product.find('sku-teste')
284
-
285
- product.delete
286
-
287
- # or
288
-
289
- Magento::Product.delete('sku-teste')
290
- ```
291
-
292
- ## GuestCart
293
-
294
- Set payment information to finish the order
295
- ```rb
296
- cart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')
297
-
298
- # or use "build" to not request information from the magento API
299
- cart = Magento::GuestCart.build(
300
- cart_id: 'aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN'
301
- )
302
-
303
- cart.payment_information(
304
- email: 'customer@gmail.com',
305
- payment: { method: 'cashondelivery' }
306
- )
307
-
308
- >> "234575" # return the order id
309
- ```
310
-
311
- ## Invoice an Order
312
-
313
- ```rb
314
- Magento::Order.invoice(order_id)
315
- >> 25 # return incoice id
316
-
317
- # or from instance
318
-
319
- order = Magento::Order.find(order_id)
320
-
321
- invoice_id = order.invoice
322
-
323
- # you can pass parameters too
324
-
325
- invoice_id = order.invoice(
326
- capture: false,
327
- appendComment: true,
328
- items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
329
- comment: {
330
- extension_attributes: { },
331
- comment: "string",
332
- is_visible_on_front: 0
333
- },
334
- notify: true
335
- )
336
- ```
337
-
338
- [Complete Invoice Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
339
-
340
- ## Create refund for invoice
341
-
342
- ```rb
343
- Magento::Invoice.invoice(invoice_id)
344
- >> 12 # return refund id
345
-
346
- # or from instance
347
-
348
- invoice = Magento::Invoice.find(invoice_id)
349
-
350
- refund_id = invoice.refund
351
-
352
- # you can pass parameters too
353
-
354
- invoice.refund(
355
- items: [
356
- {
357
- extension_attributes: {},
358
- order_item_id: 0,
359
- qty: 0
360
- }
361
- ],
362
- isOnline: true,
363
- notify: true,
364
- appendComment: true,
365
- comment: {
366
- extension_attributes: {},
367
- comment: string,
368
- is_visible_on_front: 0
369
- },
370
- arguments: {
371
- shipping_amount: 0,
372
- adjustment_positive: 0,
373
- adjustment_negative: 0,
374
- extension_attributes: {
375
- return_to_stock_items: [0]
376
- }
377
- }
378
- )
379
- ```
380
-
381
- [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
382
-
383
-
384
- ## Create offline refund for order
385
-
386
- ```rb
387
- Magento::Order.refund(order_id)
388
- >> 12 # return refund id
389
-
390
- # or from instance
391
-
392
- order = Magento::Order.find(order_id)
393
-
394
- order.refund
395
-
396
- # you can pass parameters too
397
-
398
- order.refund(
399
- items: [
400
- {
401
- extension_attributes: {},
402
- order_item_id: 0,
403
- qty: 0
404
- }
405
- ],
406
- notify: true,
407
- appendComment: true,
408
- comment: {
409
- extension_attributes: {},
410
- comment: string,
411
- is_visible_on_front: 0
412
- },
413
- arguments: {
414
- shipping_amount: 0,
415
- adjustment_positive: 0,
416
- adjustment_negative: 0,
417
- extension_attributes: {
418
- return_to_stock_items: [0]
419
- }
420
- }
421
- )
422
- ```
423
-
424
- [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
425
-
426
- ## Other Invoice methods
427
-
428
- ```rb
429
- invoice = Magento::Invoice.find(invoice_id)
430
-
431
- invoice.capture # or
432
- Magento::Invoice.capture(invoice_id)
433
-
434
- invoice.void # or
435
- Magento::Invoice.void(invoice_id)
436
-
437
- invoice.send_email # or
438
- Magento::Invoice.send_email(invoice_id)
439
-
440
- Magento::Invoice.comments(invoice_id).all
441
- Magento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all
442
- ```
443
-
444
- ## Creates new Shipment for given Order.
445
-
446
- ```rb
447
- Magento::Order.ship(order_id)
448
- >> 25 # return shipment id
449
-
450
- # or from instance
451
-
452
- order = Magento::Order.find(order_id)
453
-
454
- order.ship
455
-
456
- # you can pass parameters too
457
-
458
- order.ship(
459
- capture: false,
460
- appendComment: true,
461
- items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
462
- tracks: [
463
- {
464
- extension_attributes: { },
465
- track_number: "string",
466
- title: "string",
467
- carrier_code: "string"
468
- }
469
- ]
470
- notify: true
471
- )
472
- ```
473
-
474
- [Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
475
-
476
-
477
- ## Cancel an Order
478
-
479
- ```rb
480
- order = Magento::Order.find(order_id)
481
-
482
- order.cancel # or
483
-
484
- Magento::Order.cancel(order_id)
485
- ```
486
-
487
- ___
488
-
489
- ##TODO:
490
-
491
- ### Search products
492
- ```rb
493
- Magento::Product.search('tshort')
494
- ```
495
-
496
- ### First result
497
- ```rb
498
- Magento::Product.first
499
- >> <Magento::Product @sku="some-sku" ...>
500
-
501
- Magento::Product.where(name_like: 'some name%').first
502
- >> <Magento::Product @sku="some-sku" ...>
503
- ```
504
-
505
- ### Last result
506
- ```rb
507
- Magento::Product.last
508
- >> <Magento::Product @sku="some-sku" ...>
509
-
510
- Magento::Product.where(name_like: 'some name%').last
511
- >> <Magento::Product @sku="some-sku" ...>
512
- ```
513
-
514
- ### Count result
515
- ```rb
516
- Magento::Product.count
517
- >> 7855
518
- Magento::Product.where(name_like: 'some name%').count
519
- >> 15
520
- ```
521
-
522
- ### Tests
1
+ # Magento Ruby library
2
+
3
+ ## Install
4
+
5
+ Add in your Gemfile
6
+
7
+ ```rb
8
+ gem 'magento', '~> 0.15.0'
9
+ ```
10
+
11
+ or run
12
+
13
+ ```sh
14
+ gem install magento
15
+ ```
16
+
17
+ ### Setup
18
+
19
+ ```rb
20
+ Magento.url = 'https://yourstore.com'
21
+ Magento.token = 'MAGENTO_API_KEY'
22
+ Magento.store = :default # optional, Default is :all
23
+
24
+ Magento.with_config(store: :other_store) do # accepts store, url and token parameters
25
+ Magento::Product.find('sku')
26
+ end
27
+ ```
28
+
29
+ ## Models
30
+ ```rb
31
+ Magento::Product
32
+ Magento::Order
33
+ Magento::Country
34
+ Magento::Category
35
+ Magento::Customer
36
+ ```
37
+
38
+ ## Get details
39
+
40
+ ```rb
41
+ Magento::Product.find('sku-test')
42
+ Magento::Order.find(25)
43
+ Magento::Country.find('BR')
44
+ ```
45
+ \* _same pattern to all models_
46
+
47
+ **Outside pattern**
48
+
49
+ Get customer by token
50
+
51
+ ```rb
52
+ Magento::Customer.find_by_token('user_token')
53
+ ```
54
+
55
+ ## Shurtcut to get custom attribute value by custom attribute code in product
56
+
57
+ Exemple:
58
+
59
+ ```rb
60
+ product.attr :description
61
+ # it is the same as
62
+ product.custom_attributes.find { |a| a.attribute_code == 'description' }&.value
63
+
64
+ # or
65
+ product.description
66
+ ```
67
+
68
+ when the custom attribute does not exists:
69
+
70
+ ```rb
71
+ product.attr :special_price
72
+ > nil
73
+
74
+ product.special_price
75
+ > NoMethodError: undefined method `special_price' for #<Magento::Product:...>
76
+ ```
77
+
78
+ ```rb
79
+ product.respond_to? :special_price
80
+ > false
81
+
82
+ product.respond_to? :description
83
+ > true
84
+ ```
85
+
86
+ ## Get List
87
+
88
+ ```rb
89
+ Magento::Product.all
90
+ ```
91
+
92
+ #### Select fields:
93
+ ```rb
94
+ Magento::Product.select(:id, :sku, :name).all
95
+ Magento::Product.select(:id, :sku, :name, extension_attributes: :category_links).all
96
+ Magento::Product.select(:id, :sku, :name, extension_attributes: [:category_links, :website_ids]).all
97
+ Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, { category_links: :category_id }]).all
98
+ ```
99
+
100
+ #### Filters:
101
+
102
+ ```rb
103
+ Magento::Product.where(visibility: 4).all
104
+ Magento::Product.where(name_like: 'IPhone%').all
105
+ Magento::Product.where(price_gt: 100).all
106
+
107
+ # price > 10 AND price < 20
108
+ Magento::Product.where(price_gt: 10)
109
+ .where(price_lt: 20).all
110
+
111
+ # price < 1 OR price > 100
112
+ Magento::Product.where(price_lt: 1, price_gt: 100).all
113
+
114
+ Magento::Order.where(status_in: [:canceled, :complete]).all
115
+ ```
116
+
117
+ | Condition | Notes |
118
+ | --------- | ----- |
119
+ |eq | Equals. |
120
+ |finset | A value within a set of values |
121
+ |from | The beginning of a range. Must be used with to |
122
+ |gt | Greater than |
123
+ |gteq | Greater than or equal |
124
+ |in | In. The value is an array |
125
+ |like | Like. The value can contain the SQL wildcard characters when like is specified. |
126
+ |lt | Less than |
127
+ |lteq | Less than or equal |
128
+ |moreq | More or equal |
129
+ |neq | Not equal |
130
+ |nfinset | A value that is not within a set of values |
131
+ |nin | Not in. The value is an array |
132
+ |notnull | Not null |
133
+ |null | Null |
134
+ |to | The end of a range. Must be used with from |
135
+
136
+
137
+ #### SortOrder:
138
+
139
+ ```rb
140
+ Magento::Product.order(:sku).all
141
+ Magento::Product.order(sku: :desc).all
142
+ Magento::Product.order(status: :desc, name: :asc).all
143
+ ```
144
+
145
+ #### Pagination:
146
+
147
+ ```rb
148
+ # Set page and quantity per page
149
+ Magento::Product.page(1) # Current page, Default is 1
150
+ .page_size(25) # Default is 50
151
+ .all
152
+
153
+ # per is an alias to page_size
154
+ Magento::Product.per(25).all
155
+ ```
156
+
157
+ #### Example of several options together:
158
+ ```rb
159
+ products = Magento::Product.select(:sku, :name)
160
+ .where(name_like: 'biscoito%')
161
+ .page(1)
162
+ .page_size(5)
163
+ .all
164
+ ```
165
+
166
+ ## Get one
167
+
168
+ ```rb
169
+ Magento::Order.where(increment_id: '000013457').first
170
+ # or
171
+ Magento::Order.find_by(increment_id: '000013457')
172
+ ```
173
+
174
+ ## Count
175
+ ```rb
176
+ Magento::Order.count
177
+ Magento::Order.where(status: :pending).count
178
+ ```
179
+
180
+ \* _same pattern to all models_
181
+
182
+ ### Response
183
+
184
+ The `all` method retorns a `Magento::RecordCollection` instance
185
+
186
+ ```rb
187
+ products.first
188
+ >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
189
+
190
+ products[0]
191
+ >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
192
+
193
+ products.last
194
+ >> <Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
195
+
196
+ products.map(&:sku)
197
+ >> ["2100", "792", "836", "913", "964"]
198
+
199
+ products.size
200
+ >> 5
201
+
202
+ products.current_page
203
+ >> 1
204
+
205
+ products.next_page
206
+ >> 2
207
+
208
+ products.last_page?
209
+ >> false
210
+
211
+ products.page_size
212
+ >> 5
213
+
214
+ products.total_count
215
+ >> 307
216
+
217
+ products.filter_groups
218
+ >> [<Magento::FilterGroup @filters=[<Magento::Filter @field="name", @value="biscoito%", @condition_type="like">]>]
219
+ ```
220
+
221
+ All Methods:
222
+
223
+ ```rb
224
+ # Information about search criteria
225
+ :current_page
226
+ :next_page
227
+ :last_page?
228
+ :page_size
229
+ :total_count
230
+ :filter_groups
231
+
232
+ # Iterating with the list of items
233
+ :count
234
+ :length
235
+ :size
236
+
237
+ :first
238
+ :last
239
+ :[]
240
+ :find
241
+
242
+ :each
243
+ :each_with_index
244
+ :sample
245
+
246
+ :map
247
+ :select
248
+ :filter
249
+ :reject
250
+ :collect
251
+ :take
252
+ :take_while
253
+
254
+ :sort
255
+ :sort_by
256
+ :reverse_each
257
+ :reverse
258
+
259
+ :all?
260
+ :any?
261
+ :none?
262
+ :one?
263
+ :empty?
264
+ ```
265
+
266
+ ## Create
267
+
268
+ ```rb
269
+ Magento::Order.create(
270
+ customer_firstname: '',
271
+ customer_lastname: '',
272
+ customer_email: '',
273
+ # others attrbutes ...,
274
+ items: [
275
+ {
276
+ sku: '',
277
+ price: '',
278
+ qty_ordered: 1,
279
+ # others attrbutes ...,
280
+ }
281
+ ],
282
+ billing_address: {
283
+ # attrbutes...
284
+ },
285
+ payment: {
286
+ # attrbutes...
287
+ },
288
+ extension_attributes: {
289
+ # attrbutes...
290
+ }
291
+ )
292
+ ```
293
+
294
+ ### Update
295
+
296
+ ```rb
297
+ product = Magento::Product.find('sku-teste')
298
+
299
+ product.name = 'Updated name'
300
+ product.save
301
+
302
+ # or
303
+
304
+ product.update(name: 'Updated name')
305
+
306
+ # or
307
+
308
+ Magento::Product.update('sku-teste', name: 'Updated name')
309
+ ```
310
+
311
+ ### Delete
312
+
313
+ ```rb
314
+ product = Magento::Product.find('sku-teste')
315
+
316
+ product.delete
317
+
318
+ # or
319
+
320
+ Magento::Product.delete('sku-teste')
321
+ ```
322
+
323
+ ## GuestCart
324
+
325
+ Set payment information to finish the order
326
+ ```rb
327
+ cart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')
328
+
329
+ # or use "build" to not request information from the magento API
330
+ cart = Magento::GuestCart.build(
331
+ cart_id: 'aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN'
332
+ )
333
+
334
+ cart.payment_information(
335
+ email: 'customer@gmail.com',
336
+ payment: { method: 'cashondelivery' }
337
+ )
338
+
339
+ >> "234575" # return the order id
340
+ ```
341
+
342
+ Add coupon to cart
343
+ ```rb
344
+ cart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')
345
+
346
+ cart.add_coupon('COAU4HXE0I')
347
+ # You can also use the class method
348
+ Magento::GuestCart.add_coupon('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7', 'COAU4HXE0I')
349
+
350
+ >> true # return true on success
351
+ ```
352
+
353
+ Delete coupon from cart
354
+ ```rb
355
+ cart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')
356
+
357
+ cart.delete_coupon()
358
+ # You can also use the class method
359
+ Magento::GuestCart.delete_coupon('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')
360
+
361
+ >> true # return true on success
362
+ ```
363
+
364
+ ## Invoice an Order
365
+
366
+ ```rb
367
+ Magento::Order.invoice(order_id)
368
+ >> 25 # return incoice id
369
+
370
+ # or from instance
371
+
372
+ order = Magento::Order.find(order_id)
373
+
374
+ invoice_id = order.invoice
375
+
376
+ # you can pass parameters too
377
+
378
+ invoice_id = order.invoice(
379
+ capture: false,
380
+ appendComment: true,
381
+ items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
382
+ comment: {
383
+ extension_attributes: { },
384
+ comment: "string",
385
+ is_visible_on_front: 0
386
+ },
387
+ notify: true
388
+ )
389
+ ```
390
+
391
+ [Complete Invoice Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
392
+
393
+ ## Create refund for invoice
394
+
395
+ ```rb
396
+ Magento::Invoice.invoice(invoice_id)
397
+ >> 12 # return refund id
398
+
399
+ # or from instance
400
+
401
+ invoice = Magento::Invoice.find(invoice_id)
402
+
403
+ refund_id = invoice.refund
404
+
405
+ # you can pass parameters too
406
+
407
+ invoice.refund(
408
+ items: [
409
+ {
410
+ extension_attributes: {},
411
+ order_item_id: 0,
412
+ qty: 0
413
+ }
414
+ ],
415
+ isOnline: true,
416
+ notify: true,
417
+ appendComment: true,
418
+ comment: {
419
+ extension_attributes: {},
420
+ comment: string,
421
+ is_visible_on_front: 0
422
+ },
423
+ arguments: {
424
+ shipping_amount: 0,
425
+ adjustment_positive: 0,
426
+ adjustment_negative: 0,
427
+ extension_attributes: {
428
+ return_to_stock_items: [0]
429
+ }
430
+ }
431
+ )
432
+ ```
433
+
434
+ [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
435
+
436
+
437
+ ## Create offline refund for order
438
+
439
+ ```rb
440
+ Magento::Order.refund(order_id)
441
+ >> 12 # return refund id
442
+
443
+ # or from instance
444
+
445
+ order = Magento::Order.find(order_id)
446
+
447
+ order.refund
448
+
449
+ # you can pass parameters too
450
+
451
+ order.refund(
452
+ items: [
453
+ {
454
+ extension_attributes: {},
455
+ order_item_id: 0,
456
+ qty: 0
457
+ }
458
+ ],
459
+ notify: true,
460
+ appendComment: true,
461
+ comment: {
462
+ extension_attributes: {},
463
+ comment: string,
464
+ is_visible_on_front: 0
465
+ },
466
+ arguments: {
467
+ shipping_amount: 0,
468
+ adjustment_positive: 0,
469
+ adjustment_negative: 0,
470
+ extension_attributes: {
471
+ return_to_stock_items: [0]
472
+ }
473
+ }
474
+ )
475
+ ```
476
+
477
+ [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
478
+
479
+ ## Other Invoice methods
480
+
481
+ ```rb
482
+ invoice = Magento::Invoice.find(invoice_id)
483
+
484
+ invoice.capture # or
485
+ Magento::Invoice.capture(invoice_id)
486
+
487
+ invoice.void # or
488
+ Magento::Invoice.void(invoice_id)
489
+
490
+ invoice.send_email # or
491
+ Magento::Invoice.send_email(invoice_id)
492
+
493
+ Magento::Invoice.comments(invoice_id).all
494
+ Magento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all
495
+ ```
496
+
497
+ ## Creates new Shipment for given Order.
498
+
499
+ ```rb
500
+ Magento::Order.ship(order_id)
501
+ >> 25 # return shipment id
502
+
503
+ # or from instance
504
+
505
+ order = Magento::Order.find(order_id)
506
+
507
+ order.ship
508
+
509
+ # you can pass parameters too
510
+
511
+ order.ship(
512
+ capture: false,
513
+ appendComment: true,
514
+ items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
515
+ tracks: [
516
+ {
517
+ extension_attributes: { },
518
+ track_number: "string",
519
+ title: "string",
520
+ carrier_code: "string"
521
+ }
522
+ ]
523
+ notify: true
524
+ )
525
+ ```
526
+
527
+ [Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
528
+
529
+
530
+ ## Cancel an Order
531
+
532
+ ```rb
533
+ order = Magento::Order.find(order_id)
534
+
535
+ order.cancel # or
536
+
537
+ Magento::Order.cancel(order_id)
538
+ ```
539
+
540
+ ## Generate Sales Rules and Coupons
541
+
542
+ ```rb
543
+ rule = Magento::SalesRule.create(
544
+ name: 'Discount name',
545
+ website_ids: [1],
546
+ customer_group_ids: [0,1,2,3],
547
+ uses_per_customer: 1,
548
+ is_active: true,
549
+ stop_rules_processing: true,
550
+ is_advanced: false,
551
+ sort_order: 0,
552
+ discount_amount: 100,
553
+ discount_step: 1,
554
+ apply_to_shipping: true,
555
+ times_used: 0,
556
+ is_rss: true,
557
+ coupon_type: 'specific',
558
+ use_auto_generation: true,
559
+ uses_per_coupon: 1
560
+ )
561
+
562
+ rule.generate_coupon(quantity: 1, length: 10)
563
+ ```
564
+
565
+ Generate by class method
566
+ ```rb
567
+ Magento::SalesRule.generate_coupon(
568
+ couponSpec: {
569
+ rule_id: 7,
570
+ quantity: 1,
571
+ length: 10
572
+ }
573
+ )
574
+ ```
575
+ see all params in:
576
+ - [Magento docs Coupon](https://magento.redoc.ly/2.3.5-admin/tag/couponsgenerate#operation/salesRuleCouponManagementV1GeneratePost)
577
+ - [Magento docs SalesRules](https://magento.redoc.ly/2.3.5-admin/tag/salesRules#operation/salesRuleRuleRepositoryV1SavePost)
578
+
579
+ See [how to add coupons to cart](#guestcart)
580
+
581
+ ### First result
582
+ ```rb
583
+ Magento::Product.first
584
+ >> <Magento::Product @sku="some-sku" ...>
585
+
586
+ Magento::Product.where(name_like: 'some name%').first
587
+ >> <Magento::Product @sku="some-sku" ...>
588
+ ```
589
+
590
+ ### Count result
591
+ ```rb
592
+ Magento::Product.count
593
+ >> 7855
594
+ Magento::Product.where(name_like: 'some name%').count
595
+ >> 15
596
+ ```
597
+
598
+ ___
599
+
600
+ ##TODO:
601
+
602
+ ### Search products
603
+ ```rb
604
+ Magento::Product.search('tshort')
605
+ ```
606
+
607
+ ### Last result
608
+ ```rb
609
+ Magento::Product.last
610
+ >> <Magento::Product @sku="some-sku" ...>
611
+
612
+ Magento::Product.where(name_like: 'some name%').last
613
+ >> <Magento::Product @sku="some-sku" ...>
614
+ ```
615
+
616
+ ### Tests