diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb index de7ce05..96ea956 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb @@ -8,6 +8,7 @@ class ShoppingCartPluginMyprofileController < MyProfileController params[:settings][:enabled] = params[:settings][:enabled] == '1' params[:settings][:delivery] = params[:settings][:delivery] == '1' params[:settings][:delivery_price] = params[:settings][:delivery_price].to_d + params[:settings][:free_delivery_price] = params[:settings][:free_delivery_price].to_d end @settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin, params[:settings]) diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb index b465465..b8f94c1 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb @@ -85,6 +85,7 @@ class ShoppingCartPluginProfileController < ProfileController def buy @environment = profile.environment + @settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) render :layout => false end diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb index d847b25..aacbf8b 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb @@ -8,22 +8,26 @@ module ShoppingCartPlugin::CartHelper end def get_price(product, environment, quantity=1) - float_to_currency_cart(sell_price(product)*quantity, environment) + float_to_currency_cart(price_with_quantity(product,quantity), environment) end - def get_total(items, environment) - float_to_currency_cart(items.map { |id, quantity| sell_price(Product.find(id)) * quantity}.sum, environment) + def price_with_quantity(product, quantity=1) + quantity = 1 if !quantity.kind_of?(Numeric) + sell_price(product)*quantity + end + + def get_total(items) + items.map { |id, quantity| price_with_quantity(Product.find(id),quantity)}.sum + end + + def get_total_on_currency(items, environment) + float_to_currency_cart(get_total(items), environment) end def items_table(items, profile, by_mail = false) environment = profile.environment settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin) items = items.to_a - if settings.delivery - delivery = Product.new(:name => _('Delivery'), :price => settings.delivery_price) - delivery.save(false) - items << [delivery.id, 1] - end quantity_opts = { :class => 'cart-table-quantity' } quantity_opts.merge!({:align => 'center'}) if by_mail @@ -31,6 +35,16 @@ module ShoppingCartPlugin::CartHelper price_opts.merge!({:align => 'right'}) if by_mail items.sort! {|a, b| Product.find(a.first).name <=> Product.find(b.first).name} + if settings.delivery + if settings.free_delivery_price && get_total(items) >= settings.free_delivery_price + delivery = Product.new(:name => _('Free delivery'), :price => 0) + else + delivery = Product.new(:name => _('Delivery'), :price => settings.delivery_price) + end + delivery.save(false) + items << [delivery.id, ''] + end + table = '