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 60b9567..e34816f 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb @@ -4,12 +4,7 @@ class ShoppingCartPluginMyprofileController < MyProfileController append_view_path File.join(File.dirname(__FILE__) + '/../views') def edit - if params[:settings] - params[:settings][:enabled] = params[:settings][:enabled] == '1' - params[:settings][:delivery] = params[:settings][:delivery] == '1' - params[:settings][:free_delivery_price] = params[:settings][:free_delivery_price].to_d - params[:settings][:delivery_options] = treat_delivery_options(params[:settings][:delivery_options]) - end + params[:settings] = treat_cart_options(params[:settings]) @settings = Noosfero::Plugin::Settings.new(profile, ShoppingCartPlugin, params[:settings]) if request.post? @@ -57,6 +52,15 @@ class ShoppingCartPluginMyprofileController < MyProfileController private + def treat_cart_options(settings) + return if settings.blank? + settings[:enabled] = settings[:enabled] == '1' + settings[:delivery] = settings[:delivery] == '1' + settings[:free_delivery_price] = settings[:free_delivery_price].blank? ? nil : settings[:free_delivery_price].to_d + settings[:delivery_options] = treat_delivery_options(settings[:delivery_options]) + settings + end + def treat_delivery_options(params) result = {} params[:options].size.times do |counter| 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 fa8ada7..8304d35 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb @@ -39,7 +39,7 @@ module ShoppingCartPlugin::CartHelper 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_option, :price => settings.delivery_options[delivery_option]) + delivery = Product.new(:name => delivery_option || _('Delivery'), :price => settings.delivery_options[delivery_option]) end delivery.save(false) items << [delivery.id, ''] @@ -82,8 +82,10 @@ module ShoppingCartPlugin::CartHelper end def select_delivery_options(options, environment) - options.map do |option, price| + result = options.map do |option, price| ["#{option} (#{float_to_currency_cart(price, environment)})", option] end + result << ["#{_('Delivery')} (#{float_to_currency_cart(0, environment)})", 'delivery'] if result.empty? + result end end diff --git a/plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb index c37c2ce..1f3eaaa 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb @@ -6,7 +6,7 @@ <%= labelled_form_field('* ' + _("Name"), f.text_field(:name, :class => 'required') ) %> <%= labelled_form_field('* ' + _("Email"), f.text_field(:email, :class => 'required email') ) %> <%= labelled_form_field('* ' + _("Contact phone"), f.text_field(:contact_phone, :class => 'required') ) %> - <%= labelled_form_field(_('Delivery option'), select_tag(:delivery_option, options_for_select(select_delivery_options(@settings.delivery_options, environment)), 'data-profile-identifier' => profile.identifier)) if @settings.delivery && @settings.free_delivery_price && get_total(session[:cart][:items]) < @settings.free_delivery_price %> + <%= labelled_form_field(_('Delivery option'), select_tag(:delivery_option, options_for_select(select_delivery_options(@settings.delivery_options, environment)), 'data-profile-identifier' => profile.identifier)) unless !@settings.delivery || (@settings.free_delivery_price && get_total(session[:cart][:items]) >= @settings.free_delivery_price) %> <% if @settings.delivery %>