diff --git a/plugins/shopping_cart/20110422151030_add_shopping_cart_to_profile.rb b/plugins/shopping_cart/20110422151030_add_shopping_cart_to_profile.rb new file mode 100644 index 0000000..c5c8f17 --- /dev/null +++ b/plugins/shopping_cart/20110422151030_add_shopping_cart_to_profile.rb @@ -0,0 +1,10 @@ +class AddShoppingCartToProfile < ActiveRecord::Migration + + def self.up + add_column :profiles, :shopping_cart, :boolean, :default => true + end + + def self.down + remove_column :profiles, :shopping_cart + end +end diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb new file mode 100644 index 0000000..9e7bf2b --- /dev/null +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb @@ -0,0 +1,17 @@ +class ShoppingCartPluginMyprofileController < MyProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + def edit + if request.post? + begin + profile.shopping_cart = params[:shopping_cart] == '1' ? true : false + profile.save! + session[:notice] = _('Option updated successfully.') + rescue Exception => exception + session[:notice] = _('Option wasn\'t updated successfully.') + end + redirect_to :action => 'edit' + end + end + +end diff --git a/plugins/shopping_cart/db/migrate/20110422151030_add_shopping_cart_to_profile.rb b/plugins/shopping_cart/db/migrate/20110422151030_add_shopping_cart_to_profile.rb new file mode 100644 index 0000000..c5c8f17 --- /dev/null +++ b/plugins/shopping_cart/db/migrate/20110422151030_add_shopping_cart_to_profile.rb @@ -0,0 +1,10 @@ +class AddShoppingCartToProfile < ActiveRecord::Migration + + def self.up + add_column :profiles, :shopping_cart, :boolean, :default => true + end + + def self.down + remove_column :profiles, :shopping_cart + end +end diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin.rb b/plugins/shopping_cart/lib/shopping_cart_plugin.rb index 83ec854..1636b20 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin.rb @@ -9,12 +9,14 @@ class ShoppingCartPlugin < Noosfero::Plugin end def add_to_cart_button(item) - lambda { - link_to(_('Add to cart'), "add:#{item.name}", - :class => 'cart-add-item', - :onclick => "Cart.addItem('#{profile.identifier}', #{item.id}, this); return false" - ) - } + if context.profile.shopping_cart + lambda { + link_to(_('Add to cart'), "add:#{item.name}", + :class => 'cart-add-item', + :onclick => "Cart.addItem('#{profile.identifier}', #{item.id}, this); return false" + ) + } + end end alias :product_info_extras :add_to_cart_button @@ -32,4 +34,10 @@ class ShoppingCartPlugin < Noosfero::Plugin expanded_template('cart.html.erb',{:cart => context.session[:cart]}) end + def control_panel_buttons + if context.profile.enterprise? + { :title => 'Shopping cart', :icon => 'shopping_cart_icon', :url => {:controller => 'shopping_cart_plugin_myprofile', :action => 'edit'} } + end + end + end diff --git a/plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb new file mode 100644 index 0000000..a9f124c --- /dev/null +++ b/plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb @@ -0,0 +1,12 @@ +

<%= _('Cart options') %>

+ +<%# form_for :profile, profile, :url => {:action => 'edit'} do %> +<% form_tag :action => 'edit' do %> + <%= labelled_check_box(_('Enabled?'), :shopping_cart, '1', profile.shopping_cart) %> +
+
+
+ <%= submit_button(:save, _('Save')) %> + <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> +
+<% end%> -- libgit2 0.21.2