4

我正在尝试删除 2 个结帐步骤。我试图按照网站http://guides.spreecommerce.com/checkout.html中的文档进行操作, 但仍然没有任何反应。

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

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

我创建了一个新文件“app/models/spree/order_decorator.rb”(也在“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

然后我用不同的代码尝试了同一个文件,仍然没有发生任何事情


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 

4

4 回答 4

16

好的,所以我终于找到了
——Spree 发布了一个新版本 #1.2.0,对这个确切的问题进行了重大修复。

大礼包 1.2.0 发行说明

在 Spree 中,结账流程一直很难定制,这在过去引起了投诉。我们很高兴地在 Spree 的 1.2 版本中报告,这实际上变得更加容易......

所以现在的解决方案很简单——
只需撤消所有以前的结帐操作尝试,
通过更新 gem 文件和捆绑安装将 spree 升级到 1.2.0,
按照他们的文档处理所有代码中断(我猜你会有一些) .
并在 app/models/spree/ 下创建一个简单的 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

请享用。

于 2012-10-21T17:31:32.563 回答
4

在 spree >= 2.0.0 中,您可以使用以下辅助方法删除任何结帐步骤。请按照以下步骤操作。

第 1 步:在 app/models/spree/ 中创建名为 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/

于 2013-08-08T04:46:46.177 回答
0

Spree 中的默认结帐步骤

  1. 地址
  2. 交货
  3. 支付
  4. 确认

Spree(2.0) 允许您使用相应的帮助程序修改结帐过程以添加或删除步骤。

insert_checkout_step
remove_checkout_step

需要记住 remove_checkout_step 一次只会删除一个结帐步骤:

于 2014-02-24T09:55:26.257 回答
0

它也适用于 Spree Solidus的新分支

于 2016-11-03T02:12:51.877 回答