magento 0.17.0 → 0.20.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: 73c1f0ddb533c84f3cb909d31a6349fc51237965c2e60ff92f23bf30da582454
4
- data.tar.gz: f269b8b2a89e8c7726782cbc2638cff88ab020495807baa5ed39f874283ea657
3
+ metadata.gz: bc9582af53b1373798281de5d95c312d7821edd2e597ab7eb98b756b9b44acb0
4
+ data.tar.gz: fcdca10d53017a38791ee474a001580af31291db167cbd7cf9064d0315c3220d
5
5
  SHA512:
6
- metadata.gz: d6efe97f07e753ef46abe67223d4503c605fbc4d060a0dfc0433f06134fa5b2e59088f7664b7f5e711598f46e801666b70912fcd9fdf38ea1760ef866b9edf76
7
- data.tar.gz: 3c3b2c9b3f3d018665e9b0d2b47102a880194446bc8bb4423e002ead7ee345e42beda903f20843862987ad28751a5743a18ae77d100724c95d7884e772e8b9df
6
+ metadata.gz: 773f2e7c8d4d11b1f33003645d3b3343d84ac96909ba2209aabe43d34ba0908ffb7d93d0ee9b95da9b4a1f14c7babe71269f7798e6f43b583959a66e2f801c14
7
+ data.tar.gz: 703fe39e39b45026fdc17fd93439701ca5c1632da57e97f2b81385d79fd1396e896dff1700cac85d7e0f16108443b04108e472f41c6e0f87147ecba754ca029f
@@ -3,8 +3,6 @@ name: Ruby Gem
3
3
  on:
4
4
  push:
5
5
  branches: [ release ]
6
- pull_request:
7
- branches: [ release ]
8
6
 
9
7
  jobs:
10
8
  build:
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.15.1'
8
+ gem 'magento', '~> 0.20.0'
9
9
  ```
10
10
 
11
11
  or run
@@ -17,9 +17,11 @@ gem install magento
17
17
  ### Setup
18
18
 
19
19
  ```rb
20
- Magento.url = 'https://yourstore.com'
21
- Magento.token = 'MAGENTO_API_KEY'
22
- Magento.store = :default # optional, Default is :all
20
+ Magento.configure do |config|
21
+ config.url = 'https://yourstore.com'
22
+ config.token = 'MAGENTO_API_KEY'
23
+ config.store = :default # optional, Default is :all
24
+ end
23
25
 
24
26
  Magento.with_config(store: :other_store) do # accepts store, url and token parameters
25
27
  Magento::Product.find('sku')
@@ -83,6 +85,23 @@ product.respond_to? :description
83
85
  > true
84
86
  ```
85
87
 
88
+ ## add tier price
89
+
90
+ Add `price` on product `sku` for specified `customer_group_id`
91
+
92
+ Param `quantity` is the minimun amount to apply the price
93
+
94
+ ```rb
95
+ product = Magento::Product.find(1)
96
+ product.add_tier_price(3.99, quantity: 1, customer_group_id: :all)
97
+ > true
98
+
99
+ # OR
100
+
101
+ Magento::Product.add_tier_price(1, 3.99, quantity: 1, customer_group_id: :all)
102
+ > true
103
+ ```
104
+
86
105
  ## Get List
87
106
 
88
107
  ```rb
@@ -28,10 +28,10 @@ module Magento
28
28
 
29
29
  product = Magento::Product.create(params)
30
30
 
31
- puts "Produto criado: #{product.sku} => #{product.name}"
31
+ puts "Created product: #{product.sku} => #{product.name}"
32
32
  rescue => e
33
- puts "Erro ao criado: #{product.sku} => #{product.name}"
34
- puts " - Detalhes do erro: #{e}"
33
+ puts "Error on create: #{product.sku} => #{product.name}"
34
+ puts " - Error details: #{e}"
35
35
  end
36
36
  end
37
37
 
@@ -35,7 +35,7 @@ module Magento
35
35
  class << self
36
36
  extend Forwardable
37
37
 
38
- def_delegators :query, :all, :page, :per, :page_size, :order, :select,
38
+ def_delegators :query, :all, :find_each, :page, :per, :page_size, :order, :select,
39
39
  :where, :first, :find_by, :count
40
40
 
41
41
  def find(id)
@@ -60,11 +60,11 @@ module Magento
60
60
  b.format 'jpg'
61
61
  end
62
62
  rescue => e
63
- raise "Erro ao ler imagem #{path}: #{e}"
63
+ raise "Error on read image #{path}: #{e}"
64
64
  end
65
65
 
66
66
  def filename
67
- title.parameterize
67
+ "#{title.parameterize}-#{VARIANTS[size]}.jpg"
68
68
  end
69
69
 
70
70
  def mini_type
