Commit 518c0ef7ffc8dd26ba01c6f47f0fcb30a6a2c178
1 parent
a05fc595
Exists in
staging
and in
42 other branches
[purchase-order] Registering order on checkout
Co-authored-by: Aurélio A. Heckert <aurelio@colivre.coop.br> (ActionItem2062)
Showing
2 changed files
with
38 additions
and
0 deletions
Show diff stats
plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb
| ... | ... | @@ -89,6 +89,7 @@ class ShoppingCartPluginProfileController < ProfileController |
| 89 | 89 | end |
| 90 | 90 | |
| 91 | 91 | def send_request |
| 92 | + register_order(params[:customer], session[:cart][:items]) | |
| 92 | 93 | begin |
| 93 | 94 | ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], profile, session[:cart][:items]) |
| 94 | 95 | ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], profile, session[:cart][:items]) |
| ... | ... | @@ -223,4 +224,22 @@ class ShoppingCartPluginProfileController < ProfileController |
| 223 | 224 | end |
| 224 | 225 | true |
| 225 | 226 | end |
| 227 | + | |
| 228 | + def register_order(custumer, items) | |
| 229 | + items.each do |id, quantity| | |
| 230 | + items[id] = {:quantity => quantity, :price => Product.find(id).price} | |
| 231 | + end | |
| 232 | + ShoppingCartPlugin::PurchaseOrder.create!( | |
| 233 | + :seller => profile, | |
| 234 | + :customer => user, | |
| 235 | + :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, | |
| 236 | + :products_list => items, | |
| 237 | + :customer_name => params[:customer][:name], | |
| 238 | + :customer_email => params[:customer][:email], | |
| 239 | + :customer_contact_phone => params[:customer][:contact_phone], | |
| 240 | + :customer_address => params[:customer][:address], | |
| 241 | + :customer_city => params[:customer][:city], | |
| 242 | + :customer_zip_code => params[:customer][:zip_code] | |
| 243 | + ) | |
| 244 | + end | |
| 226 | 245 | end | ... | ... |
plugins/shopping_cart/test/functional/shopping_cart_plugin_profile_controller_test.rb
| ... | ... | @@ -144,6 +144,25 @@ class ShoppingCartPluginProfileControllerTest < Test::Unit::TestCase |
| 144 | 144 | assert_nothing_raised { get :clean, :profile => enterprise.identifier } |
| 145 | 145 | end |
| 146 | 146 | |
| 147 | + should 'register order on send request' do | |
| 148 | + product1 = fast_create(Product, :enterprise_id => enterprise.id, :price => 1.99) | |
| 149 | + product2 = fast_create(Product, :enterprise_id => enterprise.id, :price => 2.23) | |
| 150 | + @controller.stubs(:session).returns({:cart => {:items => {product1.id => 1, product2.id => 2}}}) | |
| 151 | + assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do | |
| 152 | + post :send_request, | |
| 153 | + :customer => {:name => "Manuel", :email => "manuel@ceu.com"}, | |
| 154 | + :profile => enterprise.identifier | |
| 155 | + end | |
| 156 | + | |
| 157 | + order = ShoppingCartPlugin::PurchaseOrder.last | |
| 158 | + | |
| 159 | + assert_equal 1.99, order.products_list[product1.id][:price] | |
| 160 | + assert_equal 1, order.products_list[product1.id][:quantity] | |
| 161 | + assert_equal 2.23, order.products_list[product2.id][:price] | |
| 162 | + assert_equal 2, order.products_list[product2.id][:quantity] | |
| 163 | + assert_equal ShoppingCartPlugin::PurchaseOrder::Status::OPENED, order.status | |
| 164 | + end | |
| 165 | + | |
| 147 | 166 | private |
| 148 | 167 | |
| 149 | 168 | def json_response | ... | ... |