Commit 39215aac24eb73b824eb0928ff999008ff2a7953

Authored by Braulio Bhavamitra
2 parents 53c76729 13583f20

Merge branch 'shopping_cart_bugs' into 'master'

Shopping cart bugs

Same of #601, but against master.

See merge request !606
plugins/shopping_cart/lib/shopping_cart_plugin.rb
1 1 class ShoppingCartPlugin < Noosfero::Plugin
  2 + include ModalHelper
  3 + include ActionView::Helpers::UrlHelper
2 4  
3 5 class << self
4 6 def plugin_name
... ... @@ -63,4 +65,8 @@ class ShoppingCartPlugin &lt; Noosfero::Plugin
63 65  
64 66 buttons
65 67 end
  68 +
  69 + def controller
  70 + context
  71 + end
66 72 end
... ...
plugins/shopping_cart/lib/shopping_cart_plugin/cart_helper.rb
... ... @@ -42,7 +42,7 @@ module ShoppingCartPlugin::CartHelper
42 42 else
43 43 delivery = Product.new(:name => delivery_option || _('Delivery'), :price => settings.delivery_options[delivery_option])
44 44 end
45   - delivery.save(false)
  45 + delivery.save(validate: false)
46 46 items << [delivery.id, '']
47 47 end
48 48  
... ...
plugins/shopping_cart/test/unit/shopping_cart_plugin/cart_helper_test.rb
... ... @@ -41,5 +41,19 @@ class ShoppingCartPlugin::CartHelperTest &lt; ActiveSupport::TestCase
41 41 assert_equal "#{environment.currency_unit}13#{environment.currency_separator}70", float_to_currency_cart(value,environment)
42 42 end
43 43  
44   -end
  44 + should 'return a table of items' do
  45 + enterprise = Enterprise.new(name: "Test Enterprise", identifier: "test-enterprise")
  46 + enterprise.environment = Environment.default
  47 + enterprise.save!
  48 +
  49 + product_category = fast_create(ProductCategory, :name => 'Products')
  50 + product = fast_create(Product, :name => 'test product1', :product_category_id => product_category.id, :profile_id => enterprise.id)
  51 + setting = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin)
  52 + setting.delivery = true
  53 + setting.save!
  54 +
  55 + assert_match 'table id="cart-items-table"', items_table([product], enterprise)
  56 + assert_match '<td>test product1</td>', items_table([product], enterprise)
  57 + end
45 58  
  59 +end
... ...
plugins/shopping_cart/views/cart.html.erb
... ... @@ -5,7 +5,7 @@
5 5 <a href="cart:clean" onclick="Cart.clean(this); return false" class="cart-clean"><%=_('Clean basket')%></a>
6 6 <ul class="cart-items"></ul>
7 7 <div class="cart-total"><%=_('Total:')%> <b></b></div>
8   - <a href="/plugin/shopping_cart/buy" class="cart-buy modal"><%=_('Shopping checkout')%></a>
  8 + <%= modal_link_to _('Shopping checkout'), { controller: 'shopping_cart_plugin', action: 'buy' }, { class: "cart-buy modal" } %>
9 9 </div>
10 10 <a href="#" onclick="Cart.toggle(this); return false" class="cart-toggle">
11 11 <span class="str-show"><%=_('Show basket')%></span>
... ...
plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb
... ... @@ -24,7 +24,6 @@
24 24 <% end %>
25 25 <% delivery_option = @settings.delivery_options.first && @settings.delivery_options.first.first %>
26 26 <%= items_table(@cart[:items], @profile, delivery_option) %>
27   - <%= link_to_function '', "noosfero.modal.close();", :class => 'cart-box-close icon-cancel' %>
28 27 </div>
29 28  
30 29 <%= javascript_include_tag '../plugins/shopping_cart/buy' %>
... ...
plugins/shopping_cart/views/shopping_cart_plugin_profile/buy.html.erb
... ... @@ -17,7 +17,6 @@
17 17 </div>
18 18 <% end %>
19 19 <%= items_table(session[:cart][:items], profile) %>
20   - <%= link_to_function '', "noosfero.modal.close();", :class => 'cart-box-close icon-cancel' %>
21 20 </div>
22 21  
23 22 <script type="text/javascript">
... ...