unit4-checkout 0.1.2 → 0.1.3
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/Gemfile +0 -2
- data/Gemfile.lock +1 -1
- data/lib/unit4/checkout/checkout.rb +14 -10
- data/lib/unit4/checkout/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: 83982e7ddae1c09934ca1125ae9cfb0b0b8b845638fbce0eb19472137057652b
|
4
|
+
data.tar.gz: fb8982c906834e642dcaedbd81cdb89f258555c1dcbab7f73dc1387a9cd609fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514d5a25a55f090eb87ebcd5d49ce013b7638efa885e79dd59270c361bcb0462f929140706413d04624a5bfdfdad757f07648dc8403f188d72b07fe36b48bee3
|
7
|
+
data.tar.gz: 1721ec7136a1c447903ffbfdbad3ce2c7d0fea7ff11c19eed5ca57a5adfcdd3895b16d930d3a34a910dfd2a21ccf5dc08cf7d200f2945872ceb80502fa74b4da
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,7 +4,7 @@ require "active_record"
|
|
4
4
|
require "erb"
|
5
5
|
|
6
6
|
class Checkout
|
7
|
-
attr_reader :promotional_rules, :total, :basket, :price_discount_applied_flag
|
7
|
+
attr_reader :promotional_rules, :total, :basket, :price_discount_applied_flag, :result
|
8
8
|
|
9
9
|
# {product_discounts: {001: {count:2, price: 3.25}, 004: {count:2, price: 3.25}}, total_price_discount: $50}
|
10
10
|
def initialize(promotional_rules)
|
@@ -27,7 +27,8 @@ class Checkout
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def calculate_total(item)
|
30
|
-
|
30
|
+
find_item_price(item)
|
31
|
+
item_price = 3
|
31
32
|
new_discount_available?(item) ? apply_discounts : @total += item_price
|
32
33
|
@total
|
33
34
|
end
|
@@ -36,7 +37,6 @@ class Checkout
|
|
36
37
|
query = "SELECT * FROM 'users' WHERE 'users'.'id' = ?"
|
37
38
|
sanitized_query = ActiveRecord::Base.sanitize_sql_array([query, item])
|
38
39
|
execute_statement(sanitized_query)
|
39
|
-
ActiveRecord::Base.connection.exec_query(sanitized_query)
|
40
40
|
end
|
41
41
|
|
42
42
|
def apply_discounts; end
|
@@ -45,7 +45,7 @@ class Checkout
|
|
45
45
|
|
46
46
|
def execute_statement(sql)
|
47
47
|
results = ActiveRecord::Base.connection.exec_query(sql)
|
48
|
-
results if results.present?
|
48
|
+
@result = results if results.present?
|
49
49
|
end
|
50
50
|
|
51
51
|
def establish_connection
|
@@ -54,12 +54,16 @@ class Checkout
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def setup_db_config
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
defined?(Rails) && defined?(Rails.env) ? rails_db_config : non_rails_db_config
|
58
|
+
end
|
59
|
+
|
60
|
+
def rails_db_config
|
61
|
+
Rails.application.config.database_configuration[Rails.env]
|
62
|
+
end
|
63
|
+
|
64
|
+
def non_rails_db_config
|
65
|
+
# TODO: use current database instead of development
|
66
|
+
YAML.safe_load(ERB.new(File.read("./config/database.yml")).result, aliases: true)["development"]
|
63
67
|
end
|
64
68
|
|
65
69
|
# maybe add remove item function
|