疯狂结帐-删除步骤 [英] Spree Checkout - Remove Step

查看:65
本文介绍了疯狂结帐-删除步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除2个结帐步骤。
我试图遵循网站 http://guides.spreecommerce.com/checkout上的文档.html
,但仍然没有任何反应。

I am trying to remove 2 checkout steps. I have tried to follow the documentation in the site http://guides.spreecommerce.com/checkout.html but still nothing happens.

我正在使用
Spree 1.1.2
ruby​​ 1.9.2p318
Rails 3.2.6
Ubuntu 12.04(精确)32位

I am using Spree 1.1.2 ruby 1.9.2p318 Rails 3.2.6 Ubuntu 12.04 (precise) 32-bit

我会告诉您我做了什么,您会告诉我要解决的问题。
我应该更改文件的名称或位置吗?
还是我也应该更改其他文件?
如何调试?

I'll tell you what I have done and you will tell me what to fix. Should I change the name or location of the file? Or should I change other files too? How can I debug it?

我创建了一个新文件 app / models / spree / order_decorator.rb(也在 app / models / order_decorator.rb)

I have created a new file "app/models/spree/order_decorator.rb" (also tried it under "app/models/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






然后我尝试了相同的方法文件使用不同的代码,仍然没有任何反应


Then I tried the same file with different code, still nothing happened

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 






推荐答案

好的,所以我终于找到了它-

Spree发布了新版本#1.2.0,其中包含针对此确切问题的主要修复程序。

OK, so I have finally found it -
Spree have released a new version #1.2.0 with a major fix for this exact problem.

Spree 1.2.0发行说明


很难在Spree中进行自定义,这在过去曾引起过抱怨。我们很高兴在Spree的1.2版本中报告说,此操作从本质上来说更容易...

The checkout process has always been hard to customize within Spree, and that has generated complaints in the past. We are pleased to report in the 1.2 release of Spree that this has been substaintially easier...

因此,现在的解决方案很容易-

只需撤消之前所有的结帐操作尝试,通过更新gem文件和捆绑安装,

升级到1.2.0,
处理通过遵循他们的文档进行所有代码分解(我想您会发现一些)。

并在app / models / spree /

So the solution now is quit easy -
Just undo all your previous checkout manipulation attempts,
upgrade spree to 1.2.0 by updating your gem file and bundle install,
handle all your code breakups by following their documentation (I guess you'll have some).
and create a simple order_decorator.rb under app/models/spree/

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

享受。

这篇关于疯狂结帐-删除步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