rawgento_db 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rawgento_db/query.rb +33 -0
- 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: 0a18a19fc40b1eabf92dfbeec7154f11ad6c7f7f
|
4
|
+
data.tar.gz: 3e8d26d8ca8f4327999b6882ef02a411e98aa975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e18f430c07c881e7e2915179ba9de321b070f714ae5960c22335086e9ece44ca12cb9daf617e78c2c9edfe6c8704145984d4d29b6000df6fe596e0e0780dff
|
7
|
+
data.tar.gz: c98bdb11bd142844244f5d4d504fda5aae0ee8c2fe8e790545381d1250775a909be197ab09a7c0ff5ee02d03efbfc11ae0c06e3c02935769b320d4ef5a0a6ded
|
data/lib/rawgento_db/query.rb
CHANGED
@@ -38,6 +38,26 @@ module RawgentoDB
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.update_stock product_id, stock_addition, settings=RawgentoDB.settings
|
42
|
+
results = client(settings).query(
|
43
|
+
"UPDATE cataloginventory_stock_item SET qty = qty + %f "\
|
44
|
+
"WHERE product_id = %d", [stock_addition, product_id])
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.set_available_on_stock product_id, settings=RawgentoDB.settings
|
48
|
+
result = client(settings).query(
|
49
|
+
"SELECT is_in_stock FROM cataloginventory_stock_item "\
|
50
|
+
"WHERE product_id = %d AND is_in_stock = 0 AND qty > 0", product_id)
|
51
|
+
if result.length && result[0] == 0
|
52
|
+
result = client(settings).query(
|
53
|
+
"UPDATE cataloginventory_stock_item SET is_in_stock = 1 "\
|
54
|
+
"WHERE product_id = %d", product_id)
|
55
|
+
result
|
56
|
+
else
|
57
|
+
"unclear what happened"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
41
61
|
# Newer version might require query via entity_id
|
42
62
|
# array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
|
43
63
|
# "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
|
@@ -56,6 +76,19 @@ module RawgentoDB
|
|
56
76
|
end
|
57
77
|
end
|
58
78
|
|
79
|
+
def self.sales_monthly_between product_id, from_date, to_date, settings=RawgentoDB.settings
|
80
|
+
min_date, max_date = [from_date, to_date].minmax
|
81
|
+
query = 'SELECT DISTINCT * '\
|
82
|
+
'FROM sales_bestsellers_aggregated_monthly '\
|
83
|
+
'WHERE product_id = %d AND '\
|
84
|
+
'period >= \'%s\' AND period <= \'%s\' '\
|
85
|
+
'ORDER BY period DESC' % [product_id, min_date.strftime, max_date.strftime]
|
86
|
+
result = client(settings).query(query)
|
87
|
+
result.map do |r|
|
88
|
+
[r['period'], "%1.0f" % r['qty_ordered']]
|
89
|
+
end#.uniq
|
90
|
+
end
|
91
|
+
|
59
92
|
def self.sales_monthly product_id, settings=RawgentoDB.settings
|
60
93
|
result = client(settings).query('SELECT * '\
|
61
94
|
'FROM sales_bestsellers_aggregated_monthly '\
|
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.1.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rawgento_models
|