@@ -2,8 +2,8 @@ module Magento
2
2
  class Product < Model
3
3
  self.primary_key = :sku
4
4
 
5
- def method_missing(m)
6
- attr(m) || super
5
+ def method_missing(m, *params, &block)
6
+ attr(m) || super(m, *params, &block)
7
7
  end
8
8
 
9
9
  # returns custom_attribute value by custom_attribute code
@@ -16,8 +16,56 @@ module Magento
16
16
  super || @custom_attributes&.any? { |a| a.attribute_code == attribute_code.to_s }
17
17
  end
18
18
 
19
+ def add_media(attributes)
20
+ self.class.add_media(sku, attributes)
21
+ end
22
+
23
+ # returns true if the media was deleted
24
+ def remove_media(media_id)
25
+ self.class.remove_media(sku, media_id)
26
+ end
27
+
28
+ #
29
+ # Add {price} on product {sku} for specified {customer_group_id}
30
+ #
31
+ # Param {quantity} is the minimun amount to apply the price
32
+ #
33
+ # product = Magento::Product.find(1)
34
+ # product.add_tier_price(3.99, quantity: 1, customer_group_id: :all)
35
+ #
36
+ # OR
37
+ #
38
+ # Magento::Product.add_tier_price(1, 3.99, quantity: 1, customer_group_id: :all)
39
+ #
40
+ # @return {Boolean}
41
+ def add_tier_price(price, quantity:, customer_group_id: :all)
42
+ self.class.add_tier_price(
43
+ sku, price, quantity: quantity, customer_group_id: customer_group_id
44
+ )
45
+ end
46
+
19
47
  class << self
20
48
  alias_method :find_by_sku, :find
49
+
50
+ def add_media(sku, attributes)
51
+ request.post("products/#{sku}/media", { entry: attributes }).parse
52
+ end
53
+
54
+ # returns true if the media was deleted
55
+ def remove_media(sku, media_id)
56
+ request.delete("products/#{sku}/media/#{media_id}").parse
57
+ end
58
+
59
+ # Add {price} on product {sku} for specified {customer_group_id}
60
+ #
61
+ # Param {quantity} is the minimun amount to apply the price
62
+ #
63
+ # @return {Boolean}
64
+ def add_tier_price(sku, price, quantity:, customer_group_id: :all)
65
+ request.post(
66
+ "products/#{sku}/group-prices/#{customer_group_id}/tiers/#{quantity}/price/#{price}"
67
+ ).parse
68
+ end
21
69
  end
22
70
  end
23
71
  end
@@ -58,7 +58,7 @@ module Magento
58
58
  alias_method :per, :page_size
59
59
 
60
60
  def select(*fields)
61
- fields = fields.map { |field| parse_field(field) }
61
+ fields = fields.map { |field| parse_field(field, root: true) }
62
62
 
63
63
  if model == Magento::Category
64
64
  self.fields = "children_data[#{fields.join(',')}]"
@@ -92,6 +92,28 @@ module Magento
92
92
  end
93
93
  end
94
94
 
95
+ #
96
+ # Loop all products on each page, starting from the first to the last page
97
+ def find_each
98
+ if @model == Magento::Category
99
+ raise NoMethodError, 'undefined method `find_each` for Magento::Category'
100
+ end
101
+
102
+ @current_page = 1
103
+
104
+ loop do
105
+ redords = all
106
+
107
+ redords.each do |record|
108
+ yield record
109
+ end
110
+
111
+ break if redords.last_page?
112
+
113
+ @current_page = redords.next_page
114
+ end
115
+ end
116
+
95
117
  def first
96
118
  page_size(1).page(1).all.first
97
119
  end
@@ -149,8 +171,8 @@ module Magento
149
171
  value
150
172
  end
151
173
 
152
- def parse_field(value)
153
- return verify_id(value) unless value.is_a? Hash
174
+ def parse_field(value, root: false)
175
+ return (root ? verify_id(value) : value) unless value.is_a? Hash
154
176
 
155
177
  value.map do |k, v|
156
178
  fields = v.is_a?(Array) ? v.map { |field| parse_field(field) } : [parse_field(v)]
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.17.0'
2
+ VERSION = '0.20.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.17.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria
@@ -98,9 +98,9 @@ files:
98
98
  - lib/magento/errors.rb
99
99
  - lib/magento/guest_cart.rb
100
100
  - lib/magento/import.rb
101
- - lib/magento/import/Image_finder.rb
102
101
  - lib/magento/import/category.rb
103
102
  - lib/magento/import/csv_reader.rb
103
+ - lib/magento/import/image_finder.rb
104
104
  - lib/magento/import/product.rb
105
105
  - lib/magento/import/template/products.csv
106
106
  - lib/magento/invoice.rb