magento 0.27.0 → 0.30.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2d97be580b5599c9d3a9e05f945b23a8488d5c7e1c1d63b22eca9befe00fd25
4
- data.tar.gz: 6dfbc4f7d11b4f6276b54ca1907c547ad3043dd32e50b614ce0233af59644045
3
+ metadata.gz: 3d277c39075219ce0c98d9ce89efaa2ad825723bf9a9765e9372a59d66704375
4
+ data.tar.gz: 96534c4a080cd904572aef9b01f96cef5ec59ff44f424cd93c876cb8e9feb4f2
5
5
  SHA512:
6
- metadata.gz: 237ac75f45cf458fafdb839861937b06cefc519096e769b9d1d57f809ff98138f5d7c801a65de00d83008372776b246e23f52c36575280f9ea36e3e053421101
7
- data.tar.gz: cfdece71be16ddd2e0ec6d887e37da176e37c224e03c6f402b20e01bba82822218eb1650154d3d4362b74b40bb35f0ed9c1c38d5e550746c57aed660aba7438d
6
+ metadata.gz: 719ff5a9501f7f279967ed6d2afa134383df5f4dd83a293f825d068a0eaeb5c718fd47f16f6d745aeb71d26045cecb3fb5911684367feef1a8ac558a205f8de7
7
+ data.tar.gz: 367aa9031d22e670ab8bca2a2dd380c0af4dd3077fa9701bb80a61f5b768cd02055baf43892fb10542b8e0630dd22ffb01016821e07c7c8cab28b15a6f4ae477
data/README.md CHANGED
@@ -77,7 +77,7 @@ Ruby library to consume the magento 2 api
77
77
  Add in your Gemfile
78
78
 
79
79
  ```rb
80
- gem 'magento', '~> 0.27.0'
80
+ gem 'magento', '~> 0.30.0'
81
81
  ```
82
82
 
83
83
  or run
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magento
4
+ class Cart < Model
5
+ self.endpoint = 'carts'
6
+ self.primary_key = :id
7
+
8
+ #
9
+ # Add a coupon by code to the current cart.
10
+ #
11
+ # Example:
12
+ #
13
+ # cart = Magento::Cart.find(1)
14
+ # cart.add_coupon('COAU4HXE0I')
15
+ #
16
+ # @return Boolean: true on success, false otherwise
17
+ def add_coupon(coupon)
18
+ self.class.add_coupon(id, coupon)
19
+ end
20
+
21
+ #
22
+ # Delete cart's coupon
23
+ #
24
+ # Example:
25
+ #
26
+ # cart = Magento::Cart.find(1)
27
+ # cart.delete_coupon()
28
+ #
29
+ # @return Boolean: true on success, raise exception otherwise
30
+ def delete_coupon
31
+ self.class.delete_coupon(id)
32
+ end
33
+
34
+ #
35
+ # Place order for cart
36
+ #
37
+ # Example:
38
+ #
39
+ # cart = Magento::Cart.find('12345')
40
+ #
41
+ # # or use "build" to not request information from the magento API
42
+ # cart = Magento::GuestCart.build({ 'cart_id' => '12345' })
43
+ #
44
+ # cart.order(
45
+ # email: 'customer@gmail.com',
46
+ # payment: { method: 'cashondelivery' }
47
+ # )
48
+ #
49
+ # @return String: return the order id
50
+ def order(email:, payment:)
51
+ attributes = { cartId: id, paymentMethod: payment, email: email }
52
+ self.class.order(attributes)
53
+ end
54
+
55
+ class << self
56
+ #
57
+ # Add a coupon by code to a specified cart.
58
+ #
59
+ # Example:
60
+ #
61
+ # Magento::Cart.add_coupon(
62
+ # 1,
63
+ # 'COAU4HXE0I'
64
+ # )
65
+ #
66
+ # @return Boolean: true on success, false otherwise
67
+ def add_coupon(id, coupon)
68
+ url = "#{api_resource}/#{id}/coupons/#{coupon}"
69
+ request.put(url, nil).parse
70
+ end
71
+
72
+ #
73
+ # Delete a coupon from a specified cart.
74
+ #
75
+ # Example:
76
+ #
77
+ # Magento::Cart.delete_coupon(1)
78
+ #
79
+ # @return Boolean: true on success, raise exception otherwise
80
+ def delete_coupon(id)
81
+ url = "#{api_resource}/#{id}/coupons"
82
+ request.delete(url).parse
83
+ end
84
+
85
+ #
86
+ # Place order for cart
87
+ #
88
+ # Example:
89
+ #
90
+ # Magento::Cart.order(
91
+ # cartId: '12345',
92
+ # paymentMethod: { method: 'cashondelivery' },
93
+ # email: email
94
+ # )
95
+ #
96
+ # @return String: return the order id
97
+ def order(attributes)
98
+ attributes.transform_keys(&:to_sym)
99
+ url = "#{api_resource}/#{attributes[:cartId]}/order"
100
+ request.put(url, attributes).parse
101
+ end
102
+ end
103
+ end
104
+ end
@@ -35,6 +35,33 @@ module Magento
35
35
  "inventory/get-product-salable-quantity/#{sku}/#{stock_id}"
