lib/product_customizations.rb
# given params[:customizations], return a non-persisted array of ProductCustomization objects
given params[:customizations], return a non-persisted array of ProductCustomization objects
given params [ : customizations ] return a non - persisted array of ProductCustomization objects
def product_customizations
    customizations=[]
    params[:product_customizations].each do |ct_id,cv_pair|  
      next if cv_pair.empty? || cv_pair.values.all? {|v| v.empty?}
      pc=Spree::ProductCustomization.new(:product_customization_type_id => ct_id)
      cv_pair.each_pair do |cust_opt_id, user_input|
        cpo=Spree::CustomizedProductOption.new
        cpo.customizable_product_option_id= cust_opt_id
        if user_input.is_a? String
          cpo.value = user_input
        else
          cpo.value = "" 
          cpo.customization_image = user_input["customization_image"]
        end
        pc.customized_product_options << cpo
      end
      customizations << pc
    end if params[:product_customizations]
    customizations
  end
def product_customizations customizations = [ ] params [ :product_customizations ] . each do | ct_id , cv_pair | next if cv_pair . empty? || cv_pair . values . all? { | v | v . empty? } pc = Spree :: ProductCustomization . new ( :product_customization_type_id => ct_id ) cv_pair . each_pair do | cust_opt_id , user_input | cpo = Spree :: CustomizedProductOption . new cpo . customizable_product_option_id = cust_opt_id if user_input . is_a? String cpo . value = user_input else cpo . value = "" cpo . customization_image = user_input [ "customization_image" ] end pc . customized_product_options << cpo end customizations << pc end if params [ :product_customizations ] customizations end
given params[:customizations], return a non-persisted array of ProductCustomization objects
given params [ : customizations ] return a non - persisted array of ProductCustomization objects
# do we have any customizations? # customization_type_id => # {customized_product_option_id => <user input>,  etc.} # create a product_customization based on ct_id # create a customized_product_option based on cust_opt_id # attach to its 'type' # TODO revisit. What should be here # attach to its customization