magento 0.17.1 → 0.20.1

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: '0297062d52271023e5e8a7249cccff2480305b5764d8ec72ecf95d68d52a9425'
4
- data.tar.gz: ee7ef6bf9f562e0b43ba5d86112275f99654ea1483d4a4495c9af1dd0b802e4d
3
+ metadata.gz: 68aa93fb639c7e6d3cab0a521e91c08d38aa28dd7d508f50190ce9e718ed8022
4
+ data.tar.gz: ccde7c0ccbe949e12fb97fab1c80d2dfbc18c9e8de80181b0e0dab1c763f0ee6
5
5
  SHA512:
6
- metadata.gz: 152738362dececeaa477cc34fb3430cc6c436913da11f06b17cb7e8a7265350947248290ccec6533d240243d3699dce62c1d7e7921d00d32cbc14b1cefaf8d4f
7
- data.tar.gz: 0251d571439e8e2371c14c5603d3b9fbb4a45df02beae02e4c4ee406940036dfa205e51e8bf3bf8183bb957934947c2e4018cb48d59e7b1bdfcec258f49da86e
6
+ metadata.gz: d5ddc1d9471997748938d0942e97125b0dd6620efda44c2d80d967968677595e6837bbfbcbd43eb92a9992a50fd8c2dbd3adfef880fb84e3f322ac1ba8400bd1
7
+ data.tar.gz: 631f5d649fa1bfde37f1b9662685ea400f967792b1ed293fc1d1fb20d5d49f775dacbba332f97736079dada2cc67aaecec8f6cd5ca41012537ef8a76fd61e401
@@ -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.1'
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
@@ -9,7 +9,7 @@ module Magento
9
9
  end
10
10
 
11
11
  def get_products
12
- @csv[1..].map do |row|
12
+ @csv[1..-1].map do |row|
13
13
  OpenStruct.new({
14
14
  name: row[0],
15
15
  sku: row[1],
@@ -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)
@@ -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.1'
2
+ VERSION = '0.20.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.17.1
4
+ version: 0.20.1
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