2016-02-27 94 views
0

我在狂欢电子商务改变了货币,现在我得到以下错误:如何覆盖spree控制器?

NoMethodError in Spree::OrdersController#populate 
undefined method `+' for nil:NilClass 

Extracted source (around line #116): 


114  self.currency = currency 
115  self.price = variant.price_in(currency).amount + 
116      variant.price_modifier_amount_in(currency, opts) 
117  else 
118  self.price = variant.price + 
         variant.price_modifier_amount(opts) 

enter image description here

所以我想重写OrdersController 我这样说的: https://guides.spreecommerce.com/developer/logic.html 但我仍然困惑 - 何处我找到了这个orderscontroller的初始代码?

回答

0

I changed currency in spree ecommerce and now I get the following error:

variant.price_modifier_amount_in(货币,选择采用)绝对是返回nil。所以,你改变货币的方式是打破系统,尝试调试它。

So I want to rewrite OrdersController if you want to rewrite part of OrdersController, you should use deface https://github.com/spree/deface

例如,您可以order_controller_decorator.rb添加到应用程序/控制器/大礼包/ 用下面的代码

def update 
    if @order.contents.update_cart(order_params) 
    respond_with(@order) do |format| 
     format.html do 
     if params.has_key?(:checkout) 
      @order.next if @order.cart? 
      redirect_to checkout_state_path(@order.checkout_steps.first) 
     else 
      redirect_to cart_path 
     end 
     end 
    end 
    else 
    respond_with(@order) 
    end 
end 

这个代码将改变/只覆盖更新功能。

如果您要替换控制器中的所有内容,请在app/controllers/spree/ 中创建orders_controller.rb文件,然后添加您的代码。你可能想参考original source code for order_controller

0

问题不在于spree控制器。问题是:

variant.price_modifier_amount_in(currency, opts) 

返回一个nil实例。这就是为什么你会得到:

undefined method `+' for nil:NilClass 
+0

无论如何,我在哪里可以得到这个控制器的代码? – user2950593

+0

您粘贴到问题中的堆栈跟踪(在第一行)显示抛出错误的对象的路径。堆栈跟踪是你的朋友。学会喜欢它。 – jvillian