Last active
January 27, 2024 07:43
-
-
Save momolog/7708256 to your computer and use it in GitHub Desktop.
add minimum order value to spree orders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spree::CheckoutController.class_eval do | |
def ensure_checkout_allowed | |
check = @order.checkout_allowed? | |
unless check == true | |
redirect_to spree.cart_path, :flash => {:error => I18n.t("checkout_allowed_errors.#{check}")} | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spree::Order.class_eval do | |
MINIMUM_ORDER_VALUE = (ENV['MINIMUM_ORDER_VALUE'] || 20).to_i | |
def checkout_allowed? | |
return :not_empty unless line_items.count > 0 | |
return :minimum_value unless total >= MINIMUM_ORDER_VALUE | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment