magento 0.7.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c96180295e2e45d66ac2ea4aa956ec516c3c5045d81db431538cd5462b5efcc
4
- data.tar.gz: b2d13f614c5af4b956e97b87c7e2476d1a40fd1ada11cb94270698630d44f9b2
3
+ metadata.gz: 9feeba215d0c11fed2e466bbae0fc5e7f7fe5dcd5b0d2d7608e38b2735bb94d2
4
+ data.tar.gz: 19d4dfd1fdf7b95c5f6083d26ab965c3c3b293b55733f7de05cf9e728b4b54b6
5
5
  SHA512:
6
- metadata.gz: 512781570485d5af44f8567b31c4988d096682f0e3fe6119803c18385842cecbfc28bdb2a16fb02091d0000cbf2cbae2b5174cf3b0489d398450957c76377069
7
- data.tar.gz: 51dd50c0b4a2542e6467dff88553eb5a0542f7efff10de0430a6fb3bdba32e5e8232bf4ef4e5f07b886eeebf6835aad8127791c3d84ddc89632db6ed73d35c0d
6
+ metadata.gz: fc0c4c3dc085740ec5189fb492c49557a0163fcdd685e430df84ad63f19ffecb4e0ccf5210e086f0094072ef7aea315bff209e647d9331c3bc786926cdb7786c
7
+ data.tar.gz: e0664dc298ecb36697ead9fc1c36267e82a3e9ae78a552a096a07bdc61d4feb94742773e621582ee0c1175f45e0e7c86e07bea3634e2e1bdd8868f94b91ea27b
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.7.0'
8
+ gem 'magento', '~> 0.9.1'
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
@@ -411,6 +457,17 @@ order.ship(
411
457
 
412
458
  [Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)
413
459
 
460
+
461
+ ## Cancel an Order
462
+
463
+ ```rb
464
+ order = Magento::Order.find(order_id)
465
+
466
+ order.cancel # or
467
+
468
+ Magento::Order.cancel(order_id)
469
+ ```
470
+
414
471
  ___
415
472
 
416
473
  ##TODO:
@@ -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,11 @@ 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)
16
+ end
17
+
18
+ def cancel
19
+ self.class.cancel(id)
17
20
  end
18
21
 
19
22
  #
@@ -29,6 +32,20 @@ module Magento
29
32
  self.class.invoice(id, params)
30
33
  end
31
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
+
32
49
  #
33
50
  # Creates new Shipment for given Order.
34
51
  #
@@ -43,11 +60,17 @@ module Magento
43
60
  end
44
61
 
45
62
  class << self
46
- def update(attributes)
63
+ def update(entity_id, attributes)
64
+ attributes[:entity_id] = entity_id
47
65
  hash = request.put('orders/create', { entity_key => attributes }).parse
48
66
  build(hash)
49
67
  end
50
68
 
69
+ # @return {Boolean}
70
+ def cancel(order_id)
71
+ request.post("orders/#{order_id}/cancel").parse
72
+ end
73
+
51
74
  #
52
75
  # Invoice an order
53
76
  #
@@ -75,6 +98,49 @@ module Magento
75
98
  request.post("order/#{order_id}/invoice", invoice_params).parse
76
99
  end
77
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
+
78
144
  #
79
145
  # Creates new Shipment for given Order.
80
146
  #
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.7.0'
2
+ VERSION = '0.9.1'
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.7.0
4
+ version: 0.9.1
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