magento 0.8.0 → 0.9.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 105bbf170147d3f2ff496baf63a72cb1f0b53df128190eeb81ac3b7e72fe4350
4
- data.tar.gz: 7acf462751cf0c6de4c2d8a682cbe74da9abc8dcfafc67720b755233d500fa74
3
+ metadata.gz: b2db72674e6f177281d192ec853591b747c91e3ce7f3bd61ccb5beb1a01ddf9d
4
+ data.tar.gz: 50afe2399868005885926446ac9cb6563625e99f4752ca6c339728f53adb0b0f
5
5
  SHA512:
6
- metadata.gz: 0deb6947369078c57322304294a3b3843454448f5dd949fb787944bc4ee820268e95905e244e91814c951f5bfae1638e41c59c7644f01bde49e86f5c65a0df23
7
- data.tar.gz: c8f9993a9dee4c105041b99d99b911093d37df75ab2553f99e0cca430b1d349e01a738d06c5278f0dfcfcd9d9e315a34771f6869984d573fd37df0804d7f1dbc
6
+ metadata.gz: d7734ec0ecf1fcfc46d3675f3cfcee3dd47fbab3606bb8839079b9c5b1f487ba125a6529ee6f7addef0f3e5f81bdb8bd6c97d5c9d73e45a4554ec0e5ab162ec9
7
+ data.tar.gz: 1ece8d5edc5efc8d0e336b77c0a0259caf930c51dc7a4fb40ad05954e17a4d960226356d8610c1004e91dc155d6afbeaf094b677130b8a1995ee02e702fb4abb
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.8.0'
8
+ gem 'magento', '~> 0.9.2'
9
9
  ```
10
10
 
11
11
  or run
@@ -255,6 +255,10 @@ product.save
255
255
  # or
256
256
 
257
257
  product.update(name: 'Updated name')
258
+
259
+ # or
260
+
261
+ Magento::Product.update('sku-teste', name: 'Updated name')
258
262
  ```
259
263
 
260
264
  ### Delete
@@ -320,7 +324,7 @@ invoice_id = order.invoice(
320
324
  ## Create refund for invoice
321
325
 
322
326
  ```rb
323
- Magento::Invoice.invoice(refund_id)
327
+ Magento::Invoice.invoice(invoice_id)
324
328
  >> 12 # return refund id
325
329
 
326
330
  # or from instance
@@ -361,6 +365,48 @@ invoice.refund(
361
365
  [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)
362
366
 
363
367
 
368
+ ## Create offline refund for order
369
+
370
+ ```rb
371
+ Magento::Order.refund(order_id)
372
+ >> 12 # return refund id
373
+
374
+ # or from instance
375
+
376
+ order = Magento::Order.find(order_id)
377
+
378
+ order.refund
379
+
380
+ # you can pass parameters too
381
+
382
+ order.refund(
383
+ items: [
384
+ {
385
+ extension_attributes: {},
386
+ order_item_id: 0,
387
+ qty: 0
388
+ }
389
+ ],
390
+ notify: true,
391
+ appendComment: true,
392
+ comment: {
393
+ extension_attributes: {},
394
+ comment: string,
395
+ is_visible_on_front: 0
396
+ },
397
+ arguments: {
398
+ shipping_amount: 0,
399
+ adjustment_positive: 0,
400
+ adjustment_negative: 0,
401
+ extension_attributes: {
402
+ return_to_stock_items: [0]
403
+ }
404
+ }
405
+ )
406
+ ```
407
+
408
+ [Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)
409
+
364
410
  ## Other Invoice methods
365
411
 
366
412
  ```rb
@@ -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
@@ -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.invoice(notify: false) # See the refund class method for more information
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)
@@ -92,7 +92,7 @@ module Magento
92
92
  #
93
93
  # or
94
94
  #
95
- # Magento::Order.refund(
95
+ # Magento::Invoice.refund(
96
96
  # invoice_id,
97
97
  # items: [
98
98
  # {
@@ -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/#{order_id}/refund", invoice_params).parse
128
+ request.post("invoice/#{invoice_id}/refund", refund_params).parse
129
129
  end
130
130
  end
131
131
  end
@@ -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
- attrs.each { |key, value| send("#{key}=", value) }
17
- save
16
+ self.class.update(send(self.class.primary_key), attrs)
18
17
  end
19
18
 
20
19
  def delete
@@ -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
- attrs[:entity_id] = @entity_id
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
  #
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.2'
3
3
  end
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.8.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria
@@ -48,7 +48,6 @@ files:
48
48
  - ".gitignore"
49
49
  - Gemfile
50
50
  - README.md
51
- - atrelar_produto_loja.rb
52
51
  - lib/magento.rb
53
52
  - lib/magento/category.rb
54
53
  - lib/magento/country.rb
@@ -1,20 +0,0 @@
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