magento 0.8.1 → 0.10.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 +63 -2
- data/lib/magento/customer.rb +15 -0
- data/lib/magento/invoice.rb +2 -2
- data/lib/magento/model.rb +4 -4
- data/lib/magento/order.rb +60 -3
- data/lib/magento/query.rb +16 -3
- data/lib/magento/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2d89a076f05f6e5a3f3a828d7658582a76556e57f6f0ff07a2422044ce82ab4
|
4
|
+
data.tar.gz: fbf4ab1013bf639d81781cc40042aedc5ed62062207f597e127a2ba0bc5b21b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b31854a2ad2fb3ed3ea8711c45e56a426abae13c17b392c69e0186f2594d5bb7654baf8e0dc55cf72265340153bdba56edfdff0a28836d1516d55a7c7537c4ab
|
7
|
+
data.tar.gz: 364a54b27877e55198d1cbb6f2f749aaa399301ba377ade578e2f9e092bd280002aa7cc1932c367adc8825c6790ab4aae2d39e20c30202f3a53d3cf2ecb9ce24
|
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.10.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -68,6 +68,7 @@ Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, {
|
|
68
68
|
#### Filters:
|
69
69
|
|
70
70
|
```rb
|
71
|
+
Magento::Product.where(visibility: 4).all
|
71
72
|
Magento::Product.where(name_like: 'IPhone%').all
|
72
73
|
Magento::Product.where(price_gt: 100).all
|
73
74
|
|
@@ -130,6 +131,20 @@ products = Magento::Product.select(:sku, :name)
|
|
130
131
|
.all
|
131
132
|
```
|
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
|
+
|
133
148
|
\* _same pattern to all models_
|
134
149
|
|
135
150
|
### Response
|
@@ -255,6 +270,10 @@ product.save
|
|
255
270
|
# or
|
256
271
|
|
257
272
|
product.update(name: 'Updated name')
|
273
|
+
|
274
|
+
# or
|
275
|
+
|
276
|
+
Magento::Product.update('sku-teste', name: 'Updated name')
|
258
277
|
```
|
259
278
|
|
260
279
|
### Delete
|
@@ -320,7 +339,7 @@ invoice_id = order.invoice(
|
|
320
339
|
## Create refund for invoice
|
321
340
|
|
322
341
|
```rb
|
323
|
-
Magento::Invoice.invoice(
|
342
|
+
Magento::Invoice.invoice(invoice_id)
|
324
343
|
>> 12 # return refund id
|
325
344
|
|
326
345
|
# or from instance
|
@@ -361,6 +380,48 @@ invoice.refund(
|
|
361
380
|
[Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
|
362
381
|
|
363
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
|
+
|
364
425
|
## Other Invoice methods
|
365
426
|
|
366
427
|
```rb
|
data/lib/magento/customer.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Magento
|
2
2
|
class Customer < Model
|
3
|
+
self.endpoint = 'customers/search'
|
4
|
+
|
3
5
|
def fullname
|
4
6
|
"#{@firstname} #{@lastname}"
|
5
7
|
end
|
@@ -7,11 +9,24 @@ module Magento
|
|
7
9
|
class << self
|
8
10
|
alias_method :find_by_id, :find
|
9
11
|
|
12
|
+
def update(*_attributes)
|
13
|
+
raise NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(*_attributes)
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
|
10
20
|
def find_by_token(token)
|
11
21
|
user_request = Request.new(token: token)
|
12
22
|
customer_hash = user_request.get('customers/me').parse
|
13
23
|
build(customer_hash)
|
14
24
|
end
|
25
|
+
|
26
|
+
def find(id)
|
27
|
+
hash = request.get("customers/#{id}").parse
|
28
|
+
build(hash)
|
29
|
+
end
|
15
30
|
end
|
16
31
|
end
|
17
32
|
end
|
data/lib/magento/invoice.rb
CHANGED
@@ -33,7 +33,7 @@ module Magento
|
|
33
33
|
# invoice = Magento::Invoice.find(invoice_id)
|
34
34
|
#
|
35
35
|
# invoice.refund # or you can pass parameters
|
36
|
-
# invoice.
|
36
|
+
# invoice.refund(isOnline: true) # See the refund class method for more information
|
37
37
|
#
|
38
38
|
# @return {Integer} return the refund id
|
39
39
|
def refund(refund_params = nil)
|
@@ -125,7 +125,7 @@ module Magento
|
|
125
125
|
#
|
126
126
|
# @return {Integer} return the refund id
|
127
127
|
def refund(invoice_id, refund_params=nil)
|
128
|
-
request.post("invoice/#{invoice_id}/refund",
|
128
|
+
request.post("invoice/#{invoice_id}/refund", refund_params).parse
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
data/lib/magento/model.rb
CHANGED
@@ -9,12 +9,11 @@ module Magento
|
|
9
9
|
def save
|
10
10
|
self.class.update(send(self.class.primary_key), to_h)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def update(attrs)
|
14
14
|
raise "#{self.class.name} not saved" if send(self.class.primary_key).nil?
|
15
15
|
|
16
|
-
|
17
|
-
save
|
16
|
+
self.class.update(send(self.class.primary_key), attrs)
|
18
17
|
end
|
19
18
|
|
20
19
|
def delete
|
@@ -28,7 +27,8 @@ module Magento
|
|
28
27
|
class << self
|
29
28
|
extend Forwardable
|
30
29
|
|
31
|
-
def_delegators :query, :all, :page, :per, :page_size, :order, :select,
|
30
|
+
def_delegators :query, :all, :page, :per, :page_size, :order, :select,
|
31
|
+
:where, :first, :find_by, :count
|
32
32
|
|
33
33
|
def find(id)
|
34
34
|
hash = request.get("#{api_resource}/#{id}").parse
|
data/lib/magento/order.rb
CHANGED
@@ -12,8 +12,7 @@ module Magento
|
|
12
12
|
def update(attrs)
|
13
13
|
raise "'entity_id' not found" if @entity_id.nil?
|
14
14
|
|
15
|
-
|
16
|
-
self.class.update(attrs)
|
15
|
+
self.class.update(@entity_id, attrs)
|
17
16
|
end
|
18
17
|
|
19
18
|
def cancel
|
@@ -33,6 +32,20 @@ module Magento
|
|
33
32
|
self.class.invoice(id, params)
|
34
33
|
end
|
35
34
|
|
35
|
+
|
36
|
+
#
|
37
|
+
# Create offline refund for order
|
38
|
+
#
|
39
|
+
# order = Magento::Order.find(order_id)
|
40
|
+
#
|
41
|
+
# order.refund # or you can pass parameters
|
42
|
+
# order.invoice(notify: false) # See the refund class method for more information
|
43
|
+
#
|
44
|
+
# @return {Integer} return the refund id
|
45
|
+
def refund(refund_params = nil)
|
46
|
+
self.class.refund(id, refund_params)
|
47
|
+
end
|
48
|
+
|
36
49
|
#
|
37
50
|
# Creates new Shipment for given Order.
|
38
51
|
#
|
@@ -47,7 +60,8 @@ module Magento
|
|
47
60
|
end
|
48
61
|
|
49
62
|
class << self
|
50
|
-
def update(attributes)
|
63
|
+
def update(entity_id, attributes)
|
64
|
+
attributes[:entity_id] = entity_id
|
51
65
|
hash = request.put('orders/create', { entity_key => attributes }).parse
|
52
66
|
build(hash)
|
53
67
|
end
|
@@ -84,6 +98,49 @@ module Magento
|
|
84
98
|
request.post("order/#{order_id}/invoice", invoice_params).parse
|
85
99
|
end
|
86
100
|
|
101
|
+
|
102
|
+
#
|
103
|
+
# Create offline refund for order
|
104
|
+
#
|
105
|
+
# Magento::Order.refund(order_id)
|
106
|
+
#
|
107
|
+
# or
|
108
|
+
#
|
109
|
+
# Magento::Order.refund(
|
110
|
+
# order_id,
|
111
|
+
# items: [
|
112
|
+
# {
|
113
|
+
# extension_attributes: {},
|
114
|
+
# order_item_id: 0,
|
115
|
+
# qty: 0
|
116
|
+
# }
|
117
|
+
# ],
|
118
|
+
# notify: true,
|
119
|
+
# appendComment: true,
|
120
|
+
# comment: {
|
121
|
+
# extension_attributes: {},
|
122
|
+
# comment: string,
|
123
|
+
# is_visible_on_front: 0
|
124
|
+
# },
|
125
|
+
# arguments: {
|
126
|
+
# shipping_amount: 0,
|
127
|
+
# adjustment_positive: 0,
|
128
|
+
# adjustment_negative: 0,
|
129
|
+
# extension_attributes: {
|
130
|
+
# return_to_stock_items: [
|
131
|
+
# 0
|
132
|
+
# ]
|
133
|
+
# }
|
134
|
+
# }
|
135
|
+
# )
|
136
|
+
#
|
137
|
+
# to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
|
138
|
+
#
|
139
|
+
# @return {Integer} return the refund id
|
140
|
+
def refund(order_id, refund_params = nil)
|
141
|
+
request.post("order/#{order_id}/refund", refund_params).parse
|
142
|
+
end
|
143
|
+
|
87
144
|
#
|
88
145
|
# Creates new Shipment for given Order.
|
89
146
|
#
|
data/lib/magento/query.rb
CHANGED
@@ -89,6 +89,18 @@ module Magento
|
|
89
89
|
RecordCollection.from_magento_response(result, model: model, iterable_field: field)
|
90
90
|
end
|
91
91
|
|
92
|
+
def first
|
93
|
+
page_size(1).page(1).all.first
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_by(attributes)
|
97
|
+
where(attributes).first
|
98
|
+
end
|
99
|
+
|
100
|
+
def count
|
101
|
+
select(:id).page_size(1).page(1).all.total_count
|
102
|
+
end
|
103
|
+
|
92
104
|
private
|
93
105
|
|
94
106
|
attr_accessor :current_page, :filter_groups, :request, :sort_orders, :model, :fields
|
@@ -119,10 +131,11 @@ module Magento
|
|
119
131
|
|
120
132
|
def parse_filter(key)
|
121
133
|
patter = /(.*)_([a-z]+)$/
|
122
|
-
|
123
|
-
|
134
|
+
match = key.match(patter)
|
135
|
+
|
136
|
+
return match.to_a[1..2] if match && ACCEPTED_CONDITIONS.include?(match[2])
|
124
137
|
|
125
|
-
key
|
138
|
+
[key, 'eq']
|
126
139
|
end
|
127
140
|
|
128
141
|
def parse_value_filter(condition, value)
|
data/lib/magento/version.rb
CHANGED