Commit 68bb08169b9b1b0783a21cc29d1924ea48ca1eb4
1 parent
37b51655
Exists in
master
and in
29 other branches
Only display add button to available products
Showing
2 changed files
with
9 additions
and
1 deletions
Show diff stats
plugins/shopping_cart/lib/shopping_cart_plugin.rb
@@ -9,7 +9,7 @@ class ShoppingCartPlugin < Noosfero::Plugin | @@ -9,7 +9,7 @@ class ShoppingCartPlugin < Noosfero::Plugin | ||
9 | end | 9 | end |
10 | 10 | ||
11 | def add_to_cart_button(item, enterprise = context.profile) | 11 | def add_to_cart_button(item, enterprise = context.profile) |
12 | - if enterprise.shopping_cart | 12 | + if enterprise.shopping_cart && item.available |
13 | lambda { | 13 | lambda { |
14 | link_to(_('Add to cart'), "add:#{item.name}", | 14 | link_to(_('Add to cart'), "add:#{item.name}", |
15 | :class => 'cart-add-item', | 15 | :class => 'cart-add-item', |
plugins/shopping_cart/test/unit/shopping_cart_plugin_test.rb
@@ -19,4 +19,12 @@ class ShoppingCartPluginTest < Test::Unit::TestCase | @@ -19,4 +19,12 @@ class ShoppingCartPluginTest < Test::Unit::TestCase | ||
19 | assert shopping_cart.stylesheet? | 19 | assert shopping_cart.stylesheet? |
20 | end | 20 | end |
21 | 21 | ||
22 | + should 'not add button if product unavailable' do | ||
23 | + product = fast_create(Product, :available => false) | ||
24 | + enterprise = mock() | ||
25 | + enterprise.stubs(:shopping_cart).returns(true) | ||
26 | + | ||
27 | + assert_nil shopping_cart.add_to_cart_button(product, enterprise) | ||
28 | + end | ||
29 | + | ||
22 | end | 30 | end |