magento 0.8.1 → 0.10.0

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: 8ad71d2a627ff149bce29e8ad50d8f71926a19079c2af86000db29109d305c65
4
- data.tar.gz: bc2f85e76ff1da204aa8d613a770401763bee486e6dd045af6b4e97df8758f62
3
+ metadata.gz: f2d89a076f05f6e5a3f3a828d7658582a76556e57f6f0ff07a2422044ce82ab4
4
+ data.tar.gz: fbf4ab1013bf639d81781cc40042aedc5ed62062207f597e127a2ba0bc5b21b3
5
5
  SHA512:
6
- metadata.gz: 2166a5412b4f41a7298efe838d5ad927d60905206af025a745420109ff87700c56d0adaaea49da0d2a4519fb34b2abafcedbabb810bfc6972fe28c92bd29c61a
7
- data.tar.gz: 400d5d6ef1669fb147a0281312a9504ee252d7d1a46debab0bb61cdc51286d6c0c4956dfeb355a691d49bd4d0f06e044f9fe0f9968a0d3529dcdde8b36ebd732
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.1'
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(refund_id)
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
@@ -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)
@@ -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", 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
@@ -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, :where
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
@@ -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
  #
@@ -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
- raise 'Invalid format' unless key.match(patter)
123
- raise 'Condition not accepted' unless ACCEPTED_CONDITIONS.include?(key.match(patter)[2])
134
+ match = key.match(patter)
135
+
136
+ return match.to_a[1..2] if match && ACCEPTED_CONDITIONS.include?(match[2])
124
137
 
125
- key.match(patter).to_a[1..2]
138
+ [key, 'eq']
126
139
  end
127
140
 
128
141
  def parse_value_filter(condition, value)
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.8.1'
2
+ VERSION = '0.10.0'
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.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria