flowcommerce_spree 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad7616da6a9fb5e7fbffe0a8869730ffedacb91deec3a5d08f328d2b876338ad
4
- data.tar.gz: 76ffd0d23d05028ba0d24df80fa5a092efe62f0b5f14ddde339e73ede5ee53bc
3
+ metadata.gz: d0e6c714f8986d91af70150c8365f3bde79a15b843151cc84bf5fabd83cf7e87
4
+ data.tar.gz: 4b0b172606e24bddd55d8254da339af2bf4751b441d918478310835102c9f282
5
5
  SHA512:
6
- metadata.gz: 1eb2b92c39dd528cc4990d9957ee5dba29fbdfa39d7f7a4b821d07a6f5cb366541821b67a6d23ccbc9854b3c3c0867e0cd3fff8b36f64cea627b2fa6d7da47df
7
- data.tar.gz: 75175908d8ff3a85ca061ea82890af39544e66bf5898409e0b38d467bc40880eb6ac8e1773263cc5e933ef54d28bf00a2fb1a3f5cddbd935793b92c7fa0e89f2
6
+ metadata.gz: 915818b7f7ffd75a3e2adf67d25403b5ea342b0095f2b051d4044ef91c942bee15e2e6b0a235a62f53b7e95af88f6b2626f0a3a58767214e413ad9fc3695a36a
7
+ data.tar.gz: '048827e500e921d90c3dba7169644a09702f89551be7083820b0d4c337a97a0f513609417dee1f9017f266a8f28bf846dcb5c124262dee7fed03defecbda97fd'
@@ -28,9 +28,9 @@ module Spree
28
28
  flow_data["#{flow_exp.key}.excluded"].to_i != 1
29
29
  end
30
30
 
31
- def price_range(product_zone)
31
+ def price_range(product_zone, currencies = [])
32
32
  prices = {}
33
- master_prices.each do |p|
33
+ master_prices_with_currencies(currencies).each do |p|
34
34
  currency = p.currency
35
35
  min = nil
36
36
  max = nil
@@ -40,15 +40,15 @@ module Spree
40
40
  price = v.price_in(currency)
41
41
  next if price.nil? || price.amount.nil?
42
42
 
43
- min = price if min.nil? || min.amount > price.amount
44
- max = price if max.nil? || max.amount < price.amount
43
+ min = [price, min].compact.min { |a, b| a.amount <=> b.amount }
44
+ max = [price, max].compact.max { |a, b| a.amount <=> b.amount }
45
45
  end
46
46
  else
47
47
  min = max = master.price_in(currency)
48
48
  end
49
49
 
50
- rmin = min&.amount&.to_s(:rounded, precision: 0) || 0
51
- rmax = max&.amount&.to_s(:rounded, precision: 0) || 0
50
+ rmin = round_with_precision(min, 0)
51
+ rmax = round_with_precision(max, 0)
52
52
 
53
53
  prices[currency] = { min: rmin, max: rmax }
54
54
  end
@@ -56,6 +56,10 @@ module Spree
56
56
  add_flow_price_range(prices, product_zone)
57
57
  end
58
58
 
59
+ def round_with_precision(number, precision)
60
+ number&.amount&.to_s(:rounded, precision: precision) || 0
61
+ end
62
+
59
63
  def add_flow_price_range(prices, product_zone)
60
64
  flow_experience_key = product_zone&.flow_data&.[]('key')
61
65
  return prices if flow_experience_key.blank?
@@ -70,8 +74,8 @@ module Spree
70
74
  price = v.flow_local_price(flow_experience_key)
71
75
  next if price.amount.nil? || price.currency != currency
72
76
 
73
- min = price if min.nil? || min.amount > price.amount
74
- max = price if max.nil? || max.amount < price.amount
77
+ min = [price, min].compact.min { |a, b| a.amount <=> b.amount }
78
+ max = [price, max].compact.max { |a, b| a.amount <=> b.amount }
75
79
  end
76
80
  end
77
81
 
@@ -80,8 +84,8 @@ module Spree
80
84
  max ||= master_price
81
85
  end
82
86
 
83
- rmin = min&.amount&.to_s(:rounded, precision: 0) || 0
84
- rmax = max&.amount&.to_s(:rounded, precision: 0) || 0
87
+ rmin = round_with_precision(min, 0)
88
+ rmax = round_with_precision(max, 0)
85
89
 
86
90
  prices[currency] = { min: rmin, max: rmax }
87
91
  prices
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FlowcommerceSpree
4
- VERSION = '0.0.10'
4
+ VERSION = '0.0.11'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowcommerce_spree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurel Branzeanu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-04 00:00:00.000000000 Z
12
+ date: 2021-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_model_serializers