magento 0.9.2 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +1 -1
- data/README.md +592 -506
- data/lib/magento.rb +5 -0
- data/lib/magento/customer.rb +19 -4
- data/lib/magento/model.rb +14 -4
- data/lib/magento/model_mapper.rb +5 -2
- data/lib/magento/order.rb +4 -2
- data/lib/magento/params.rb +9 -0
- data/lib/magento/params/create_category.rb +21 -0
- data/lib/magento/params/create_custom_attribute.rb +17 -0
- data/lib/magento/params/create_image.rb +65 -0
- data/lib/magento/params/create_product.rb +147 -0
- data/lib/magento/product.rb +14 -0
- data/lib/magento/query.rb +16 -3
- data/lib/magento/request.rb +1 -1
- data/lib/magento/sales_rule.rb +32 -0
- data/lib/magento/shared/action_condition.rb +4 -0
- data/lib/magento/shared/condition.rb +4 -0
- data/lib/magento/version.rb +1 -1
- data/magento-ruby.gemspec +3 -0
- data/magento.gemspec +3 -0
- metadata +51 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb31fed59d9d16923e61b3f77d218087e2c2dc0e40912f59c0f0f447886ec6a4
|
4
|
+
data.tar.gz: 7d93a4d2dcef4ad968a7dacd9eb0445f7f6885791ef202873df555efad9fc4dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b15c59d8eb5f07ebc3df8e875128463790c3a26f6e96f0b076404a3aa18c7760f0d66636f3292b596f0d527da180f1125a8789dc59ed38b769b215bf02be580
|
7
|
+
data.tar.gz: 193242af27b216087e158b95bd136ee9fc70b66ca0e68711e5eda257b854beba663949a70a385b495191b12273ded59fb7dec44595a28d52704a4fe5ea1f38d5
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,506 +1,592 @@
|
|
1
|
-
# Magento Ruby library
|
2
|
-
|
3
|
-
## Install
|
4
|
-
|
5
|
-
Add in your Gemfile
|
6
|
-
|
7
|
-
```rb
|
8
|
-
gem 'magento', '~> 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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Magento::
|
42
|
-
Magento::
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
```
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
```rb
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Magento::Product
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
Magento::Product.
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
```rb
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
```
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
```rb
|
327
|
-
Magento::
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
)
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
1
|
+
# Magento Ruby library
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
Add in your Gemfile
|
6
|
+
|
7
|
+
```rb
|
8
|
+
gem 'magento', '~> 0.13.1'
|
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
|
+
## Invoice an Order
|
343
|
+
|
344
|
+
```rb
|
345
|
+
Magento::Order.invoice(order_id)
|
346
|
+
>> 25 # return incoice id
|
347
|
+
|
348
|
+
# or from instance
|
349
|
+
|
350
|
+
order = Magento::Order.find(order_id)
|
351
|
+
|
352
|
+
invoice_id = order.invoice
|
353
|
+
|
354
|
+
# you can pass parameters too
|
355
|
+
|
356
|
+
invoice_id = order.invoice(
|
357
|
+
capture: false,
|
358
|
+
appendComment: true,
|
359
|
+
items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
|
360
|
+
comment: {
|
361
|
+
extension_attributes: { },
|
362
|
+
comment: "string",
|
363
|
+
is_visible_on_front: 0
|
364
|
+
},
|
365
|
+
notify: true
|
366
|
+
)
|
367
|
+
```
|
368
|
+
|
369
|
+
[Complete Invoice Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
|
370
|
+
|
371
|
+
## Create refund for invoice
|
372
|
+
|
373
|
+
```rb
|
374
|
+
Magento::Invoice.invoice(invoice_id)
|
375
|
+
>> 12 # return refund id
|
376
|
+
|
377
|
+
# or from instance
|
378
|
+
|
379
|
+
invoice = Magento::Invoice.find(invoice_id)
|
380
|
+
|
381
|
+
refund_id = invoice.refund
|
382
|
+
|
383
|
+
# you can pass parameters too
|
384
|
+
|
385
|
+
invoice.refund(
|
386
|
+
items: [
|
387
|
+
{
|
388
|
+
extension_attributes: {},
|
389
|
+
order_item_id: 0,
|
390
|
+
qty: 0
|
391
|
+
}
|
392
|
+
],
|
393
|
+
isOnline: true,
|
394
|
+
notify: true,
|
395
|
+
appendComment: true,
|
396
|
+
comment: {
|
397
|
+
extension_attributes: {},
|
398
|
+
comment: string,
|
399
|
+
is_visible_on_front: 0
|
400
|
+
},
|
401
|
+
arguments: {
|
402
|
+
shipping_amount: 0,
|
403
|
+
adjustment_positive: 0,
|
404
|
+
adjustment_negative: 0,
|
405
|
+
extension_attributes: {
|
406
|
+
return_to_stock_items: [0]
|
407
|
+
}
|
408
|
+
}
|
409
|
+
)
|
410
|
+
```
|
411
|
+
|
412
|
+
[Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
|
413
|
+
|
414
|
+
|
415
|
+
## Create offline refund for order
|
416
|
+
|
417
|
+
```rb
|
418
|
+
Magento::Order.refund(order_id)
|
419
|
+
>> 12 # return refund id
|
420
|
+
|
421
|
+
# or from instance
|
422
|
+
|
423
|
+
order = Magento::Order.find(order_id)
|
424
|
+
|
425
|
+
order.refund
|
426
|
+
|
427
|
+
# you can pass parameters too
|
428
|
+
|
429
|
+
order.refund(
|
430
|
+
items: [
|
431
|
+
{
|
432
|
+
extension_attributes: {},
|
433
|
+
order_item_id: 0,
|
434
|
+
qty: 0
|
435
|
+
}
|
436
|
+
],
|
437
|
+
notify: true,
|
438
|
+
appendComment: true,
|
439
|
+
comment: {
|
440
|
+
extension_attributes: {},
|
441
|
+
comment: string,
|
442
|
+
is_visible_on_front: 0
|
443
|
+
},
|
444
|
+
arguments: {
|
445
|
+
shipping_amount: 0,
|
446
|
+
adjustment_positive: 0,
|
447
|
+
adjustment_negative: 0,
|
448
|
+
extension_attributes: {
|
449
|
+
return_to_stock_items: [0]
|
450
|
+
}
|
451
|
+
}
|
452
|
+
)
|
453
|
+
```
|
454
|
+
|
455
|
+
[Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
|
456
|
+
|
457
|
+
## Other Invoice methods
|
458
|
+
|
459
|
+
```rb
|
460
|
+
invoice = Magento::Invoice.find(invoice_id)
|
461
|
+
|
462
|
+
invoice.capture # or
|
463
|
+
Magento::Invoice.capture(invoice_id)
|
464
|
+
|
465
|
+
invoice.void # or
|
466
|
+
Magento::Invoice.void(invoice_id)
|
467
|
+
|
468
|
+
invoice.send_email # or
|
469
|
+
Magento::Invoice.send_email(invoice_id)
|
470
|
+
|
471
|
+
Magento::Invoice.comments(invoice_id).all
|
472
|
+
Magento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all
|
473
|
+
```
|
474
|
+
|
475
|
+
## Creates new Shipment for given Order.
|
476
|
+
|
477
|
+
```rb
|
478
|
+
Magento::Order.ship(order_id)
|
479
|
+
>> 25 # return shipment id
|
480
|
+
|
481
|
+
# or from instance
|
482
|
+
|
483
|
+
order = Magento::Order.find(order_id)
|
484
|
+
|
485
|
+
order.ship
|
486
|
+
|
487
|
+
# you can pass parameters too
|
488
|
+
|
489
|
+
order.ship(
|
490
|
+
capture: false,
|
491
|
+
appendComment: true,
|
492
|
+
items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
|
493
|
+
tracks: [
|
494
|
+
{
|
495
|
+
extension_attributes: { },
|
496
|
+
track_number: "string",
|
497
|
+
title: "string",
|
498
|
+
carrier_code: "string"
|
499
|
+
}
|
500
|
+
]
|
501
|
+
notify: true
|
502
|
+
)
|
503
|
+
```
|
504
|
+
|
505
|
+
[Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
|
506
|
+
|
507
|
+
|
508
|
+
## Cancel an Order
|
509
|
+
|
510
|
+
```rb
|
511
|
+
order = Magento::Order.find(order_id)
|
512
|
+
|
513
|
+
order.cancel # or
|
514
|
+
|
515
|
+
Magento::Order.cancel(order_id)
|
516
|
+
```
|
517
|
+
|
518
|
+
## Generate Sales Rules and Coupons
|
519
|
+
|
520
|
+
```rb
|
521
|
+
rule = Magento::SalesRule.create(
|
522
|
+
name: 'Discount name',
|
523
|
+
website_ids: [1],
|
524
|
+
customer_group_ids: [0,1,2,3],
|
525
|
+
uses_per_customer: 1,
|
526
|
+
is_active: true,
|
527
|
+
stop_rules_processing: true,
|
528
|
+
is_advanced: false,
|
529
|
+
sort_order: 0,
|
530
|
+
discount_amount: 100,
|
531
|
+
discount_step: 1,
|
532
|
+
apply_to_shipping: true,
|
533
|
+
times_used: 0,
|
534
|
+
is_rss: true,
|
535
|
+
coupon_type: 'specific',
|
536
|
+
use_auto_generation: true,
|
537
|
+
uses_per_coupon: 1
|
538
|
+
)
|
539
|
+
|
540
|
+
rule.generate_coupon(quantity: 1, length: 10)
|
541
|
+
```
|
542
|
+
|
543
|
+
Renarate by class method
|
544
|
+
```rb
|
545
|
+
Magento::SalesRule.generate_coupon(
|
546
|
+
couponSpec: {
|
547
|
+
rule_id: 7,
|
548
|
+
quantity: 1,
|
549
|
+
length: 10
|
550
|
+
}
|
551
|
+
)
|
552
|
+
```
|
553
|
+
see all params in:
|
554
|
+
- [Magento docs Coupon](https://magento.redoc.ly/2.3.5-admin/tag/couponsgenerate#operation/salesRuleCouponManagementV1GeneratePost)
|
555
|
+
- [Magento docs SalesRules](https://magento.redoc.ly/2.3.5-admin/tag/salesRules#operation/salesRuleRuleRepositoryV1SavePost)
|
556
|
+
|
557
|
+
### First result
|
558
|
+
```rb
|
559
|
+
Magento::Product.first
|
560
|
+
>> <Magento::Product @sku="some-sku" ...>
|
561
|
+
|
562
|
+
Magento::Product.where(name_like: 'some name%').first
|
563
|
+
>> <Magento::Product @sku="some-sku" ...>
|
564
|
+
```
|
565
|
+
|
566
|
+
### Count result
|
567
|
+
```rb
|
568
|
+
Magento::Product.count
|
569
|
+
>> 7855
|
570
|
+
Magento::Product.where(name_like: 'some name%').count
|
571
|
+
>> 15
|
572
|
+
```
|
573
|
+
|
574
|
+
___
|
575
|
+
|
576
|
+
##TODO:
|
577
|
+
|
578
|
+
### Search products
|
579
|
+
```rb
|
580
|
+
Magento::Product.search('tshort')
|
581
|
+
```
|
582
|
+
|
583
|
+
### Last result
|
584
|
+
```rb
|
585
|
+
Magento::Product.last
|
586
|
+
>> <Magento::Product @sku="some-sku" ...>
|
587
|
+
|
588
|
+
Magento::Product.where(name_like: 'some name%').last
|
589
|
+
>> <Magento::Product @sku="some-sku" ...>
|
590
|
+
```
|
591
|
+
|
592
|
+
### Tests
|