36
36
  ).parse
37
37
  end
38
+
39
+ #
40
+ # ==== Example
41
+ #
42
+ # Inventory.update_source_items(
43
+ # [
44
+ # {
45
+ # "sku": "new_product1",
46
+ # "source_code": "central",
47
+ # "quantity": 1000,
48
+ # "status": 1
49
+ # },
50
+ # {
51
+ # "sku": "new_product1",
52
+ # "source_code": "east",
53
+ # "quantity": 2000,
54
+ # "status": 1
55
+ # }
56
+ # ]
57
+ # )
58
+ # # => []
59
+ #
60
+ # @return Array
61
+ def update_source_items(source_items)
62
+ body = { sourceItems: source_items }
63
+ Request.new.post('inventory/source-items', body).parse
64
+ end
38
65
  end
39
66
  end
40
67
  end
@@ -54,7 +54,12 @@ module Magento
54
54
  begin
55
55
  msg = resp.parse['message']
56
56
  errors = resp.parse['errors'] || resp.parse['parameters']
57
- resp.parse['parameters'].each { |k, v| msg.sub! "%#{k}", v } if resp.parse['parameters'].is_a? Hash
57
+ case errors
58
+ when Hash
59
+ errors.each { |k, v| msg.sub! "%#{k}", v }
60
+ when Array
61
+ errors.each_with_index { |v, i| msg.sub! "%#{i + 1}", v.to_s }
62
+ end
58
63
  rescue StandardError
59
64
  msg = 'Failed access to the magento server'
60
65
  errors = []
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.27.0'
2
+ VERSION = '0.30.0'
3
3
  end
data/lib/magento.rb CHANGED
@@ -25,6 +25,7 @@ require_relative 'magento/guest_cart'
25
25
  require_relative 'magento/sales_rule'
26
26
  require_relative 'magento/inventory'
27
27
  require_relative 'magento/import'
28
+ require_relative 'magento/cart'
28
29
 
29
30
  require_relative 'magento/params/create_custom_attribute'
30
31
  require_relative 'magento/params/create_image'
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.27.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria
@@ -95,6 +95,7 @@ files:
95
95
  - bin/console
96
96
  - bin/setup
97
97
  - lib/magento.rb
98
+ - lib/magento/cart.rb
98
99
  - lib/magento/category.rb
99
100
  - lib/magento/configuration.rb
100
101
  - lib/magento/country.rb
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  - !ruby/object:Gem::Version
186
187
  version: '0'
187
188
  requirements: []
188
- rubygems_version: 3.0.3
189
+ rubygems_version: 3.0.3.1
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Magento Ruby library