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 9e7bf2b..9b2a0fa 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb @@ -4,8 +4,7 @@ class ShoppingCartPluginMyprofileController < MyProfileController def edit if request.post? begin - profile.shopping_cart = params[:shopping_cart] == '1' ? true : false - profile.save! + profile.update_attributes!(params[:profile_attr]) session[:notice] = _('Option updated successfully.') rescue Exception => exception session[:notice] = _('Option wasn\'t updated successfully.') diff --git a/plugins/shopping_cart/db/migrate/20110513112133_add_shopping_cart_delivery_to_profile.rb b/plugins/shopping_cart/db/migrate/20110513112133_add_shopping_cart_delivery_to_profile.rb new file mode 100644 index 0000000..b123733 --- /dev/null +++ b/plugins/shopping_cart/db/migrate/20110513112133_add_shopping_cart_delivery_to_profile.rb @@ -0,0 +1,12 @@ +class AddShoppingCartDeliveryToProfile < ActiveRecord::Migration + + def self.up + add_column :profiles, :shopping_cart_delivery, :boolean, :default => false + add_column :profiles, :shopping_cart_delivery_price, :decimal, :default => 0 + end + + def self.down + remove_column :profiles, :shopping_cart_delivery + remove_column :profiles, :shopping_cart_delivery_price + end +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 2ece9c7..59a66d4 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb @@ -15,8 +15,20 @@ module ShoppingCartPlugin::CartHelper float_to_currency_cart(items.map { |id, quantity| sell_price(Product.find(id)) * quantity}.sum, environment) end - def items_table(items, environment, by_mail = false) - ' _('Delivery'), :price => profile.shopping_cart_delivery_price, :product_category => ProductCategory.last) + items << [delivery.id, 1] + end + + quantity_opts = { :class => 'cart-table-quantity' } + quantity_opts.merge!({:align => 'center'}) if by_mail + price_opts = {:class => 'cart-table-price'} + price_opts.merge!({:align => 'right'}) if by_mail + + table = '
' + content_tag('tr', @@ -26,18 +38,19 @@ module ShoppingCartPlugin::CartHelper ) + items.map do |id, quantity| product = Product.find(id) - quantity_opts = { :class => 'cart-table-quantity' } - quantity_opts.merge!({:align => 'center'}) if by_mail - price_opts = {:class => 'cart-table-price'} - price_opts.merge!({:align => 'right'}) if by_mail content_tag('tr', content_tag('td', product.name) + content_tag('td', quantity, quantity_opts ) + content_tag('td', get_price(product, environment), price_opts ) ) - end.join("\n") + + end.join("\n") + + total = get_total(items, environment) + delivery.destroy if profile.shopping_cart_delivery + + table + content_tag('th', _('Total:'), :colspan => 2, :class => 'cart-table-total-label') + - content_tag('th', get_total(items, environment), :class => 'cart-table-total-value') + + content_tag('th', total, :class => 'cart-table-total-value') + '
' end diff --git a/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb b/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb index c882bbd..cdb3da2 100644 --- a/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb +++ b/plugins/shopping_cart/test/functional/shopping_cart_plugin_myprofile_controller_test.rb @@ -20,7 +20,7 @@ class ShoppingCartPluginMyprofileControllerTest < Test::Unit::TestCase should 'be able to enable shopping cart' do enterprise.shopping_cart = false enterprise.save - post :edit, :profile => enterprise.identifier, :shopping_cart => '1' + post :edit, :profile => enterprise.identifier, :profile_attr => {:shopping_cart => '1'} enterprise.reload assert enterprise.shopping_cart @@ -29,9 +29,34 @@ class ShoppingCartPluginMyprofileControllerTest < Test::Unit::TestCase should 'be able to disable shopping cart' do enterprise.shopping_cart = true enterprise.save - post :edit, :profile => enterprise.identifier, :shopping_cart => '0' + post :edit, :profile => enterprise.identifier, :profile_attr => {:shopping_cart => '0'} enterprise.reload assert !enterprise.shopping_cart end + + should 'be able to enable shopping cart delivery' do + enterprise.shopping_cart_delivery = false + enterprise.save + post :edit, :profile => enterprise.identifier, :profile_attr => {:shopping_cart_delivery => '1'} + enterprise.reload + + assert enterprise.shopping_cart_delivery + end + + should 'be able to disable shopping cart delivery' do + enterprise.shopping_cart_delivery = true + enterprise.save + post :edit, :profile => enterprise.identifier, :profile_attr => {:shopping_cart_delivery => '0'} + enterprise.reload + + assert !enterprise.shopping_cart_delivery + end + + should 'be able to choose the delivery price' do + price = 4.35 + post :edit, :profile => enterprise.identifier, :profile_attr => {:shopping_cart_delivery_price => price} + enterprise.reload + assert enterprise.shopping_cart_delivery_price == price + end end diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb index 1fd7e9b..e462f34 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/customer_notification.html.erb @@ -21,7 +21,7 @@

<%=_('Here are the products you bought:')%>

- <%= items_table(@items, @environment, true) %> + <%= items_table(@items, @supplier, true) %>

--
diff --git a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb index 13cb3f8..5464470 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin/mailer/supplier_notification.html.erb @@ -21,7 +21,7 @@

<%=_('And here are the items bought by this customer:')%>

- <%= items_table(@items, @environment, true) %> + <%= items_table(@items, @supplier, true) %>

--
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 index a9f124c..687455f 100644 --- a/plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb +++ b/plugins/shopping_cart/views/shopping_cart_plugin_myprofile/edit.html.erb @@ -1,8 +1,10 @@

<%= _('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) %> +<% form_for(:profile_attr, profile, :url => {:action => 'edit'}, :html => {:method => 'post'}) do |f| %> +<%# form_tag :action => 'edit' do %> + <%= labelled_form_field(_('Enabled?'), f.check_box(:shopping_cart)) %> + <%= labelled_form_field(_('Delivery?'), f.check_box(:shopping_cart_delivery)) %> + <%= labelled_form_field(_('Delivery price:'), f.text_field(:shopping_cart_delivery_price)) %>

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 3519a02..7e2f146 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 @@ -3,22 +3,21 @@ <% form_for(:customer, person, :url => {:action => 'send_request'}, :html => {:onsubmit => "return Cart.send_request(this)", :id => 'cart-request-form' }) do |f| %>
- <%= labelled_form_field('* ' + _("Full name"), f.text_field(:name, :class => 'required') ) %> + <%= labelled_form_field('* ' + _("Name"), f.text_field(:name, :class => 'required') ) %> <%= labelled_form_field('* ' + _("Email"), f.text_field(:email, :class => 'required email') ) %> - <%= labelled_form_field('* ' + _("Phone number"), f.text_field(:contact_phone, :class => 'required') ) %> + <%= labelled_form_field('* ' + _("Contact phone"), f.text_field(:contact_phone, :class => 'required') ) %>
<%=_('Delivery Address')%> <%= labelled_form_field(_('Address (street and number)'), f.text_field(:address)) %> <%= labelled_form_field( _("City"), f.text_field(:city)) %> <%= labelled_form_field( _("State"), f.text_field(:state)) %> - <%= select_country(_('Country'), :customer, :country, {:class => 'type-select'}, {:selected => person.country}) %> <%= labelled_form_field(_('ZIP code'), f.text_field(:zip_code)) %>
<%= submit_button(:send, _('Send buy request')) %>
<% end %> - <%= items_table(session[:cart][:items], @environment) %> + <%= items_table(session[:cart][:items], profile) %>