2016-02-27 98 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