magento 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +152 -1
- data/atrelar_produto_loja.rb +20 -0
- data/lib/magento.rb +2 -0
- data/lib/magento/invoice.rb +132 -0
- data/lib/magento/order.rb +83 -0
- data/lib/magento/polymorphic_model.rb +18 -0
- data/lib/magento/shared/comment.rb +5 -0
- data/lib/magento/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c96180295e2e45d66ac2ea4aa956ec516c3c5045d81db431538cd5462b5efcc
|
4
|
+
data.tar.gz: b2d13f614c5af4b956e97b87c7e2476d1a40fd1ada11cb94270698630d44f9b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512781570485d5af44f8567b31c4988d096682f0e3fe6119803c18385842cecbfc28bdb2a16fb02091d0000cbf2cbae2b5174cf3b0489d398450957c76377069
|
7
|
+
data.tar.gz: 51dd50c0b4a2542e6467dff88553eb5a0542f7efff10de0430a6fb3bdba32e5e8232bf4ef4e5f07b886eeebf6835aad8127791c3d84ddc89632db6ed73d35c0d
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add in your Gemfile
|
6
6
|
|
7
7
|
```rb
|
8
|
-
gem 'magento', '~> 0.
|
8
|
+
gem 'magento', '~> 0.7.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -288,6 +288,129 @@ 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
|
+
|
291
414
|
___
|
292
415
|
|
293
416
|
##TODO:
|
@@ -296,3 +419,31 @@ ___
|
|
296
419
|
```rb
|
297
420
|
Magento::Product.search('tshort')
|
298
421
|
```
|
422
|
+
|
423
|
+
### First result
|
424
|
+
```rb
|
425
|
+
Magento::Product.first
|
426
|
+
>> <Magento::Product @sku="some-sku" ...>
|
427
|
+
|
428
|
+
Magento::Product.where(name_like: 'some name%').first
|
429
|
+
>> <Magento::Product @sku="some-sku" ...>
|
430
|
+
```
|
431
|
+
|
432
|
+
### Last result
|
433
|
+
```rb
|
434
|
+
Magento::Product.last
|
435
|
+
>> <Magento::Product @sku="some-sku" ...>
|
436
|
+
|
437
|
+
Magento::Product.where(name_like: 'some name%').last
|
438
|
+
>> <Magento::Product @sku="some-sku" ...>
|
439
|
+
```
|
440
|
+
|
441
|
+
### Count result
|
442
|
+
```rb
|
443
|
+
Magento::Product.count
|
444
|
+
>> 7855
|
445
|
+
Magento::Product.where(name_like: 'some name%').count
|
446
|
+
>> 15
|
447
|
+
```
|
448
|
+
|
449
|
+
### Tests
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require './lib/magento'
|
2
|
+
|
3
|
+
Magento.url = 'https://maniadagua.com'
|
4
|
+
Magento.token = 'f44251o3xjijz8ou78hoyh8a06kdtkmh'
|
5
|
+
|
6
|
+
page = 245
|
7
|
+
|
8
|
+
loop do
|
9
|
+
products = Magento::Product.page(page).per(5).all
|
10
|
+
|
11
|
+
products.each do |product|
|
12
|
+
Magento::Product.update(product.sku, extension_attributes: { website_ids: [1, 2] })
|
13
|
+
puts "update page #{page}, product: #{product.name}"
|
14
|
+
rescue => e
|
15
|
+
puts "ERRO ao cadastrar: #{product.name}, #{e.message}"
|
16
|
+
end
|
17
|
+
|
18
|
+
break if products.last_page?
|
19
|
+
page = products.next_page
|
20
|
+
end
|
data/lib/magento.rb
CHANGED
@@ -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::Order.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/#{order_id}/refund", invoice_params).parse
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/lib/magento/order.rb
CHANGED
@@ -16,11 +16,94 @@ module Magento
|
|
16
16
|
self.class.update(attrs)
|
17
17
|
end
|
18
18
|
|
19
|
+
#
|
20
|
+
# Invoice current order
|
21
|
+
#
|
22
|
+
# order = Magento::Order.find(order_id)
|
23
|
+
#
|
24
|
+
# order.invoice # or you can pass parameters
|
25
|
+
# order.invoice(capture: false) # See the invoice class method for more information
|
26
|
+
#
|
27
|
+
# @return String: return the invoice id
|
28
|
+
def invoice(params=nil)
|
29
|
+
self.class.invoice(id, params)
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Creates new Shipment for given Order.
|
34
|
+
#
|
35
|
+
# order = Magento::Order.find(order_id)
|
36
|
+
#
|
37
|
+
# order.ship # or you can pass parameters
|
38
|
+
# order.ship(notify: false) # See the shipment class method for more information
|
39
|
+
#
|
40
|
+
# Return the shipment id
|
41
|
+
def ship(params=nil)
|
42
|
+
self.class.ship(id, params)
|
43
|
+
end
|
44
|
+
|
19
45
|
class << self
|
20
46
|
def update(attributes)
|
21
47
|
hash = request.put('orders/create', { entity_key => attributes }).parse
|
22
48
|
build(hash)
|
23
49
|
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Invoice an order
|
53
|
+
#
|
54
|
+
# Magento::Order.invoice(order_id)
|
55
|
+
#
|
56
|
+
# or
|
57
|
+
#
|
58
|
+
# Magento::Order.invoice(
|
59
|
+
# order_id,
|
60
|
+
# capture: false,
|
61
|
+
# appendComment: true,
|
62
|
+
# items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice
|
63
|
+
# comment: {
|
64
|
+
# extension_attributes: { },
|
65
|
+
# comment: "string",
|
66
|
+
# is_visible_on_front: 0
|
67
|
+
# },
|
68
|
+
# notify: true
|
69
|
+
# )
|
70
|
+
#
|
71
|
+
# to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)
|
72
|
+
#
|
73
|
+
# @return String: return the invoice id
|
74
|
+
def invoice(order_id, invoice_params=nil)
|
75
|
+
request.post("order/#{order_id}/invoice", invoice_params).parse
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Creates new Shipment for given Order.
|
80
|
+
#
|
81
|
+
# Magento::Order.ship(order_id)
|
82
|
+
#
|
83
|
+
# or
|
84
|
+
#
|
85
|
+
# Magento::Order.ship(
|
86
|
+
# order_id,
|
87
|
+
# capture: false,
|
88
|
+
# appendComment: true,
|
89
|
+
# items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment
|
90
|
+
# tracks: [
|
91
|
+
# {
|
92
|
+
# extension_attributes: { },
|
93
|
+
# track_number: "string",
|
94
|
+
# title: "string",
|
95
|
+
# carrier_code: "string"
|
96
|
+
# }
|
97
|
+
# ]
|
98
|
+
# notify: true
|
99
|
+
# )
|
100
|
+
#
|
101
|
+
# to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
|
102
|
+
#
|
103
|
+
# @return {String}: return the shipment id
|
104
|
+
def ship(order_id, shipment_params = nil)
|
105
|
+
request.post("order/#{order_id}/ship", shipment_params).parse
|
106
|
+
end
|
24
107
|
end
|
25
108
|
end
|
26
109
|
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
|
data/lib/magento/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wallas Faria
|
@@ -48,15 +48,18 @@ files:
|
|
48
48
|
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- README.md
|
51
|
+
- atrelar_produto_loja.rb
|
51
52
|
- lib/magento.rb
|
52
53
|
- lib/magento/category.rb
|
53
54
|
- lib/magento/country.rb
|
54
55
|
- lib/magento/customer.rb
|
55
56
|
- lib/magento/errors.rb
|
56
57
|
- lib/magento/guest_cart.rb
|
58
|
+
- lib/magento/invoice.rb
|
57
59
|
- lib/magento/model.rb
|
58
60
|
- lib/magento/model_mapper.rb
|
59
61
|
- lib/magento/order.rb
|
62
|
+
- lib/magento/polymorphic_model.rb
|
60
63
|
- lib/magento/product.rb
|
61
64
|
- lib/magento/query.rb
|
62
65
|
- lib/magento/record_collection.rb
|
@@ -66,6 +69,7 @@ files:
|
|
66
69
|
- lib/magento/shared/billing_address.rb
|
67
70
|
- lib/magento/shared/bundle_product_option.rb
|
68
71
|
- lib/magento/shared/category_link.rb
|
72
|
+
- lib/magento/shared/comment.rb
|
69
73
|
- lib/magento/shared/configurable_product_option.rb
|
70
74
|
- lib/magento/shared/currency.rb
|
71
75
|
- lib/magento/shared/custom_attribute.rb
|