magento 0.20.0 → 0.23.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 +48 -1
- 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/params/create_product.rb +26 -26
- data/lib/magento/product.rb +54 -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: 2212acd226570a0dc73fc66683290aca3469006680b1e7946f3426177d0368a3
|
4
|
+
data.tar.gz: 1b3029f0f0eb3f0c6b583e4c025f8ab5d53dba8bfeed197e6e8ffc3c08ebf473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4b55ba92ddfe5e7831da80ccdf170139a6b8f3459be07d35bfc877ee0638cbcaf15f98d7215f01b017510bb4d8458cf45e229acca7b3dc5d5fa2054e8f00b1
|
7
|
+
data.tar.gz: e35feff6cb0a82ece59cf57cb4bde0b0f9d7ea5989ff307c17211045fee78fff1dafbbcc8aaec34be3249e14c784679569d2d9d8dfc773124033592cc82189cf
|
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.23.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -614,6 +614,53 @@ Magento::Product.where(name_like: 'some name%').count
|
|
614
614
|
>> 15
|
615
615
|
```
|
616
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
|
+
|
617
664
|
___
|
618
665
|
|
619
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
|
@@ -4,33 +4,33 @@ require_relative 'create_custom_attribute'
|
|
4
4
|
module Magento
|
5
5
|
module Params
|
6
6
|
# Example
|
7
|
-
#
|
8
|
-
# params = Magento::Params::CreateProduct.new(
|
9
|
-
# sku: '556-teste-builder',
|
10
|
-
# name: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',
|
11
|
-
# description: 'Descrição do produto',
|
12
|
-
# brand: 'Coca-Cola',
|
13
|
-
# price: 4.99,
|
14
|
-
# special_price: 3.49,
|
15
|
-
# quantity: 2,
|
16
|
-
# weight: 0.3,
|
17
|
-
# attribute_set_id: 4,
|
18
|
-
# images: [
|
19
|
-
# *Magento::Params::CreateImage.new(
|
20
|
-
# path: 'https://urltoimage.com/image.jpg',
|
21
|
-
# title: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',
|
22
|
-
# position: 0,
|
23
|
-
# main: true
|
24
|
-
# ).variants, # it's generate all variants thumbnail => '100x100', small_image => '300x300' and image => '800x800'
|
25
|
-
# Magento::Params::CreateImage.new(
|
26
|
-
# path: '/path/to/image.jpg',
|
27
|
-
# title: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',
|
28
|
-
# position: 1
|
29
|
-
# )
|
30
|
-
# ]
|
31
|
-
# )
|
32
7
|
#
|
33
|
-
# Magento::
|
8
|
+
# params = Magento::Params::CreateProduct.new(
|
9
|
+
# sku: '556-teste-builder',
|
10
|
+
# name: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',
|
11
|
+
# description: 'Descrição do produto',
|
12
|
+
# brand: 'Coca-Cola',
|
13
|
+
# price: 4.99,
|
14
|
+
# special_price: 3.49,
|
15
|
+
# quantity: 2,
|
16
|
+
# weight: 0.3,
|
17
|
+
# attribute_set_id: 4,
|
18
|
+
# images: [
|
19
|
+
# *Magento::Params::CreateImage.new(
|
20
|
+
# path: 'https://urltoimage.com/image.jpg',
|
21
|
+
# title: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',
|
22
|
+
# position: 0,
|
23
|
+
# main: true
|
24
|
+
# ).variants, # it's generate all variants thumbnail => '100x100', small_image => '300x300' and image => '800x800'
|
25
|
+
# Magento::Params::CreateImage.new(
|
26
|
+
# path: '/path/to/image.jpg',
|
27
|
+
# title: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',
|
28
|
+
# position: 1
|
29
|
+
# )
|
30
|
+
# ]
|
31
|
+
# )
|
32
|
+
#
|
33
|
+
# Magento::Product.create(params.to_h)
|
34
34
|
#
|
35
35
|
class CreateProduct < Dry::Struct
|
36
36
|
ProductTypes = Type::String.default('simple'.freeze).enum(
|
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,29 @@ module Magento
|
|
44
52
|
)
|
45
53
|
end
|
46
54
|
|
55
|
+
#
|
56
|
+
# Remove tier price
|
57
|
+
#
|
58
|
+
# product = Magento::Product.find(1)
|
59
|
+
# product.remove_tier_price(quantity: 1, customer_group_id: :all)
|
60
|
+
#
|
61
|
+
# @return {Boolean}
|
62
|
+
def remove_tier_price(quantity:, customer_group_id: :all)
|
63
|
+
self.class.remove_tier_price(
|
64
|
+
sku, quantity: quantity, customer_group_id: customer_group_id
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Update product stock
|
69
|
+
#
|
70
|
+
# product = Magento::Product.find('sku')
|
71
|
+
# product.update_stock(qty: 12, is_in_stock: true)
|
72
|
+
#
|
73
|
+
# see all available attributes in: https://magento.redoc.ly/2.4.1-admin/tag/productsproductSkustockItemsitemId
|
74
|
+
def update_stock(attributes)
|
75
|
+
self.class.update_stock(sku, id, attributes)
|
76
|
+
end
|
77
|
+
|
47
78
|
class << self
|
48
79
|
alias_method :find_by_sku, :find
|
49
80
|
|
@@ -66,6 +97,29 @@ module Magento
|
|
66
97
|
"products/#{sku}/group-prices/#{customer_group_id}/tiers/#{quantity}/price/#{price}"
|
67
98
|
).parse
|
68
99
|
end
|
100
|
+
|
101
|
+
# Remove tier price
|
102
|
+
#
|
103
|
+
# Product.remove_tier_price('sku', quantity: 1, customer_group_id: :all)
|
104
|
+
#
|
105
|
+
# @return {Boolean}
|
106
|
+
def remove_tier_price(sku, quantity:, customer_group_id: :all)
|
107
|
+
request.delete(
|
108
|
+
"products/#{sku}/group-prices/#{customer_group_id}/tiers/#{quantity}"
|
109
|
+
).parse
|
110
|
+
end
|
111
|
+
|
112
|
+
# Update product stock
|
113
|
+
#
|
114
|
+
# Magento::Product.update_stock(sku, id, {
|
115
|
+
# qty: 12,
|
116
|
+
# is_in_stock: true
|
117
|
+
# })
|
118
|
+
#
|
119
|
+
# see all available attributes in: https://magento.redoc.ly/2.4.1-admin/tag/productsproductSkustockItemsitemId
|
120
|
+
def update_stock(sku, id, attributes)
|
121
|
+
request.put("products/#{sku}/stockItems/#{id}", stockItem: attributes).parse
|
122
|
+
end
|
69
123
|
end
|
70
124
|
end
|
71
125
|
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.23.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
|