ruby-on-rails – 跳过结账步骤但进行关联
我尝试修改我的CheckoutSteps.
我们的客户无法选择送货或付款,因为所有订单都是相同的. (运费为5欧元,订单超过100欧元,然后免费). 付款总是Eruopean BankTransfer(我们注意到订单中的客户 – 电子邮件). 所以我从我的订单中删除了州“:delivery”.跳过该步骤但没有对运输的分配. 我很难在Controller中自动分配它. 我看到正常的assigment是nested_attribute但我很难自己做这些关联.我试图调试控制器和模型,但我找不到正确的关联,并找到一种手动设置它们的方法. "order"=>{"shipments_attributes"=>{"0"=>{"selected_shipping_rate_id"=>"16","id"=>"20"}}}, 但我找不到任何我可以自己进行调整的代码. Spree::Order.last.shipments => [] 但是一旦我们进入“交付”页面 Spree::Order.last.shipments => #<ActiveRecord::Associations::CollectionProxy [#<Spree::Shipment id: 28,tracking: nil,number: "H43150550345",cost: #<BigDecimal:ff44afc,'0.0',9(18)>,............. 因此运费为0.0 Spree::Order.last.shipments.first.cost.to_f => 0 但是当我们在网页上选择运送方式时 Spree::Order.last.shipments.first.cost.to_f => 5.0 所以我的问题是,如何在没有user_interaction的情况下以编程方式进行此行为? 我不知道什么事情发生,文档没有帮助. //编辑 使用了一些模型函数,找到了create_proposed_shipments和shipment.update_amounts. checkout_flow do go_to_state :address #go_to_state :delivery #kicked out go_to_state :payment,if: ->(order) { order.create_proposed_shipments #create the shipping order.shipments.first.update_amounts #"accept" the shipping order.payment_required? } 解决方法
好吧,我让它运行得很好,没有碰到流动
第一: Spree::Order.class_eval do def needs_delivery? #your logic goes here return false end end 然后我们需要我们的订单本身可以选择其运输的功能 Spree::Order.class_eval do def select_default_shipping #clone_billing_address #uncomment if user just types in one address create_proposed_shipments #creates the shippings shipments.first.update_amounts #uses the first shippings update_totals #updates the order end end 下一步是劫持checkout_controller Spree::CheckoutController.class_eval do def before_delivery if @order.needs_delivery? #user needs to select shipping,default behaviour @order.create_proposed_shipments else #we select the shipping for the user @order.select_default_shipping @order.next #go to next step #default logic for finalizing unless he can't select payment_method if @order.completed? session[:order_id] = nil flash.notice = Spree.t(:order_processed_successfully) flash[:commerce_tracking] = "nothing special" redirect_to completion_route else redirect_to checkout_state_path(@order.state) end end end end 花了很多倍,希望节省别人的时间. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |