magento 0.18.1 → 0.21.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: bab9845aefc480901b6d4fae6181054bcb4337f52c7ecdcb5c43d9256489c498
4
- data.tar.gz: 31510059e22ae9c29eb9ad8d134122342fc58330ca6f382867f530e700035aef
3
+ metadata.gz: 15c67c62a1922aae194eab45cae0684451a565ff8d7897fd914e8f4c7f2b9934
4
+ data.tar.gz: 0a75750bf4e0976d81b72d69398d05ca5e7d63ea3588fe161ff6dd46d4223f7f
5
5
  SHA512:
6
- metadata.gz: 7a03f247c66668011492453cc90e146968cc39c1ead0dc8823593187f3169a5cd63885f0d5bc53abd781840520df0a7c026228fcf9a501f8338ea342b7874ab7
7
- data.tar.gz: cce4a8ee5d5abe1b4c6d2f93e11aa21b5724e6965c9c6812a31020967c56d8b572ef2e92012346b7848de2da3e9e56189be663b0a9a05ae7155d75e29712a272
6
+ metadata.gz: 02e95ff4336f3312a98acd8158decb1f66241f1183bb75de941f75c2cedaa7705ffcc732a9d8cb73d925cbd5f22a4404f42462bc8be46bfe86d219e880d45949
7
+ data.tar.gz: 4f70b1965fcaeaf3f67bafee6a2a3f4d2f38296f11eb591f0e42302d796f0b4c810851facfd3d9c757d9fb97d1c4d4e996d653b6c46e4b8184205522560a655b
@@ -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.21.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
@@ -595,6 +614,35 @@ Magento::Product.where(name_like: 'some name%').count
595
614
  >> 15
596
615
  ```
597
616
 
617
+ ## Inventory
618
+
619
+ ### Check whether a product is salable
620
+
621
+ ```rb
622
+ Inventory.get_product_salable_quantity(sku: '4321', stock_id: 1)
623
+ >> 1
624
+ ```
625
+
626
+ ### Check whether a product is salable for a specified quantity
627
+
628
+ ```rb
629
+ Inventory.is_product_salable_for_requested_qty(
630
+ sku: '4321',
631
+ stock_id: 1,
632
+ requested_qty: 2
633
+ )
634
+ >> OpenStruct {
635
+ :salable => false,
636
+ :errors => [
637
+ [0] {
638
+ "code" => "back_order-disabled",
639
+ "message" => "Backorders are disabled"
640
+ },
641
+ ...
642
+ ]
643
+ }
644
+ ```
645
+
598
646
  ___
599
647
 
600
648
  ##TODO:
@@ -22,6 +22,7 @@ require_relative 'magento/order'
22
22
  require_relative 'magento/invoice'
23
23
  require_relative 'magento/guest_cart'
24
24
  require_relative 'magento/sales_rule'
25
+ require_relative 'magento/inventory'
25
26
  require_relative 'magento/import'
26
27
 
27
28
  Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
@@ -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],
@@ -0,0 +1,40 @@
1
+ module Magento
2
+ class Inventory
3
+ class << self
4
+ #
5
+ # ==== Example
6
+ #
7
+ # Inventory.is_product_salable_for_requested_qty(
8
+ # sku: '4321',
9
+ # stock_id: 1,
10
+ # requested_qty: 2
11
+ # )
12
+ # # =>
13
+ # OpenStruct {
14
+ # :salable => false,
15
+ # :errors => [
16
+ # [0] {
17
+ # "code" => "back_order-disabled",
18
+ # "message" => "Backorders are disabled"
19
+ # },
20
+ # ...
21
+ # ]
22
+ # }
23
+ #
24
+ # @return OpenStruct
25
+ def is_product_salable_for_requested_qty(sku:, stock_id:, requested_qty:)
26
+ result = Request.new.get(
27
+ "inventory/is-product-salable-for-requested-qty/#{sku}/#{stock_id}/#{requested_qty}"
28
+ ).parse
29
+
30
+ OpenStruct.new(result)
31
+ end
32
+
33
+ def get_product_salable_quantity(sku:, stock_id:)
34
+ Request.new.get(
35
+ "inventory/get-product-salable-quantity/#{sku}/#{stock_id}"
36
+ ).parse
37
+ end
38
+ end
39
+ end
40
+ end
@@ -25,6 +25,25 @@ module Magento
25
25
  self.class.remove_media(sku, media_id)
26
26
  end
27
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
+
28
47
  class << self
29
48
  alias_method :find_by_sku, :find
30
49
 
@@ -36,6 +55,17 @@ module Magento
36
55
  def remove_media(sku, media_id)
37
56
  request.delete("products/#{sku}/media/#{media_id}").parse
38
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
39
69
  end
40
70
  end
41
71
  end
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.18.1'
2
+ VERSION = '0.21.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.18.1
4
+ version: 0.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria
@@ -103,6 +103,7 @@ files:
103
103
  - lib/magento/import/image_finder.rb
104
104
  - lib/magento/import/product.rb
105
105
  - lib/magento/import/template/products.csv
106
+ - lib/magento/inventory.rb
106
107
  - lib/magento/invoice.rb
107
108
  - lib/magento/model.rb
108
109
  - lib/magento/model_mapper.rb