rawgento_db 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/rawgento_db.rb +4 -2
- data/lib/rawgento_db/query.rb +49 -6
- data/lib/rawgento_db/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3b3478f240604d44d825c5e952cbbe7588b091
|
4
|
+
data.tar.gz: fc9d252fab119300aa6df0fb2a187656be37dc8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e3c905bbb095ac98b5efdecdd17f674f8384724e0a67ee4b02b0ad7e286189abdfbd6281ffa26b132fa1b64cc22aec733f899a1a8126652d17dd368645834b2
|
7
|
+
data.tar.gz: 3041a3b2dcc9779872f4766f29d66671cfc98989e035272c63480da44ab66eb0dc3a7bf29da366619911ea9e6c5a821ab00c30a75df88ebe523a4364790c6c28
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RawgentoDB
|
2
2
|
|
3
|
-
Interact with a Magento MySQL database, using assumptions of a specific installation
|
3
|
+
Interact with a Magento MySQL database, using assumptions of a specific installation.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,6 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install rawgento_db
|
20
20
|
|
21
|
-
## Usage
|
22
21
|
|
23
22
|
### Configuration
|
24
23
|
|
@@ -30,6 +29,26 @@ Edit rawgento_db-config.yml to your needs.
|
|
30
29
|
username: myuser
|
31
30
|
password: mysecret
|
32
31
|
|
32
|
+
The first 5 keys define access to the mysql (magento) database.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
`RawgentoDB` defines the following methods:
|
37
|
+
|
38
|
+
- `RawgetoDB.settings`: Reads the aforementioned config file and returns its values (a hash). The settings are needed for all the other operations.
|
39
|
+
- `RawgentoDB::Query.products`: Returns an array of Struct(:product_id, '')s containing the product_id (unfortunately, name is not easily accessible atm).
|
40
|
+
- `RawgentoDB::Query.stock`: Returns am array of Struct(:product_id, :qty)s containing current stock per product.
|
41
|
+
- `RawgentoDB::Query.understock(settings)`: Returns array of [product_id, qty, min_qty] for products with notify_min_stock smaller than current stock.
|
42
|
+
- `RawgentoDB::Query.sales_monthly(product_id, settings)`: Returns array of [period, qty_ordered] information for one product.
|
43
|
+
- `RawgentoDB::Query.sales_daily(product_id, settings)`: Returns array of [period, qty_ordered] information for one product.
|
44
|
+
- `RawgentoDB::Query.attribute_varchar(attribute_id, settings)`: Returns array of [product_id, attribute_value] varchar-attribute-value information for all products.
|
45
|
+
- `RawgentoDB::Query.attribute_option(attribute_id, settings)`: Returns array of [product_id, attribute_value] attribute-value of an option for all products.
|
46
|
+
|
47
|
+
|
48
|
+
Furthermore, some command line applications are provided to get a view on the Shop through the eyes of the `rawgento_db` gem:
|
49
|
+
|
50
|
+
- `rawgento_show_products`: Shows a table of products.
|
51
|
+
|
33
52
|
## Development
|
34
53
|
|
35
54
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec rawgento_db` to use the gem in this directory, ignoring other installed copies of this gem.
|
data/lib/rawgento_db.rb
CHANGED
@@ -3,7 +3,9 @@ require "rawgento_db/query"
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module RawgentoDB
|
6
|
-
|
7
|
-
|
6
|
+
DEFAULT_CONFIG_FILE = "rawgento_db-config.yml"
|
7
|
+
def self.settings file=DEFAULT_CONFIG_FILE
|
8
|
+
@@settings ||= YAML.load_file(file || DEFAULT_CONFIG_FILE)
|
9
|
+
@@settings
|
8
10
|
end
|
9
11
|
end
|
data/lib/rawgento_db/query.rb
CHANGED
@@ -6,16 +6,16 @@ module RawgentoDB
|
|
6
6
|
|
7
7
|
class Query
|
8
8
|
def self.client settings
|
9
|
+
# Pick up a memoized settings?
|
9
10
|
Mysql2::Client.new settings
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.products settings
|
13
|
-
|
14
|
-
|
15
|
-
'
|
16
|
-
' csi.product_id=cpf.entity_id')
|
14
|
+
# Unfortunately, name is an own attribute in different table.
|
15
|
+
result = client(settings).query('SELECT entity_id '\
|
16
|
+
'FROM catalog_product_entity')
|
17
17
|
result.map do |r|
|
18
|
-
Product.new r["
|
18
|
+
Product.new r["entity_id"], r[""]
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -27,7 +27,18 @@ module RawgentoDB
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.
|
30
|
+
def self.understocked settings
|
31
|
+
results = client(settings).query(
|
32
|
+
"SELECT product_id, qty, notify_stock_qty "\
|
33
|
+
"FROM cataloginventory_stock_item "\
|
34
|
+
"WHERE notify_stock_qty > qty;")
|
35
|
+
results.map do |row|
|
36
|
+
[row['product_id'], row['name'],
|
37
|
+
row['notify_stock_qty'], row['qty']]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.sales_monthly product_id, settings
|
31
42
|
result = client(settings).query('SELECT * '\
|
32
43
|
'FROM sales_bestsellers_aggregated_monthly '\
|
33
44
|
' WHERE product_id = %d ORDER BY period DESC' % product_id)
|
@@ -35,5 +46,37 @@ module RawgentoDB
|
|
35
46
|
[r['period'], "%1.0f" % r['qty_ordered']]
|
36
47
|
end
|
37
48
|
end
|
49
|
+
|
50
|
+
def self.sales_daily product_id, settings
|
51
|
+
result = client(settings).query('SELECT * '\
|
52
|
+
'FROM sales_bestsellers_aggregated_daily '\
|
53
|
+
' WHERE product_id = %d ORDER BY period DESC' % product_id)
|
54
|
+
result.map do |r|
|
55
|
+
[r['period'], "%1.0f" % r['qty_ordered']]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.attribute_varchar attribute_id, settings
|
60
|
+
result = client(settings).query("
|
61
|
+
SELECT entity_id, value
|
62
|
+
FROM catalog_product_entity_varchar
|
63
|
+
WHERE attribute_id=#{attribute_id};")
|
64
|
+
result.map do |r|
|
65
|
+
[r['entity_id'], r['value']]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.attribute_option attribute_id, settings
|
70
|
+
# Join
|
71
|
+
result = client(settings).query("
|
72
|
+
SELECT optchoice.entity_id, optval.value
|
73
|
+
FROM eav_attribute_option_value as optval,
|
74
|
+
catalog_product_entity_int as optchoice
|
75
|
+
WHERE optchoice.attribute_id=#{attribute_id}
|
76
|
+
AND optval.option_id=optchoice.value;")
|
77
|
+
result.map do |r|
|
78
|
+
[r['entity_id'], r['value']]
|
79
|
+
end
|
80
|
+
end
|
38
81
|
end
|
39
82
|
end
|
data/lib/rawgento_db/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rawgento_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Wolfsteller
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rawgento_models
|