Commit 773fab23137594a571ab78b2f49fa09aba3132de

Authored by Rodrigo Souto
1 parent 82653b80

Stop using application helper

(ActionItem1970)
plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb
... ... @@ -16,7 +16,7 @@ class ShoppingCartPluginProfileController < ProfileController
16 16 :products => [{
17 17 :id => product.id,
18 18 :name => product.name,
19   - :price => get_price(product),
  19 + :price => get_price(product, profile.environment),
20 20 :description => product.description,
21 21 :picture => product.default_image(:minor),
22 22 :quantity => session[:cart][:items][product.id]
... ... @@ -44,7 +44,7 @@ class ShoppingCartPluginProfileController < ProfileController
44 44 product = Product.find(id)
45 45 { :id => product.id,
46 46 :name => product.name,
47   - :price => get_price(product),
  47 + :price => get_price(product, profile.environment),
48 48 :description => product.description,
49 49 :picture => product.default_image(:minor),
50 50 :quantity => quantity
... ... @@ -83,6 +83,7 @@ class ShoppingCartPluginProfileController < ProfileController
83 83 end
84 84  
85 85 def buy
  86 + @environment = profile.environment
86 87 render :layout => false
87 88 end
88 89  
... ...
plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb
... ... @@ -7,15 +7,15 @@ module ShoppingCartPlugin::CartHelper
7 7 product.discount ? product.price_with_discount : product.price
8 8 end
9 9  
10   - def get_price(product)
11   - float_to_currency(sell_price(product))
  10 + def get_price(product, environment)
  11 + float_to_currency_cart(sell_price(product), environment)
12 12 end
13 13  
14   - def get_total(items)
15   - float_to_currency(items.map { |id, quantity| sell_price(Product.find(id)) * quantity}.sum)
  14 + def get_total(items, environment)
  15 + float_to_currency_cart(items.map { |id, quantity| sell_price(Product.find(id)) * quantity}.sum, environment)
16 16 end
17 17  
18   - def items_table(items, by_mail = false)
  18 + def items_table(items, environment, by_mail = false)
19 19 '<table id="cart-items-table" cellpadding="2" cellspacing="0"
20 20 border="'+(by_mail ? '1' : '0')+'"
21 21 style="'+(by_mail ? 'border-collapse:collapse' : '')+'">' +
... ... @@ -33,12 +33,18 @@ module ShoppingCartPlugin::CartHelper
33 33 content_tag('tr',
34 34 content_tag('td', product.name) +
35 35 content_tag('td', quantity, quantity_opts ) +
36   - content_tag('td', get_price(product), price_opts )
  36 + content_tag('td', get_price(product, environment), price_opts )
37 37 )
38 38 end.join("\n") +
39 39 content_tag('th', _('Total:'), :colspan => 2, :class => 'cart-table-total-label') +
40   - content_tag('th', get_total(items), :class => 'cart-table-total-value') +
  40 + content_tag('th', get_total(items, environment), :class => 'cart-table-total-value') +
41 41 '</table>'
42 42 end
43 43  
  44 + private
  45 +
  46 + def float_to_currency_cart(value, environment)
  47 + number_to_currency(value, :unit => environment.currency_unit, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter, :format => "%u %n")
  48 + end
  49 +
44 50 end
... ...
plugins/shopping_cart/lib/shopping_cart_plugin/mailer.rb
1   -include ApplicationHelper
2   -
3 1 class ShoppingCartPlugin::Mailer < Noosfero::Plugin::MailerBase
4 2  
5 3 prepend_view_path(ShoppingCartPlugin.root_path+'/views')
... ...
plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb
... ... @@ -4,7 +4,6 @@
4 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5 5 </head>
6 6 <body>
7   - <% environment = @environment %>
8 7 <h4><%= _('Hi %s!') % @customer[:name] %></h4>
9 8  
10 9 <p>
... ... @@ -22,13 +21,13 @@
22 21 </ul>
23 22  
24 23 <p><%=_('Here are the products you bought:')%></p>
25   - <%= items_table(@items, true) %>
  24 + <%= items_table(@items, @environment, true) %>
26 25  
27 26 <p>
28 27 --<br/>
29 28 <%=_('Thanks for buying with us!')%><br/>
30 29 <%= link_to @supplier.name, @supplier.url %>
31 30 </p>
32   - <small style="color: #888"><%= _('A service of %s.') % environment.name %></small>
  31 + <small style="color: #888"><%= _('A service of %s.') % @environment.name %></small>
33 32 </body>
34 33 </html>
... ...
plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb
... ... @@ -4,7 +4,6 @@
4 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5 5 </head>
6 6 <body>
7   - <% environment = @environment %>
8 7 <h4><%= _('Hi %s!') % @supplier.name %></h4>
9 8  
10 9 <p>
... ... @@ -22,12 +21,12 @@
22 21 </ul>
23 22  
24 23 <p><%=_('And here are the items bought by this customer:')%></p>
25   - <%= items_table(@items, true) %>
  24 + <%= items_table(@items, @environment, true) %>
26 25  
27 26 <p>
28 27 --<br/>
29   - <%=_('If there are any problems with this email contact the admin of %s.') % environment.name %>
  28 + <%=_('If there are any problems with this email contact the admin of %s.') % @environment.name %>
30 29 </p>
31   - <small style="color: #888"><%= _('A service of %s.') % environment.name %></small>
  30 + <small style="color: #888"><%= _('A service of %s.') % @environment.name %></small>
32 31 </body>
33 32 </html>
... ...
plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb
... ... @@ -18,7 +18,7 @@
18 18 <%= submit_button(:send, _('Send buy request')) %>
19 19 </div>
20 20 <% end %>
21   - <%= items_table(session[:cart][:items]) %>
  21 + <%= items_table(session[:cart][:items], @environment) %>
22 22 </div>
23 23  
24 24 <script type="text/javascript">
... ...