magento 0.8.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -2
- data/lib/magento/customer.rb +30 -0
- data/lib/magento/invoice.rb +1 -1
- data/lib/magento/model.rb +15 -6
- data/lib/magento/model_mapper.rb +5 -2
- data/lib/magento/order.rb +63 -4
- 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: ba575ef3ae90104d8c2fab63e96762478536391becc467892d0feee3ff9a15ad
|
4
|
+
data.tar.gz: 655504007fb8ff01db537e8d7fa51641fba248ce0fdee9a0b153418b95dce688
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720efc55bf0754e8a13dae1230208536743bc6939f53ba7ccf4d116e325e257486e4522188fee86bc1383a11c92c49692e4f193cd6d402ce23f687086549a5d2
|
7
|
+
data.tar.gz: 7984a5870e45ebcd220d0426918bd5b616ae545112fd68bc0ca6ac4cb2e60b1e1891ae2e46ed233a06be9f9ae399b5de9a02e8608400ed668336903f34c71472
|
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.11.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -32,6 +32,7 @@ Magento::Product
|
|
32
32
|
Magento::Order
|
33
33
|
Magento::Country
|
34
34
|
Magento::Category
|
35
|
+
Magento::Customer
|
35
36
|
```
|
36
37
|
|
37
38
|
## Get details
|
@@ -68,6 +69,7 @@ Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, {
|
|
68
69
|
#### Filters:
|
69
70
|
|
70
71
|
```rb
|
72
|
+
Magento::Product.where(visibility: 4).all
|
71
73
|
Magento::Product.where(name_like: 'IPhone%').all
|
72
74
|
Magento::Product.where(price_gt: 100).all
|
73
75
|
|
@@ -130,6 +132,20 @@ products = Magento::Product.select(:sku, :name)
|
|
130
132
|
.all
|
131
133
|
```
|
132
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
|
+
|
133
149
|
\* _same pattern to all models_
|
134
150
|
|
135
151
|
### Response
|
@@ -255,6 +271,10 @@ product.save
|
|
255
271
|
# or
|
256
272
|
|
257
273
|
product.update(name: 'Updated name')
|
274
|
+
|
275
|
+
# or
|
276
|
+
|
277
|
+
Magento::Product.update('sku-teste', name: 'Updated name')
|
258
278
|
```
|
259
279
|
|
260
280
|
### Delete
|
@@ -320,7 +340,7 @@ invoice_id = order.invoice(
|
|
320
340
|
## Create refund for invoice
|
321
341
|
|
322
342
|
```rb
|
323
|
-
Magento::Invoice.invoice(
|
343
|
+
Magento::Invoice.invoice(invoice_id)
|
324
344
|
>> 12 # return refund id
|
325
345
|
|
326
346
|
# or from instance
|
@@ -361,6 +381,48 @@ invoice.refund(
|
|
361
381
|
[Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
|
362
382
|
|
363
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
|
+
|
364
426
|
## Other Invoice methods
|
365
427
|
|
366
428
|
```rb
|
data/lib/magento/customer.rb
CHANGED
@@ -1,17 +1,47 @@
|
|
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
|
6
8
|
|
9
|
+
def update(attributes)
|
10
|
+
raise "id not present" if @id.nil?
|
11
|
+
|
12
|
+
attributes.each { |key, value| send("#{key}=", value) }
|
13
|
+
save
|
14
|
+
end
|
15
|
+
|
7
16
|
class << self
|
8
17
|
alias_method :find_by_id, :find
|
9
18
|
|
19
|
+
def update(id, attributes)
|
20
|
+
hash = request.put("customers/#{id}", { customer: attributes }).parse
|
21
|
+
|
22
|
+
block_given? ? yield(hash) : build(hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create(attributes)
|
26
|
+
attributes.transform_keys!(&:to_sym)
|
27
|
+
password = attributes.delete :password
|
28
|
+
hash = request.post("customers", {
|
29
|
+
customer: attributes,
|
30
|
+
password: password
|
31
|
+
}).parse
|
32
|
+
build(hash)
|
33
|
+
end
|
34
|
+
|
10
35
|
def find_by_token(token)
|
11
36
|
user_request = Request.new(token: token)
|
12
37
|
customer_hash = user_request.get('customers/me').parse
|
13
38
|
build(customer_hash)
|
14
39
|
end
|
40
|
+
|
41
|
+
def find(id)
|
42
|
+
hash = request.get("customers/#{id}").parse
|
43
|
+
build(hash)
|
44
|
+
end
|
15
45
|
end
|
16
46
|
end
|
17
47
|
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)
|
data/lib/magento/model.rb
CHANGED
@@ -7,14 +7,17 @@ module Magento
|
|
7
7
|
include Magento::ModelParser
|
8
8
|
|
9
9
|
def save
|
10
|
-
self.class.update(send(self.class.primary_key), to_h)
|
10
|
+
self.class.update(send(self.class.primary_key), to_h) do |hash|
|
11
|
+
update_attributes(hash)
|
12
|
+
end
|
11
13
|
end
|
12
|
-
|
14
|
+
|
13
15
|
def update(attrs)
|
14
16
|
raise "#{self.class.name} not saved" if send(self.class.primary_key).nil?
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
self.class.update(send(self.class.primary_key), attrs) do |hash|
|
19
|
+
update_attributes(hash)
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def delete
|
@@ -25,10 +28,15 @@ module Magento
|
|
25
28
|
@id || send(self.class.primary_key)
|
26
29
|
end
|
27
30
|
|
31
|
+
protected def update_attributes(hash)
|
32
|
+
ModelMapper.map_hash(self, hash)
|
33
|
+
end
|
34
|
+
|
28
35
|
class << self
|
29
36
|
extend Forwardable
|
30
37
|
|
31
|
-
def_delegators :query, :all, :page, :per, :page_size, :order, :select,
|
38
|
+
def_delegators :query, :all, :page, :per, :page_size, :order, :select,
|
39
|
+
:where, :first, :find_by, :count
|
32
40
|
|
33
41
|
def find(id)
|
34
42
|
hash = request.get("#{api_resource}/#{id}").parse
|
@@ -48,7 +56,8 @@ module Magento
|
|
48
56
|
def update(id, attributes)
|
49
57
|
body = { entity_key => attributes }
|
50
58
|
hash = request.put("#{api_resource}/#{id}", body).parse
|
51
|
-
|
59
|
+
|
60
|
+
block_given? ? yield(hash) : build(hash)
|
52
61
|
end
|
53
62
|
|
54
63
|
def api_resource
|
data/lib/magento/model_mapper.rb
CHANGED
@@ -17,9 +17,12 @@ module Magento
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.map_hash(model, values)
|
20
|
-
object = model.new
|
20
|
+
object = model.is_a?(Class) ? model.new : model
|
21
21
|
values.each do |key, value|
|
22
|
-
object.
|
22
|
+
unless object.respond_to?(key) && object.respond_to?("#{key}=")
|
23
|
+
object.singleton_class.instance_eval { attr_accessor key }
|
24
|
+
end
|
25
|
+
|
23
26
|
if value.is_a?(Hash)
|
24
27
|
class_name = Magento.inflector.camelize(Magento.inflector.singularize(key))
|
25
28
|
value = map_hash(Object.const_get("Magento::#{class_name}"), value)
|
data/lib/magento/order.rb
CHANGED
@@ -12,8 +12,9 @@ module Magento
|
|
12
12
|
def update(attrs)
|
13
13
|
raise "'entity_id' not found" if @entity_id.nil?
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
self.class.update(@entity_id, attrs) do |hash|
|
16
|
+
update_attributes(hash)
|
17
|
+
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def cancel
|
@@ -33,6 +34,20 @@ module Magento
|
|
33
34
|
self.class.invoice(id, params)
|
34
35
|
end
|
35
36
|
|
37
|
+
|
38
|
+
#
|
39
|
+
# Create offline refund for order
|
40
|
+
#
|
41
|
+
# order = Magento::Order.find(order_id)
|
42
|
+
#
|
43
|
+
# order.refund # or you can pass parameters
|
44
|
+
# order.invoice(notify: false) # See the refund class method for more information
|
45
|
+
#
|
46
|
+
# @return {Integer} return the refund id
|
47
|
+
def refund(refund_params = nil)
|
48
|
+
self.class.refund(id, refund_params)
|
49
|
+
end
|
50
|
+
|
36
51
|
#
|
37
52
|
# Creates new Shipment for given Order.
|
38
53
|
#
|
@@ -47,9 +62,10 @@ module Magento
|
|
47
62
|
end
|
48
63
|
|
49
64
|
class << self
|
50
|
-
def update(attributes)
|
65
|
+
def update(entity_id, attributes)
|
66
|
+
attributes[:entity_id] = entity_id
|
51
67
|
hash = request.put('orders/create', { entity_key => attributes }).parse
|
52
|
-
build(hash)
|
68
|
+
block_given? ? yield(hash) : build(hash)
|
53
69
|
end
|
54
70
|
|
55
71
|
# @return {Boolean}
|
@@ -84,6 +100,49 @@ module Magento
|
|
84
100
|
request.post("order/#{order_id}/invoice", invoice_params).parse
|
85
101
|
end
|
86
102
|
|
103
|
+
|
104
|
+
#
|
105
|
+
# Create offline refund for order
|
106
|
+
#
|
107
|
+
# Magento::Order.refund(order_id)
|
108
|
+
#
|
109
|
+
# or
|
110
|
+
#
|
111
|
+
# Magento::Order.refund(
|
112
|
+
# order_id,
|
113
|
+
# items: [
|
114
|
+
# {
|
115
|
+
# extension_attributes: {},
|
116
|
+
# order_item_id: 0,
|
117
|
+
# qty: 0
|
118
|
+
# }
|
119
|
+
# ],
|
120
|
+
# notify: true,
|
121
|
+
# appendComment: true,
|
122
|
+
# comment: {
|
123
|
+
# extension_attributes: {},
|
124
|
+
# comment: string,
|
125
|
+
# is_visible_on_front: 0
|
126
|
+
# },
|
127
|
+
# arguments: {
|
128
|
+
# shipping_amount: 0,
|
129
|
+
# adjustment_positive: 0,
|
130
|
+
# adjustment_negative: 0,
|
131
|
+
# extension_attributes: {
|
132
|
+
# return_to_stock_items: [
|
133
|
+
# 0
|
134
|
+
# ]
|
135
|
+
# }
|
136
|
+
# }
|
137
|
+
# )
|
138
|
+
#
|
139
|
+
# to complete [documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
|
140
|
+
#
|
141
|
+
# @return {Integer} return the refund id
|
142
|
+
def refund(order_id, refund_params = nil)
|
143
|
+
request.post("order/#{order_id}/refund", refund_params).parse
|
144
|
+
end
|
145
|
+
|
87
146
|
#
|
88
147
|
# Creates new Shipment for given Order.
|
89
148
|
#
|
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