magento 0.17.0 → 0.20.0
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 +4 -4
 - data/.github/workflows/gem-push.yml +0 -2
 - data/README.md +23 -4
 - data/lib/magento/import/{Image_finder.rb → image_finder.rb} +0 -0
 - data/lib/magento/import/product.rb +3 -3
 - data/lib/magento/model.rb +1 -1
 - data/lib/magento/params/create_image.rb +2 -2
 - data/lib/magento/product.rb +50 -2
 - data/lib/magento/query.rb +25 -3
 - data/lib/magento/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: bc9582af53b1373798281de5d95c312d7821edd2e597ab7eb98b756b9b44acb0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: fcdca10d53017a38791ee474a001580af31291db167cbd7cf9064d0315c3220d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 773f2e7c8d4d11b1f33003645d3b3343d84ac96909ba2209aabe43d34ba0908ffb7d93d0ee9b95da9b4a1f14c7babe71269f7798e6f43b583959a66e2f801c14
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 703fe39e39b45026fdc17fd93439701ca5c1632da57e97f2b81385d79fd1396e896dff1700cac85d7e0f16108443b04108e472f41c6e0f87147ecba754ca029f
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ 
     | 
|
| 
       5 
5 
     | 
    
         
             
            Add in your Gemfile
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            ```rb
         
     | 
| 
       8 
     | 
    
         
            -
            gem 'magento', '~> 0. 
     | 
| 
      
 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. 
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -28,10 +28,10 @@ module Magento 
     | 
|
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                      product = Magento::Product.create(params)
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                      puts " 
     | 
| 
      
 31 
     | 
    
         
            +
                      puts "Created product: #{product.sku} => #{product.name}"
         
     | 
| 
       32 
32 
     | 
    
         
             
                    rescue => e
         
     | 
| 
       33 
     | 
    
         
            -
                      puts " 
     | 
| 
       34 
     | 
    
         
            -
                      puts " -  
     | 
| 
      
 33 
     | 
    
         
            +
                      puts "Error on create: #{product.sku} => #{product.name}"
         
     | 
| 
      
 34 
     | 
    
         
            +
                      puts " - Error details: #{e}"
         
     | 
| 
       35 
35 
     | 
    
         
             
                    end
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         | 
    
        data/lib/magento/model.rb
    CHANGED
    
    | 
         @@ -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 " 
     | 
| 
      
 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
         
     | 
    
        data/lib/magento/product.rb
    CHANGED
    
    | 
         @@ -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
         
     | 
    
        data/lib/magento/query.rb
    CHANGED
    
    | 
         @@ -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)]
         
     | 
    
        data/lib/magento/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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
         
     |