Skip to content

Instantly share code, notes, and snippets.

@momolog
Last active January 27, 2024 07:43
Show Gist options
  • Save momolog/7708256 to your computer and use it in GitHub Desktop.
Save momolog/7708256 to your computer and use it in GitHub Desktop.
add minimum order value to spree orders
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
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