magento 0.19.0 → 0.22.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/README.md +53 -4
- data/lib/magento.rb +1 -0
- data/lib/magento/import/csv_reader.rb +1 -1
- data/lib/magento/inventory.rb +40 -0
- data/lib/magento/product.rb +30 -0
- data/lib/magento/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b2408f7d630a838f697a67fd49e5c9821cb3876867ac1ca3bd895b7907aed3d
|
4
|
+
data.tar.gz: a96cf27ae84be012af63fcb7a85c012680abfcc8a605317176d30b306b75099e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11472a37cda254fdec29a954cb96255326bf10abe0d50c2ef5befb2ebf894e446c5d89faec168fd010949edc7a7b009a8ed4aeddebf63a7152f4cf2b2eb52395
|
7
|
+
data.tar.gz: f3d20a4db9adddd584271fc653cffedd9131db1b4ed2d1fa5cdadf18cc48e6086cb3a6e940e2eaee0cc40639071e384442e92535209078d006d30e2c966b20c4
|
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.22.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')
|
@@ -612,6 +614,53 @@ Magento::Product.where(name_like: 'some name%').count
|
|
612
614
|
>> 15
|
613
615
|
```
|
614
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
|
+
|
646
|
+
## Update product stock
|
647
|
+
|
648
|
+
```rb
|
649
|
+
product = Magento::Product.find('sku')
|
650
|
+
product.update_stock(qty: 12, is_in_stock: true)
|
651
|
+
```
|
652
|
+
|
653
|
+
or by class method
|
654
|
+
|
655
|
+
```rb
|
656
|
+
Magento::Product.update_stock(sku, id, {
|
657
|
+
qty: 12,
|
658
|
+
is_in_stock: true
|
659
|
+
})
|
660
|
+
```
|
661
|
+
|
662
|
+
see all available attributes in: https://magento.redoc.ly/2.4.1-admin/tag/productsproductSkustockItemsitemId
|
663
|
+
|
615
664
|
___
|
616
665
|
|
617
666
|
##TODO:
|
data/lib/magento.rb
CHANGED
@@ -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 }
|
@@ -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
|
data/lib/magento/product.rb
CHANGED
@@ -6,6 +6,14 @@ module Magento
|
|
6
6
|
attr(m) || super(m, *params, &block)
|
7
7
|
end
|
8
8
|
|
9
|
+
def stock
|
10
|
+
extension_attributes&.stock_item
|
11
|
+
end
|
12
|
+
|
13
|
+
def stock_quantity
|
14
|
+
stock&.qty
|
15
|
+
end
|
16
|
+
|
9
17
|
# returns custom_attribute value by custom_attribute code
|
10
18
|
# return nil if custom_attribute is not present
|
11
19
|
def attr(attribute_code)
|
@@ -44,6 +52,16 @@ module Magento
|
|
44
52
|
)
|
45
53
|
end
|
46
54
|
|
55
|
+
# Update product stock
|
56
|
+
#
|
57
|
+
# product = Magento::Product.find('sku')
|
58
|
+
# product.update_stock(qty: 12, is_in_stock: true)
|
59
|
+
#
|
60
|
+
# see all available attributes in: https://magento.redoc.ly/2.4.1-admin/tag/productsproductSkustockItemsitemId
|
61
|
+
def update_stock(attributes)
|
62
|
+
self.class.update_stock(sku, id, attributes)
|
63
|
+
end
|
64
|
+
|
47
65
|
class << self
|
48
66
|
alias_method :find_by_sku, :find
|
49
67
|
|
@@ -66,6 +84,18 @@ module Magento
|
|
66
84
|
"products/#{sku}/group-prices/#{customer_group_id}/tiers/#{quantity}/price/#{price}"
|
67
85
|
).parse
|
68
86
|
end
|
87
|
+
|
88
|
+
# Update product stock
|
89
|
+
#
|
90
|
+
# Magento::Product.update_stock(sku, id, {
|
91
|
+
# qty: 12,
|
92
|
+
# is_in_stock: true
|
93
|
+
# })
|
94
|
+
#
|
95
|
+
# see all available attributes in: https://magento.redoc.ly/2.4.1-admin/tag/productsproductSkustockItemsitemId
|
96
|
+
def update_stock(sku, id, attributes)
|
97
|
+
request.put("products/#{sku}/stockItems/#{id}", stockItem: attributes).parse
|
98
|
+
end
|
69
99
|
end
|
70
100
|
end
|
71
101
|
end
|
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.22.0
|
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
|