mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
add spree currency helper, fix some typos and specs
This commit is contained in:
@@ -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)
|
||||
|
||||
5
app/helpers/spree_currency_helper.rb
Normal file
5
app/helpers/spree_currency_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module SpreeCurrencyHelper
|
||||
def spree_number_to_currency(amount)
|
||||
Spree::Money.new(amount).to_s
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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
|
||||
\:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user