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