Using Spree, how can I find product option values from an order in rails console?

孤街浪徒 提交于 2019-12-11 03:43:50

问题


I am able to get products from an order, but I still didn't find a way to get its option_values in order to produce it. This is how I found the product:

  p = Order.find_by_number("R326153622").products.first

Then, I have its option_types through p.option_types which gives me:

=> [#<OptionType id: 935339118, name: "gender", ...>, 
    #<OptionType id: 935339117, name: "size", ...>, 
    #<OptionType id: 643188970, name: "color", ...>]

Ok! Now my headache starts. I just can't realize where to find the gender, size, and color of this product, chosen by the customer when he put it in his cart.

I'm giving up and calling the customer right away, but still wanted to understand it =D


回答1:


you can do it like so

  p = Order.find_by_number("R326153622").products.first

then

  p.option_types.map(&:name)

what is happening here is that this form

 array.map(&:method_name)

call this methods on each one of array members



来源:https://stackoverflow.com/questions/16240226/using-spree-how-can-i-find-product-option-values-from-an-order-in-rails-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!