app/controllers/plugins/ecommerce/front/checkout_controller.rb in camaleon_ecommerce-1.2.1 vs app/controllers/plugins/ecommerce/front/checkout_controller.rb in camaleon_ecommerce-2.0.0

- old
+ new

@@ -32,12 +32,14 @@ errors = ecommerce_verify_cart_errors(@cart) if errors.present? flash[:cama_ecommerce][:error] = errors.join('<br>') redirect_to :back else + hooks_run('plugin_ecommerce_before_complete_free_order', @cart) @cart.set_meta('free_order', true) - mark_order_like_received(@cart) + commerce_mark_cart_received(@cart) + hooks_run('plugin_ecommerce_after_complete_free_order', @cart) redirect_to plugins_ecommerce_orders_path end else flash[:cama_ecommerce][:error] = "Invalid complete payment" redirect_to :back @@ -65,20 +67,20 @@ data = params[:cart] qty = data[:qty].to_f rescue 0 product = current_site.products.find(data[:product_id]).decorate unless product.valid_variation?(params[:variation_id]) flash[:cama_ecommerce][:error] = t('plugins.ecommerce.messages.missing_variation', default: 'Invalid Product Variation') - return redirect_to action: :cart_index + return params[:format] == 'json' ? render(json: flash.discard(:cama_ecommerce).to_hash) : (redirect_to action: :cart_index) end unless product.can_added?(qty, params[:variation_id]) - flash[:cama_ecommerce][:error] = t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(params[:variation_id]), qty: product.the_qty_real(params[:variation_id]), default: 'There is not enough products "%{product}" (Available %{qty})') - return redirect_to :back + flash[:cama_ecommerce][:error] = t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(params[:variation_id]), qty: product.the_qty(params[:variation_id]), default: 'There is not enough products "%{product}" (Available %{qty})') + return params[:format] == 'json' ? render(json: flash.discard(:cama_ecommerce).to_hash) : (redirect_to :back) end @cart.add_product(product, qty, params[:variation_id]) flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.added_product_in_cart', default: 'Product added into cart') - redirect_to action: :cart_index + params[:format] == 'json' ? render(json: flash.discard(:cama_ecommerce).to_hash) : (redirect_to action: :cart_index) end def cart_update errors = [] params[:product_items].each do |data| @@ -86,28 +88,28 @@ product = item.product.decorate qty = data[:qty].to_f if product.can_added?(qty, item.variation_id) @cart.add_product(product, qty, item.variation_id) else - errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(item.variation_id), qty: product.the_qty_real(item.variation_id), default: 'There is not enough products "%{product}" (Available %{qty})') + errors << t('plugins.ecommerce.messages.not_enough_product_qty', product: product.the_variation_title(item.variation_id), qty: product.the_qty(item.variation_id), default: 'There is not enough products "%{product}" (Available %{qty})') end end flash[:cama_ecommerce][:error] = errors.join('<br>') if errors.present? flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.cart_updated', default: 'Shopping cart updated') unless errors.present? - redirect_to action: :cart_index + params[:format] == 'json' ? render(json: flash.discard(:cama_ecommerce).to_hash) : (redirect_to action: :cart_index) end def cart_remove @cart.product_items.find(params[:product_item_id]).destroy flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.cart_deleted', default: 'Product removed from your shopping cart') - redirect_to action: :cart_index + params[:format] == 'json' ? render(json: flash.discard(:cama_ecommerce).to_hash) : (redirect_to action: :cart_index) end def cancel_order @cart.update({status: 'canceled', kind: 'order', closed_at: Time.now}) flash[:cama_ecommerce][:notice] = t('plugins.ecommerce.messages.canceled_order', default: "Canceled Order") - redirect_to plugins_ecommerce_orders_url + params[:format] == 'json' ? render(json: flash.discard(:cama_ecommerce).to_hash) : (redirect_to plugins_ecommerce_orders_url) end def pay_by_stripe result = Plugins::Ecommerce::CartService.new(current_site, @cart). pay_with_stripe(payment_method: @payment, @@ -119,24 +121,24 @@ if result[:payment_error] flash[:payment_error] = true end redirect_to :back else - mark_order_like_received(@cart) + commerce_mark_cart_received(@cart) redirect_to plugins_ecommerce_orders_url end end def pay_by_bank_transfer @cart.set_meta("payment_data", params[:details]) - mark_order_like_received(@cart, 'bank_pending') + commerce_mark_cart_received(@cart, 'bank_pending') redirect_to plugins_ecommerce_orders_url end def pay_by_on_delivery @cart.set_meta("payment_data", params[:details]) - mark_order_like_received(@cart, 'on_delivery') + commerce_mark_cart_received(@cart, 'on_delivery') redirect_to plugins_ecommerce_orders_url end def pay_by_authorize_net res = Plugins::Ecommerce::CartService.new(current_site, @cart). @@ -151,11 +153,11 @@ if res[:error].present? flash[:cama_ecommerce][:error] = res[:error] flash[:payment_error] = true redirect_to :back else - mark_order_like_received(@cart) + commerce_mark_cart_received(@cart) redirect_to plugins_ecommerce_orders_url end end def success_paypal @@ -165,18 +167,17 @@ :payer_id => params[:PayerID] }) if response.success? @cart.set_meta('payment_data', {token: params[:token], PayerID: params[:PayerID], ip: request.remote_ip}) - mark_order_like_received(@cart) + commerce_mark_cart_received(@cart) else flash[:cama_ecommerce][:error] = response.message end redirect_to plugins_ecommerce_orders_url end def cancel_paypal - # @cart = current_site.orders.find_by_slug(params[:order]) redirect_to plugins_ecommerce_orders_url end def pay_by_paypal result = Plugins::Ecommerce::CartService.new(current_site, @cart).