magento 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/magento/model.rb +2 -1
- data/lib/magento/query.rb +16 -3
- data/lib/magento/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2d89a076f05f6e5a3f3a828d7658582a76556e57f6f0ff07a2422044ce82ab4
|
4
|
+
data.tar.gz: fbf4ab1013bf639d81781cc40042aedc5ed62062207f597e127a2ba0bc5b21b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b31854a2ad2fb3ed3ea8711c45e56a426abae13c17b392c69e0186f2594d5bb7654baf8e0dc55cf72265340153bdba56edfdff0a28836d1516d55a7c7537c4ab
|
7
|
+
data.tar.gz: 364a54b27877e55198d1cbb6f2f749aaa399301ba377ade578e2f9e092bd280002aa7cc1932c367adc8825c6790ab4aae2d39e20c30202f3a53d3cf2ecb9ce24
|
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.10.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -68,6 +68,7 @@ Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, {
|
|
68
68
|
#### Filters:
|
69
69
|
|
70
70
|
```rb
|
71
|
+
Magento::Product.where(visibility: 4).all
|
71
72
|
Magento::Product.where(name_like: 'IPhone%').all
|
72
73
|
Magento::Product.where(price_gt: 100).all
|
73
74
|
|
@@ -130,6 +131,20 @@ products = Magento::Product.select(:sku, :name)
|
|
130
131
|
.all
|
131
132
|
```
|
132
133
|
|
134
|
+
## Get one
|
135
|
+
|
136
|
+
```rb
|
137
|
+
Magento::Order.where(increment_id: '000013457').first
|
138
|
+
# or
|
139
|
+
Magento::Order.find_by(increment_id: '000013457')
|
140
|
+
```
|
141
|
+
|
142
|
+
## Count
|
143
|
+
```rb
|
144
|
+
Magento::Order.count
|
145
|
+
Magento::Order.where(status: :pending).count
|
146
|
+
```
|
147
|
+
|
133
148
|
\* _same pattern to all models_
|
134
149
|
|
135
150
|
### Response
|
data/lib/magento/model.rb
CHANGED
@@ -27,7 +27,8 @@ module Magento
|
|
27
27
|
class << self
|
28
28
|
extend Forwardable
|
29
29
|
|
30
|
-
def_delegators :query, :all, :page, :per, :page_size, :order, :select,
|
30
|
+
def_delegators :query, :all, :page, :per, :page_size, :order, :select,
|
31
|
+
:where, :first, :find_by, :count
|
31
32
|
|
32
33
|
def find(id)
|
33
34
|
hash = request.get("#{api_resource}/#{id}").parse
|
data/lib/magento/query.rb
CHANGED
@@ -89,6 +89,18 @@ module Magento
|
|
89
89
|
RecordCollection.from_magento_response(result, model: model, iterable_field: field)
|
90
90
|
end
|
91
91
|
|
92
|
+
def first
|
93
|
+
page_size(1).page(1).all.first
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_by(attributes)
|
97
|
+
where(attributes).first
|
98
|
+
end
|
99
|
+
|
100
|
+
def count
|
101
|
+
select(:id).page_size(1).page(1).all.total_count
|
102
|
+
end
|
103
|
+
|
92
104
|
private
|
93
105
|
|
94
106
|
attr_accessor :current_page, :filter_groups, :request, :sort_orders, :model, :fields
|
@@ -119,10 +131,11 @@ module Magento
|
|
119
131
|
|
120
132
|
def parse_filter(key)
|
121
133
|
patter = /(.*)_([a-z]+)$/
|
122
|
-
|
123
|
-
|
134
|
+
match = key.match(patter)
|
135
|
+
|
136
|
+
return match.to_a[1..2] if match && ACCEPTED_CONDITIONS.include?(match[2])
|
124
137
|
|
125
|
-
key
|
138
|
+
[key, 'eq']
|
126
139
|
end
|
127
140
|
|
128
141
|
def parse_value_filter(condition, value)
|
data/lib/magento/version.rb
CHANGED