mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
add currency localisation
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -36,3 +36,5 @@ config/initializers/feature_toggle.rb
|
||||
NERD_tree*
|
||||
coverage
|
||||
libpeerconnection.log
|
||||
tags
|
||||
app/assets/javascripts/tags
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Convert number to string currency using injected currency localisation settings.
|
||||
#
|
||||
# Injected: currencyLocalisation - see /app/serializers/api/currency_localization_serializer.rb
|
||||
|
||||
Darkswarm.filter "localiseCurrency", (currencyLocalization)->
|
||||
(amount) ->
|
||||
decimals = if currencyLocalization.hide_cents then 0 else 2
|
||||
amount_fixed = amount.toFixed(decimals)
|
||||
currency_str = ""
|
||||
currency_str = " " + currencyLocalization.currency if currencyLocalization.display_currency
|
||||
|
||||
# Return string
|
||||
if currencyLocalization.symbol_position == 'before'
|
||||
currencyLocalization.symbol + amount_fixed + currency_str
|
||||
else
|
||||
amount_fixed + " " + currencyLocalization.symbol + currency_str
|
||||
|
||||
@@ -6,6 +6,6 @@ Darkswarm.factory 'Variants', ->
|
||||
|
||||
extend: (variant)->
|
||||
variant.getPrice = ->
|
||||
variant.price * variant.line_item.quantity
|
||||
variant.basePricePercentage = Math.round(variant.base_price / variant.price * 100)
|
||||
variant.price_with_fees * variant.line_item.quantity
|
||||
variant.basePricePercentage = Math.round(variant.price / variant.price_with_fees * 100)
|
||||
variant
|
||||
|
||||
@@ -10,26 +10,26 @@
|
||||
.expanded{"ng-show" => "expanded"}
|
||||
%ul
|
||||
%li.cost
|
||||
.right {{ variant.base_price | currency }}
|
||||
.right {{ variant.price | localiseCurrency }}
|
||||
Item cost
|
||||
%li{"bo-if" => "variant.fees.admin"}
|
||||
.right {{ variant.fees.admin | currency }}
|
||||
.right {{ variant.fees.admin | localiseCurrency }}
|
||||
Admin fee
|
||||
%li{"bo-if" => "variant.fees.sales"}
|
||||
.right {{ variant.fees.sales | currency }}
|
||||
.right {{ variant.fees.sales | localiseCurrency }}
|
||||
Sales fee
|
||||
%li{"bo-if" => "variant.fees.packing"}
|
||||
.right {{ variant.fees.packing | currency }}
|
||||
.right {{ variant.fees.packing | localiseCurrency }}
|
||||
Packing fee
|
||||
%li{"bo-if" => "variant.fees.transport"}
|
||||
.right {{ variant.fees.transport | currency }}
|
||||
.right {{ variant.fees.transport | localiseCurrency }}
|
||||
Transport fee
|
||||
%li{"bo-if" => "variant.fees.fundraising"}
|
||||
.right {{ variant.fees.fundraising | currency }}
|
||||
.right {{ variant.fees.fundraising | localiseCurrency }}
|
||||
Fundraising fee
|
||||
%li
|
||||
%strong
|
||||
.right = {{ variant.price | currency }}
|
||||
.right = {{ variant.price | localiseCurrency }}
|
||||
|
||||
|
||||
%a{"ng-click" => "expanded = !expanded"}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
.small-4.medium-2.large-2.columns.variant-price
|
||||
.table-cell.price
|
||||
%i.ofn-i_009-close
|
||||
{{ variant.price | currency }}
|
||||
{{ variant.price | localiseCurrency }}
|
||||
|
||||
-# Now in a template in app/assets/javascripts/templates !
|
||||
%price-breakdown{"price-breakdown" => "_", variant: "variant",
|
||||
@@ -59,4 +59,4 @@
|
||||
.small-12.medium-2.large-2.columns.total-price.text-right
|
||||
.table-cell
|
||||
%strong
|
||||
{{ variant.getPrice() | currency }}
|
||||
{{ variant.getPrice() | localiseCurrency }}
|
||||
|
||||
@@ -21,6 +21,11 @@ module InjectionHelper
|
||||
inject_json_ams "taxons", Spree::Taxon.all, Api::TaxonSerializer
|
||||
end
|
||||
|
||||
def inject_currency_localization
|
||||
inject_json_ams "currencyLocalization", {}, Api::CurrencyLocalizationSerializer
|
||||
end
|
||||
|
||||
|
||||
def inject_json(name, partial, opts = {})
|
||||
render partial: "json/injection", locals: {name: name, partial: partial}.merge(opts)
|
||||
end
|
||||
|
||||
@@ -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) ? number_to_currency(amount) : amount
|
||||
options.delete(:format_as_currency) ? Spree::Money.new(amount).to_s : amount
|
||||
end
|
||||
|
||||
def alternative_available_distributors(order)
|
||||
|
||||
32
app/serializers/api/currency_localization_serializer.rb
Normal file
32
app/serializers/api/currency_localization_serializer.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class Api::CurrencyLocalizationSerializer < ActiveModel::Serializer
|
||||
attributes :currency, :display_currency, :symbol, :symbol_position, :hide_cents, :decimal_mark, :thousands_separator
|
||||
|
||||
def currency
|
||||
Spree::Config[:currency]
|
||||
end
|
||||
|
||||
def display_currency
|
||||
Spree::Config[:display_currency]
|
||||
end
|
||||
|
||||
def symbol
|
||||
::Money.new(1, Spree::Config[:currency]).symbol
|
||||
end
|
||||
|
||||
def symbol_position
|
||||
Spree::Config[:currency_symbol_position]
|
||||
end
|
||||
|
||||
def hide_cents
|
||||
Spree::Config[:hide_cents]
|
||||
end
|
||||
|
||||
def decimal_mark
|
||||
Spree::Config[:currency_decimal_mark]
|
||||
end
|
||||
|
||||
def thousands_separator
|
||||
Spree::Config[:currency_thousands_separator]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,13 +1,13 @@
|
||||
class Api::VariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display,
|
||||
:on_demand, :price, :fees, :base_price
|
||||
:on_demand, :price, :fees, :price_with_fees
|
||||
|
||||
def price
|
||||
object.price_with_fees(options[:current_distributor], options[:current_order_cycle])
|
||||
def price_with_fees
|
||||
object.price_with_fees(options[:current_distributor], options[:current_order_cycle]).to_f
|
||||
end
|
||||
|
||||
def base_price
|
||||
object.price
|
||||
def price
|
||||
object.price.to_f
|
||||
end
|
||||
|
||||
def fees
|
||||
|
||||
@@ -7,6 +7,6 @@ class Spree::Api::VariantSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def price
|
||||
object.price.nil? ? 0.to_f : object.price
|
||||
object.price.nil? ? 0.to_f : object.price.to_f
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
%table
|
||||
%tr
|
||||
%th Cart total
|
||||
%td.cart-total.text-right= number_to_currency checkout_cart_total_with_adjustments(current_order)
|
||||
%td.cart-total.text-right= Spree::Money.new(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() | currency }}
|
||||
%td.shipping.text-right {{ Checkout.shippingPrice() | spreeCurrency }}
|
||||
|
||||
%tr
|
||||
%th Total
|
||||
%td.total.text-right {{ Checkout.cartTotal() | currency }}
|
||||
%td.total.text-right {{ Checkout.cartTotal() | spreeCurrency }}
|
||||
- if current_order.price_adjustment_totals.present?
|
||||
- current_order.price_adjustment_totals.each do |label, total|
|
||||
%tr
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
= inject_json "railsFlash", "flash"
|
||||
= inject_taxons
|
||||
= inject_current_order
|
||||
= inject_currency_localization
|
||||
|
||||
.off-canvas-wrap{offcanvas: true}
|
||||
.inner-wrap
|
||||
|
||||
@@ -22,20 +22,20 @@
|
||||
%small
|
||||
{{line_item.quantity}}
|
||||
%i.ofn-i_009-close
|
||||
{{ line_item.variant.price | currency }}
|
||||
{{ line_item.variant.price_with_fees | localiseCurrency }}
|
||||
|
||||
.columns.small-2
|
||||
%small
|
||||
\=
|
||||
%strong
|
||||
.right {{ line_item.variant.getPrice() | currency }}
|
||||
.right {{ line_item.variant.getPrice() | localiseCurrency }}
|
||||
|
||||
%li.total-cart{"ng-show" => "Cart.line_items_present().length > 0"}
|
||||
.row
|
||||
.columns.small-6
|
||||
%em Total:
|
||||
.columns.small-6.text-right
|
||||
%strong {{ Cart.total() | currency }}
|
||||
%strong {{ Cart.total() | localiseCurrency }}
|
||||
|
||||
.text-right
|
||||
%a.button.primary.small{href: checkout_path, "ng-disabled" => "Cart.dirty"} Quick checkout
|
||||
|
||||
@@ -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: <%= number_to_currency checkout_cart_total_with_adjustments(@order) %>
|
||||
Subtotal: <%= Spree::Money.new(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= number_to_currency @order.item_total
|
||||
%span.order-total.item-total= Spree::Money.new(@order.item_total).to_s
|
||||
%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"}= number_to_currency product.price
|
||||
%span.price.selling{:itemprop => "price"}= Spree::Money.new(product.price).to_s
|
||||
|
||||
- if paginated_products.respond_to?(:num_pages)
|
||||
- params.delete(:search)
|
||||
|
||||
16876
db/suburb_seeds.rb
16876
db/suburb_seeds.rb
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user