diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 12bf76c471..93b59c8e4b 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -8,7 +8,7 @@ module Spree def order_distribution_subtotal(order, options={}) options.reverse_merge! :format_as_currency => true amount = order.adjustments.enterprise_fee.sum &:amount - options.delete(:format_as_currency) ? Spree::Money.new(amount).to_s : amount + options.delete(:format_as_currency) ? spree_number_to_currency(amount) : amount end def alternative_available_distributors(order) diff --git a/app/helpers/spree_currency_helper.rb b/app/helpers/spree_currency_helper.rb new file mode 100644 index 0000000000..479ced2771 --- /dev/null +++ b/app/helpers/spree_currency_helper.rb @@ -0,0 +1,5 @@ +module SpreeCurrencyHelper + def spree_number_to_currency(amount) + Spree::Money.new(amount).to_s + end +end diff --git a/app/views/checkout/_summary.html.haml b/app/views/checkout/_summary.html.haml index dc5392e8d3..8609fd7a16 100644 --- a/app/views/checkout/_summary.html.haml +++ b/app/views/checkout/_summary.html.haml @@ -5,7 +5,7 @@ %table %tr %th Cart total - %td.cart-total.text-right= Spree::Money.new(checkout_cart_total_with_adjustments(current_order)) + %td.cart-total.text-right= spree_number_to_currency(checkout_cart_total_with_adjustments(current_order)) - checkout_adjustments_for_summary(current_order, exclude: [:shipping, :distribution]).each do |adjustment| %tr @@ -14,11 +14,11 @@ %tr %th Shipping - %td.shipping.text-right {{ Checkout.shippingPrice() | spreeCurrency }} + %td.shipping.text-right {{ Checkout.shippingPrice() | localizeCurrency }} %tr %th Total - %td.total.text-right {{ Checkout.cartTotal() | spreeCurrency }} + %td.total.text-right {{ Checkout.cartTotal() | localizeCurrency }} - if current_order.price_adjustment_totals.present? - current_order.price_adjustment_totals.each do |label, total| %tr diff --git a/app/views/spree/order_mailer/confirm_email.text.erb b/app/views/spree/order_mailer/confirm_email.text.erb index 80e08eca52..99f2671a02 100644 --- a/app/views/spree/order_mailer/confirm_email.text.erb +++ b/app/views/spree/order_mailer/confirm_email.text.erb @@ -10,7 +10,7 @@ Order for: <%= @order.bill_address.full_name %> <%= item.variant.sku %> <%= raw(item.variant.product.supplier.name) %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (QTY: <%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> <% end %> ============================================================ -Subtotal: <%= Spree::Money.new(checkout_cart_total_with _adjustments(@order)).to_str %> +Subtotal: <%= spree_number_to_currency(checkout_cart_total_with _adjustments(@order)) %> <% checkout_adjustments_for_summary(@order, exclude: [:distribution]).each do |adjustment| %> <%= raw(adjustment.label) %> <%= adjustment.display_amount %> <% end %> diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index f91c398b64..953ea83e18 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -24,7 +24,7 @@ %td Product \: - %span.order-total.item-total= Spree::Money.new(@order.item_total).to_s + %span.order-total.item-total= spree_number_to_currency(@order.item_total) %td Distribution \: diff --git a/app/views/spree/shared/_products.html.haml b/app/views/spree/shared/_products.html.haml index c66ad23c74..8ea2743642 100644 --- a/app/views/spree/shared/_products.html.haml +++ b/app/views/spree/shared/_products.html.haml @@ -15,7 +15,7 @@ .product-image = link_to small_image(product, :itemprop => "image"), product, :itemprop => 'url' = link_to truncate(product.name, :length => 50), product, :class => 'info', :itemprop => "name", :title => product.name - %span.price.selling{:itemprop => "price"}= Spree::Money.new(product.price).to_s + %span.price.selling{:itemprop => "price"}= spree_number_to_currency(product.price) - if paginated_products.respond_to?(:num_pages) - params.delete(:search) diff --git a/spec/javascripts/unit/darkswarm/filters/localize_currency_spec.js.coffee b/spec/javascripts/unit/darkswarm/filters/localize_currency_spec.js.coffee index fc0b9dafa2..9acc4a1b63 100644 --- a/spec/javascripts/unit/darkswarm/filters/localize_currency_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/filters/localize_currency_spec.js.coffee @@ -1,15 +1,14 @@ describe 'convert number to localised currency ', -> - filter = null - - currencyconfig = - currency: "D" - symbol: "$" - symbol_position: "before" - hide_cents: "false" - decimal_mark: "." - thousands_separator: "," + filter = currencyconfig = null beforeEach -> + currencyconfig = + currency: "D" + symbol: "$" + symbol_position: "before" + hide_cents: "false" + decimal_mark: "." + thousands_separator: "," module 'Darkswarm' module ($provide)-> $provide.value "currencyConfig", currencyconfig @@ -26,16 +25,13 @@ describe 'convert number to localised currency ', -> it "can use any currency symbol", -> currencyconfig.symbol = "£" expect(filter(404.04)).toEqual "£404.04" - currencyconfig.symbol = "$" it "can place symbols after the amount", -> currencyconfig.symbol_position = "after" expect(filter(333.3)).toEqual "333.30 $" - currencyconfig.symbol_position = "before" it "can add a currency string", -> currencyconfig.display_currency = "true" expect(filter(5)).toEqual "$5.00 D" - currencyconfig.display_currency = "false"