Commit 5d2b389563e1a97e829dae420ee6b791604d6e73

Authored by Rodrigo Souto
1 parent f2de5935

Profile cart control panel

* Feature:
    - Possibility to enable and disable "Add to cart" buttons
    - Also possibility to further configurations of cart on the profile.
plugins/shopping_cart/20110422151030_add_shopping_cart_to_profile.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class AddShoppingCartToProfile < ActiveRecord::Migration
  2 +
  3 + def self.up
  4 + add_column :profiles, :shopping_cart, :boolean, :default => true
  5 + end
  6 +
  7 + def self.down
  8 + remove_column :profiles, :shopping_cart
  9 + end
  10 +end
... ...
plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class ShoppingCartPluginMyprofileController < MyProfileController
  2 + append_view_path File.join(File.dirname(__FILE__) + '/../views')
  3 +
  4 + def edit
  5 + if request.post?
  6 + begin
  7 + profile.shopping_cart = params[:shopping_cart] == '1' ? true : false
  8 + profile.save!
  9 + session[:notice] = _('Option updated successfully.')
  10 + rescue Exception => exception
  11 + session[:notice] = _('Option wasn\'t updated successfully.')
  12 + end
  13 + redirect_to :action => 'edit'
  14 + end
  15 + end
  16 +
  17 +end
... ...
plugins/shopping_cart/db/migrate/20110422151030_add_shopping_cart_to_profile.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class AddShoppingCartToProfile < ActiveRecord::Migration
  2 +
  3 + def self.up
  4 + add_column :profiles, :shopping_cart, :boolean, :default => true
  5 + end
  6 +
  7 + def self.down
  8 + remove_column :profiles, :shopping_cart
  9 + end
  10 +end
... ...
plugins/shopping_cart/lib/shopping_cart_plugin.rb
... ... @@ -9,12 +9,14 @@ class ShoppingCartPlugin &lt; Noosfero::Plugin
9 9 end
10 10  
11 11 def add_to_cart_button(item)
12   - lambda {
13   - link_to(_('Add to cart'), "add:#{item.name}",
14   - :class => 'cart-add-item',
15   - :onclick => "Cart.addItem('#{profile.identifier}', #{item.id}, this); return false"
16   - )
17   - }
  12 + if context.profile.shopping_cart
  13 + lambda {
  14 + link_to(_('Add to cart'), "add:#{item.name}",
  15 + :class => 'cart-add-item',
  16 + :onclick => "Cart.addItem('#{profile.identifier}', #{item.id}, this); return false"
  17 + )
  18 + }
  19 + end
18 20 end
19 21  
20 22 alias :product_info_extras :add_to_cart_button
... ... @@ -32,4 +34,10 @@ class ShoppingCartPlugin &lt; Noosfero::Plugin
32 34 expanded_template('cart.html.erb',{:cart => context.session[:cart]})
33 35 end
34 36  
  37 + def control_panel_buttons
  38 + if context.profile.enterprise?
  39 + { :title => 'Shopping cart', :icon => 'shopping_cart_icon', :url => {:controller => 'shopping_cart_plugin_myprofile', :action => 'edit'} }
  40 + end
  41 + end
  42 +
35 43 end
... ...
plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<h1> <%= _('Cart options') %> </h1>
  2 +
  3 +<%# form_for :profile, profile, :url => {:action => 'edit'} do %>
  4 +<% form_tag :action => 'edit' do %>
  5 + <%= labelled_check_box(_('Enabled?'), :shopping_cart, '1', profile.shopping_cart) %>
  6 + <br style='clear: both'/>
  7 + <br style='clear: both'/>
  8 + <div>
  9 + <%= submit_button(:save, _('Save')) %>
  10 + <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %>
  11 + </div>
  12 +<% end%>
... ...