2012-07-12 111 views
3

我試圖刪除2個結帳步驟。 我試圖按照網站http://guides.spreecommerce.com/checkout.html 中的文檔,但仍然沒有任何反應。Spree結賬 - 刪除步驟

我使用 施普雷1.1.2 紅寶石1.9.2p318 的Rails 3.2.6 的Ubuntu 12.04(精確)32位

我會告訴你我做了什麼,你會告訴我什麼修理。 我應該更改文件的名稱或位置嗎? 還是應該更換其他文件? 我該如何調試它?

我創建了一個新的文件 「應用程序/模型/大禮包/ order_decorator.rb」(也嘗試過 「應用程序/模型/ order_decorator.rb」 下)

module SpreeCustomExtension 

    class Engine < Rails::Engine 

    def self.activate 

     Spree::Order.class_eval do 



     StateMachine::Machine.ignore_method_conflicts = true # I HAVE ADDED THOSE 2 LINES LATER, HOPING IT WOULD HELP ME, 

     Spree::Order.state_machines.clear        # IT DIDN'T. 



     # customize the checkout state machine 

     Order.state_machines[:state] = StateMachine::Machine.new(Order, :initial => 'cart') do 

      after_transition :to => 'complete', :do => :complete_order 

      before_transition :to => 'complete', :do => :process_payment 

      event :next do 

      transition :from => 'cart', :to => 'payment' 

      transition :from => 'payment', :to => 'complete' 

      end 



      event :cancel do 

      transition :to => 'canceled', :if => :allow_cancel? 

      end 

      event :return do 

      transition :to => 'returned', :from => 'awaiting_return' 

      end 

      event :resume do 

      transition :to => 'resumed', :from => 'canceled', :if => :allow_resume? 

      end 

      event :authorize_return do 

      transition :to => 'awaiting_return' 

      end 



      before_transition :to => 'complete' do |order| 

      begin 

       order.process_payments! 

      rescue Core::GatewayError 

       !!Spree::Config[:allow_checkout_on_gateway_error] 

      end 

      end 



      before_transition :to => ['delivery'] do |order| 

      order.shipments.each { |s| s.destroy unless s.shipping_method.available_to_order?(order) } 

      end 



      after_transition :to => 'complete', :do => :finalize! 

      after_transition :to => 'delivery', :do => :create_tax_charge! 

      after_transition :to => 'payment', :do => :create_shipment! 

      after_transition :to => 'resumed', :do => :after_resume 

      after_transition :to => 'canceled', :do => :after_cancel 

     end 



     end 

    end 

    end 

end 

然後我嘗試了不同的代碼相同的文件,仍然沒有動靜


Spree::Order.class_eval do 



    StateMachine::Machine.ignore_method_conflicts = true 

    Spree::Order.state_machines.clear 



    state_machine :initial => 'cart', :use_transactions => false do 



    event :next do 

     transition :from => 'cart',  :to => 'payment', :if => :payment_required? 

     transition :from => 'cart',  :to => 'complete' 

     transition :from => 'confirm', :to => 'complete' 



     # note: some payment methods will not support a confirm step 

     transition :from => 'payment', :to => 'confirm', 

             :if => Proc.new { |order| order.payment_method && order.payment_method.payment_profiles_supported? } 



     transition :from => 'payment', :to => 'complete' 

    end 



    event :cancel do 

     transition :to => 'canceled', :if => :allow_cancel? 

    end 

    event :return do 

     transition :to => 'returned', :from => 'awaiting_return' 

    end 

    event :resume do 

     transition :to => 'resumed', :from => 'canceled', :if => :allow_resume? 

    end 

    event :authorize_return do 

     transition :to => 'awaiting_return' 

    end 



    before_transition :to => 'complete' do |order| 

     begin 

     order.process_payments! 

     rescue Core::GatewayError 

     if Spree::Config[:allow_checkout_on_gateway_error] 

      true 

     else 

      false 

     end 

     end 

    end 



    before_transition :to => ['delivery'] do |order| 

     order.shipments.each { |s| s.destroy unless s.shipping_method.available_to_order?(order) } 

    end 



    after_transition :to => 'complete', :do => :finalize! 

    after_transition :to => 'delivery', :do => :create_tax_charge! 

    after_transition :to => 'payment', :do => :create_shipment! 

    after_transition :to => 'resumed', :do => :after_resume 

    after_transition :to => 'canceled', :do => :after_cancel 



    end 



end 

+0

我有類似的問題。我發現,當我試圖繼續進程時,步驟實際上被刪除,所以問題出現在另一個地方。在調試時,我發現CheckoutController處理'/ checkout',並且有以下參數:{「state」=>「address」}我不知道參數是如何到達的,但我認爲這是問題所在。 – 2012-07-17 21:49:01

+1

好的...我發現了其他東西...問題是routes.rb中的以下行: match'/ checkout',:to =>'checkout#edit',:state =>'address',: as =>:結賬 – 2012-07-17 21:59:24

回答

14

好的,所以我終於找到了它 -
Spree已經發布了一個新版本#1.2.0,並針對這個確切問題進行了主要修復。

Spree 1.2.0 Release Notes

結帳過程中一直難以大禮包內定製,並已經產生,在過去的投訴。我們很高興在狂歡的1.2版本,這已經substaintially容易報表...

因此,解決辦法現在很容易退出 -
只要撤銷先前所有的結賬作案企圖,
升級大禮包1.2.0通過更新您的gem文件和軟件包安裝,
通過遵循他們的文檔(我想你會有一些)來處理你所有的代碼分解。
創造下的應用程序/模型/大禮包一個簡單的order_decorator.rb/

Spree::Order.class_eval do 
    checkout_flow do 
    go_to_state :address 
    go_to_state :payment, :if => lambda { |order| order.payment_required? } 
    go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } 
    go_to_state :complete 
    end 

    # If true, causes the payment step to happen during the checkout process 
    def payment_required? 
    return false 
    end 

    # If true, causes the confirmation step to happen during the checkout process 
    def confirmation_required? 
    return true 
    end 

end 

享受。

+0

謝謝,非常有幫助!使用瘋狂3.0.5 – 2016-02-10 16:00:30

3

我使用spree> = 2.0.0你可以使用下面的helper方法來刪除任何checkout步驟。按照下面給出的步驟。

第1步:在應用程序/模型/大禮包/創建名稱order_decorator.rb

第2步新文件:複製並粘貼下面的代碼它。

Spree::Order.class_eval do 
#replace :delivery to any other state 
remove_checkout_step :delivery 
end 

感謝狂歡社區。http://guides.spreecommerce.com/developer/

0

在施普雷默認結帳步驟

  1. 地址
  2. 交貨
  3. 付款
  4. 確認

狂歡(2.0)允許您修改結帳過程中添加或刪除步驟通過使用相應的幫手。

insert_checkout_step 
remove_checkout_step 

需要記住remove_checkout_step將一次刪除只有一個結帳步驟: