1

When I have a Product without any Variants, I am trying to select it by itself to add it as a Line Item to my Cart. Im doing this via the following:

My Params I'm sending in:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"cYWaQT2T3V8huhPaZZO0A2PIuEp2/hO3ar9svRTKKG8=", "product_id"=>"1060500594", "variants"=>{"1013589418"=>"1"}}


@order = current_order(true)
@size = Spree::OptionValue.find(params[:size]) if params[:size]
@color = Spree::OptionValue.find(params[:color]) if params[:color]

@prod_id = params[:product_id]

if @size && @color
  @variant = Spree::Variant.joins(:option_values).where("spree_option_values.id in (?) AND product_id = ?", [@size, @color], @prod_id).first
else
  @variant = Spree::Product.find(@prod_id).master
end

It seems to not find the Variant in the Else-Portion of the Statement. It works perfectly fine, if the @size/@color is being passed in on a Product with Variants. The confusing part is - If I execute exactly this code in the console, it works as it should.

4

0 回答 0