Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow prices with nil amount #3987

Merged
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/spree/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Price < Spree::Base
delegate :tax_rates, to: :variant

validate :check_price
validates :amount, allow_nil: true, numericality: {
validates :amount, numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: MAXIMUM_AMOUNT
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ChangeColumnNullOnPrices < ActiveRecord::Migration[5.2]
def change
change_column_null(:spree_prices, :amount, false)
end
end
13 changes: 13 additions & 0 deletions core/lib/tasks/migrations/delete_prices_with_nil_amount.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

namespace :solidus do
namespace :migrations do
namespace :delete_prices_with_nil_amount do
task up: :environment do
print "Deleting prices wich amount attribute is nil ... "
Spree::Price.where(amount: nil).delete_all
puts "Success"
end
end
end
end
7 changes: 7 additions & 0 deletions core/lib/tasks/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ namespace :solidus do
] do
puts "Your Solidus install is ready for Solidus 2.11"
end

desc "Upgrade Solidus to version 3.0"
task three_point_zero: [
'solidus:migrations:delete_prices_with_nil_amount:up',
] do
puts "Your Solidus install is ready for Solidus 3.0"
end
end
end