add spree currency helper, fix some typos and specs

This commit is contained in:
Rafael Schouten
2014-09-11 11:47:55 +10:00
parent c1971d015c
commit 09a4c4e17e
7 changed files with 20 additions and 19 deletions

View File

@@ -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)

View File

@@ -0,0 +1,5 @@
module SpreeCurrencyHelper
def spree_number_to_currency(amount)
Spree::Money.new(amount).to_s
end
end

View File

@@ -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

View File

@@ -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 %>

View File

@@ -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
\:

View File

@@ -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)

View File

@@ -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"