magentwo 0.1.5 → 0.1.6
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 +1 -1
- data/lib/adapter.rb +3 -4
- data/lib/dataset.rb +16 -0
- data/lib/filter.rb +13 -1
- data/lib/magentwo.rb +2 -2
- data/lib/model/base.rb +1 -1
- data/lib/model/cart.rb +12 -0
- data/lib/model/order.rb +19 -0
- data/magentwo.gemspec +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: 1f59f2c1b33cb0312fc53612b912df7a33e0497963daab678d4d9483e64cbd70
|
4
|
+
data.tar.gz: 4fdd910bc6d19c011eacc347a23102ba0a04a4a67179137f88a3a1d18ee32c73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ed9e751d283d7ceeee972b61edbfe19338e1c86fb8c2db312104f75346de47c6592c5ff885a3a3c593c4c2cbad6b7230efd60f533600875a290ef72b6b45872
|
7
|
+
data.tar.gz: 1f32e42bca87fda93e87f0bad9b42092b67a3c885679c42784321ebfc460eb27adb102de34fe85d1211a67c91cb8263a76cb8b8355b21ccc8f4cbf22db0a8ad7
|
data/README.md
CHANGED
@@ -90,7 +90,7 @@ end
|
|
90
90
|
To update Models back to Magento 2 use the `save` method
|
91
91
|
This switches the first and last name of the Customer Foo Bar
|
92
92
|
```
|
93
|
-
customer = Magentwo::Customer.filter(:first_name => "Foo"
|
93
|
+
customer = Magentwo::Customer.filter(:first_name => "Foo", :last_name => "Bar").first
|
94
94
|
customer.firstname = "Bar"
|
95
95
|
customer.lastname = "Foo"
|
96
96
|
customer.save
|
data/lib/adapter.rb
CHANGED
@@ -10,14 +10,13 @@ module Magentwo
|
|
10
10
|
end
|
11
11
|
|
12
12
|
response = self.send(http_method, path, params)
|
13
|
-
Magentwo.logger.debug response.body
|
14
|
-
|
13
|
+
Magentwo.logger.debug "Response body: #{response.body}"
|
15
14
|
parsed_response = case method
|
16
15
|
when :get_with_meta_data, :put, :post, :delete then transform( parse( response))
|
17
16
|
when :get
|
18
17
|
parsed = parse(response)
|
19
|
-
if parsed.is_a?(Hash) && parsed
|
20
|
-
parsed[:items].map do |item|
|
18
|
+
if parsed.is_a?(Hash) && (parsed.has_key? :items)
|
19
|
+
(parsed[:items] || []).map do |item|
|
21
20
|
transform item
|
22
21
|
end
|
23
22
|
else
|
data/lib/dataset.rb
CHANGED
@@ -40,6 +40,22 @@ module Magentwo
|
|
40
40
|
filter args, invert:true
|
41
41
|
end
|
42
42
|
|
43
|
+
def gt args
|
44
|
+
Dataset.new self.model, self.opts.merge(:filters => self.opts[:filters] + [Filter::Gt.new(args.keys.first, args.values.first)])
|
45
|
+
end
|
46
|
+
|
47
|
+
def lt args
|
48
|
+
Dataset.new self.model, self.opts.merge(:filters => self.opts[:filters] + [Filter::Lt.new(args.keys.first, args.values.first)])
|
49
|
+
end
|
50
|
+
|
51
|
+
def gteq args
|
52
|
+
Dataset.new self.model, self.opts.merge(:filters => self.opts[:filters] + [Filter::Gteq.new(args.keys.first, args.values.first)])
|
53
|
+
end
|
54
|
+
|
55
|
+
def lteq args
|
56
|
+
Dataset.new self.model, self.opts.merge(:filters => self.opts[:filters] + [Filter::Lteq.new(args.keys.first, args.values.first)])
|
57
|
+
end
|
58
|
+
|
43
59
|
def select *fields
|
44
60
|
Dataset.new self.model, self.opts.merge(:fields => Filter::Fields.new(fields))
|
45
61
|
end
|
data/lib/filter.rb
CHANGED
@@ -20,7 +20,7 @@ module Magentwo
|
|
20
20
|
def to_query idx
|
21
21
|
[
|
22
22
|
"searchCriteria[filter_groups][#{idx}][filters][0][field]=#{self.field}",
|
23
|
-
"searchCriteria[filter_groups][#{idx}][filters][0][value]=#{URI::encode(self.value.join(",")
|
23
|
+
"searchCriteria[filter_groups][#{idx}][filters][0][value]=#{URI::encode(self.value.map(&:to_s).join(","))}",
|
24
24
|
"searchCriteria[filter_groups][#{idx}][filters][0][condition_type]=#{self.class.name.split("::").last.downcase}"]
|
25
25
|
.join("&")
|
26
26
|
end
|
@@ -67,6 +67,18 @@ module Magentwo
|
|
67
67
|
class Like < Magentwo::Filter::Compare
|
68
68
|
end
|
69
69
|
|
70
|
+
class Gt < Magentwo::Filter::Compare
|
71
|
+
end
|
72
|
+
|
73
|
+
class Lt < Magentwo::Filter::Compare
|
74
|
+
end
|
75
|
+
|
76
|
+
class Gteq < Magentwo::Filter::Compare
|
77
|
+
end
|
78
|
+
|
79
|
+
class Lteq < Magentwo::Filter::Compare
|
80
|
+
end
|
81
|
+
|
70
82
|
class PageSize < Magentwo::Filter::Simple
|
71
83
|
def initialize value
|
72
84
|
super(:page_size, value)
|
data/lib/magentwo.rb
CHANGED
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
require 'logger'
|
5
5
|
|
6
6
|
module Magentwo
|
7
|
-
Models = %w(base product customer order coupon sales_rule category)
|
7
|
+
Models = %w(base product customer order coupon sales_rule category cart)
|
8
8
|
def self.connect host=nil, user_name=nil, password=nil
|
9
9
|
raise ArgumentError, "no host specified" unless host
|
10
10
|
raise ArgumentError, "no user_name specified" unless user_name
|
@@ -17,7 +17,7 @@ module Magentwo
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.logger
|
20
|
-
@@logger ||= Logger.new STDOUT, {:level => Logger::
|
20
|
+
@@logger ||= Logger.new STDOUT, {:level => Logger::DEBUG}
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.default_page_size
|
data/lib/model/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Magentwo
|
2
2
|
class Base
|
3
|
-
DatasetMethods = %i(filter exclude select fields count fields info page order_by like)
|
3
|
+
DatasetMethods = %i(filter exclude select fields count fields info page order_by like gt lt gteq lteq)
|
4
4
|
|
5
5
|
def initialize args
|
6
6
|
args.each do |key, value|
|
data/lib/model/cart.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Magentwo
|
2
|
+
class Cart < Base
|
3
|
+
Attributes = %i(id created_at updated_at is_active is_virtual items_count items_qty customer billing_address reserved_order_id orig_order_id currency customer_is_guest customer_note_notify customer_tax_class_id store_id)
|
4
|
+
Attributes.each do |attr| attr_accessor attr end
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def get_path
|
8
|
+
"#{self.base_path}/search"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/model/order.rb
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
module Magentwo
|
2
2
|
class Order < Base
|
3
|
+
Attributes = %i(base_currency_code base_discount_amount base_discount_invoiced base_grand_total base_discount_tax_compensation_amount base_discount_tax_compensation_invoiced base_shipping_amount base_shipping_discount_amount base_shipping_discount_tax_compensation_amnt base_shipping_incl_tax base_shipping_invoiced base_shipping_tax_amount base_subtotal base_subtotal_incl_tax base_subtotal_invoiced base_tax_amount base_tax_invoiced base_total_due base_total_invoiced base_total_invoiced_cost base_total_paid base_to_global_rate base_to_order_rate billing_address_id created_at customer_dob customer_email customer_firstname customer_gender customer_group_id customer_id customer_is_guest customer_lastname customer_note_notify discount_amount discount_invoiced entity_id global_currency_code grand_total discount_tax_compensation_amount discount_tax_compensation_invoiced increment_id is_virtual order_currency_code protect_code quote_id shipping_amount shipping_description shipping_discount_amount shipping_discount_tax_compensation_amount shipping_incl_tax shipping_invoiced shipping_tax_amount state status store_currency_code store_id store_name store_to_base_rate store_to_order_rate subtotal subtotal_incl_tax subtotal_invoiced tax_amount tax_invoiced total_due total_invoiced total_item_count total_paid total_qty_ordered updated_at weight items billing_address payment status_histories extension_attributes amount_refunded base_amount_refunded base_discount_amount base_discount_invoiced base_discount_tax_compensation_amount base_discount_tax_compensation_invoiced base_original_price base_price base_price_incl_tax base_row_invoiced base_row_total base_row_total_incl_tax base_tax_amount base_tax_invoiced created_at discount_amount discount_invoiced discount_percent free_shipping discount_tax_compensation_amount discount_tax_compensation_invoiced is_qty_decimal item_id name no_discount order_id original_price price price_incl_tax product_id product_type qty_canceled qty_invoiced qty_ordered qty_refunded qty_shipped row_invoiced row_total row_total_incl_tax row_weight sku store_id tax_amount tax_invoiced tax_percent updated_at weight)
|
4
|
+
Attributes.each do |attr| attr_accessor attr end
|
3
5
|
|
6
|
+
def products
|
7
|
+
product_skus = self.items.map do |item|
|
8
|
+
item[:sku]
|
9
|
+
end
|
10
|
+
Magentwo::Product.filter(:sku => product_skus).all
|
11
|
+
end
|
12
|
+
|
13
|
+
def customer
|
14
|
+
Magentwo::Customer[self.customer_id]
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
#this is necessary as the return type of magento2 is not consistent
|
19
|
+
def [] unique_identifier
|
20
|
+
self.filter(:entity_id => unique_identifier).first
|
21
|
+
end
|
22
|
+
end
|
4
23
|
end
|
5
24
|
end
|
data/magentwo.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magentwo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Mueß
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/filter.rb
|
28
28
|
- lib/magentwo.rb
|
29
29
|
- lib/model/base.rb
|
30
|
+
- lib/model/cart.rb
|
30
31
|
- lib/model/category.rb
|
31
32
|
- lib/model/coupon.rb
|
32
33
|
- lib/model/customer.rb
|