rawgento_db 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 4622e7707a432c99a1e294cd1d78250d058d9068
4
- data.tar.gz: b6a2811e39bf69befb9afb9d18fe5ce5c677f4ab
3
+ metadata.gz: 0a18a19fc40b1eabf92dfbeec7154f11ad6c7f7f
4
+ data.tar.gz: 3e8d26d8ca8f4327999b6882ef02a411e98aa975
5
5
  SHA512:
6
- metadata.gz: 867da4b5037e036803c25536a81118d84ed79dbe0b1c2fd2181df206aad367c891a53402ed7d45e40e55a92eb7291a400ac5757e86d433185a8e4687d7873531
7
- data.tar.gz: 3a26b4fe0f942704b7445dbce6a557f050bcc587dd11d47e23cb25172740211e82c5eff3779e40904130ff7948e767f0a745855a796af95768bf7ff8dfbe9f9a
6
+ metadata.gz: 00e18f430c07c881e7e2915179ba9de321b070f714ae5960c22335086e9ece44ca12cb9daf617e78c2c9edfe6c8704145984d4d29b6000df6fe596e0e0780dff
7
+ data.tar.gz: c98bdb11bd142844244f5d4d504fda5aae0ee8c2fe8e790545381d1250775a909be197ab09a7c0ff5ee02d03efbfc11ae0c06e3c02935769b320d4ef5a0a6ded
@@ -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 '\
@@ -1,3 +1,3 @@
1
1
  module RawgentoDB
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-05-29 00:00:00.000000000 Z
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rawgento_models