Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/concerns/spree/user_reporting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def average_order_value
if order_count.to_i > 0
lifetime_value / order_count
else
BigDecimal("0.00")
Spree::ZERO
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions core/app/models/spree/calculator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'spree/preferences/persistable'

module Spree
class Calculator < Spree::Base
include Spree::Preferences::Persistable
Expand Down
1 change: 0 additions & 1 deletion core/app/models/spree/payment_method.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'spree/preferences/persistable'
require 'spree/preferences/statically_configurable'

module Spree
Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class GatewayError < RuntimeError; end
require 'spree/bus'
require 'spree/config'
require 'spree/core/engine'
require 'spree/zero'

require 'spree/i18n'
require 'spree/localized_number'
Expand Down
6 changes: 1 addition & 5 deletions core/lib/spree/preferences/preferable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ def convert_preference_value(value, type, preference_encryptor = nil)
when :password
value.to_s
when :decimal
begin
value.to_s.to_d
rescue ArgumentError
BigDecimal(0)
end
value.to_s.to_d
when :integer
value.to_i
when :boolean
Expand Down
3 changes: 3 additions & 0 deletions core/lib/spree/zero.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

Spree::ZERO = BigDecimal(0).freeze
2 changes: 1 addition & 1 deletion core/spec/models/spree/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@
# this is a strange default for ActiveRecord

it '#amount' do
expect(subject.amount).to eql(BigDecimal('0'))
expect(subject.amount).to eql(Spree::ZERO)
end
end

Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def load_orders
end
context "without orders" do
it "returns 0.00" do
expect(subject.lifetime_value).to eq BigDecimal("0.00")
expect(subject.lifetime_value).to eq Spree::ZERO
end
end
end
Expand Down Expand Up @@ -144,7 +144,7 @@ def load_orders
end
context "without orders" do
it "returns 0.00" do
expect(subject.average_order_value).to eq BigDecimal("0.00")
expect(subject.average_order_value).to eq Spree::ZERO
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def compute(object)
items_count = object.quantity
items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?

return BigDecimal(0) if items_count == 0
return Spree::ZERO if items_count == 0

additional_items_count = items_count - 1
preferred_first_item + preferred_additional_item * additional_items_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def compute(object)

def cast_to_d(value)
value.to_s.to_d
rescue ArgumentError
BigDecimal(0)
end

def preferred_tiers_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def compute(object)

def cast_to_d(value)
value.to_s.to_d
rescue ArgumentError
BigDecimal(0)
end

def preferred_tiers_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def perform(options = {})
# item_total and ship_total
def compute_amount(calculable)
amount = calculator.compute(calculable)
amount ||= BigDecimal(0)
amount ||= Spree::ZERO
amount = amount.abs
[(calculable.item_total + calculable.ship_total), amount].min * -1
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def compute_amount(adjustable)
order = adjustable.is_a?(Order) ? adjustable : adjustable.order
return 0 unless promotion.line_item_actionable?(order, adjustable)
promotion_amount = calculator.compute(adjustable)
promotion_amount ||= BigDecimal(0)
promotion_amount ||= Spree::ZERO
promotion_amount = promotion_amount.abs
[adjustable.amount, promotion_amount].min * -1
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CreateQuantityAdjustments < CreateItemAdjustments
#
def compute_amount(line_item)
adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
adjustment_amount ||= BigDecimal(0)
adjustment_amount ||= Spree::ZERO
adjustment_amount = adjustment_amount.abs

order = line_item.order
Expand Down
2 changes: 0 additions & 2 deletions legacy_promotions/app/models/spree/promotion_action.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'spree/preferences/persistable'

module Spree
# Base class for all types of promotion action.
#
Expand Down
2 changes: 1 addition & 1 deletion legacy_promotions/app/models/spree/promotion_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update
end
best_promotion_adjustment.amount
else
BigDecimal('0')
Spree::ZERO
end
end

Expand Down
2 changes: 0 additions & 2 deletions legacy_promotions/app/models/spree/promotion_rule.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'spree/preferences/persistable'

module Spree
# Base class for all promotion rules
class PromotionRule < Spree::Base
Expand Down
4 changes: 1 addition & 3 deletions promotions/app/models/solidus_promotions/benefit.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "spree/preferences/persistable"

module SolidusPromotions
# Base class for all types of benefit.
#
Expand Down Expand Up @@ -44,7 +42,7 @@ def discount(adjustable)

# Ensure a negative amount which does not exceed the object's amount
def compute_amount(adjustable)
promotion_amount = calculator.compute(adjustable) || BigDecimal("0")
promotion_amount = calculator.compute(adjustable) || Spree::ZERO
[adjustable.discountable_amount, promotion_amount.abs].min * -1
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AdjustLineItemQuantityGroups < AdjustLineItem
#
def compute_amount(line_item)
adjustment_amount = calculator.compute(Item.new(line_item))
return BigDecimal("0") if adjustment_amount.nil? || adjustment_amount.zero?
return Spree::ZERO if adjustment_amount.nil? || adjustment_amount.zero?

adjustment_amount = adjustment_amount.abs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def compute(object)
items_count = object.quantity
items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?

return BigDecimal("0") if items_count == 0
return Spree::ZERO if items_count == 0

additional_items_count = items_count - 1
preferred_first_item + preferred_additional_item * additional_items_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def compute_item(object)

def cast_to_d(value)
value.to_s.to_d
rescue ArgumentError
BigDecimal("0")
end

def preferred_tiers_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def compute_item(object)

def cast_to_d(value)
value.to_s.to_d
rescue ArgumentError
BigDecimal("0")
end

def preferred_tiers_content
Expand Down
2 changes: 0 additions & 2 deletions promotions/app/models/solidus_promotions/condition.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "spree/preferences/persistable"

module SolidusPromotions
class Condition < Spree::Base
include Spree::Preferences::Persistable
Expand Down
Loading