def admin_update
      return if !user_is_allowed('products', 'edit')
      
      resp = Caboose::StdClass.new({'attributes' => {}})
      product = Product.find(params[:id])    
      
      save = true    
      params.each do |name,value|
        case name
          when 'alternate_id'
            product.alternate_id = value
          when 'date_available'
            if value.strip.length == 0
              product.date_available = nil
            else
              begin
                product.date_available = DateTime.parse(value)
              rescue
                resp.error = "Invalid date"
                save = false
              end
            end
          when 'title'
            product.title = value
          when 'caption'
            product.caption = value
          when 'featured'
            product.featured = value
          when 'description'
            product.description = value
          when 'category_id'
            product.category_id = value
          when 'vendor_id'  
            product.vendor_id = value
          when 'handle'
            product.handle = value
          when 'seo_title'
            product.seo_title = value
          when 'seo_description'
            product.seo_description = value
          when 'option1'
            product.option1 = value
          when 'option2'
            product.option2 = value
          when 'option3'
            product.option3 = value
          when 'default1'
            product.default1 = value
            Variant.where(:product_id => product.id, :option1 => nil).each do |p|
              p.option1 = value
              p.save
            end
          when 'default2'
            product.default2 = value
            Variant.where(:product_id => product.id, :option2 => nil).each do |p|
              p.option2 = value
              p.save
            end
          when 'default3'
            product.default3 = value
            Variant.where(:product_id => product.id, :option3 => nil).each do |p|
              p.option3 = value
              p.save
            end
          when 'status'
            product.status = value
        end
      end
      resp.success = save && product.save
      render :json => resp
    end
def admin_update
      return if !user_is_allowed('products', 'edit')
      
      resp = Caboose::StdClass.new({'attributes' => {}})
      product = Product.find(params[:id])    
      
      save = true    
      params.each do |name,value|
        case name
          when 'alternate_id'
            product.alternate_id = value
          when 'date_available'
            if value.strip.length == 0
              product.date_available = nil
            else
              begin
                product.date_available = DateTime.parse(value)
              rescue
                resp.error = "Invalid date"
                save = false
              end
            end
          when 'title'
            product.title = value
          when 'caption'
            product.caption = value
          when 'featured'
            product.featured = value
          when 'description'
            product.description = value
          when 'category_id'
            product.category_id = value
          when 'vendor_id'  
            product.vendor_id = value
          when 'handle'
            product.handle = value
          when 'seo_title'
            product.seo_title = value
          when 'seo_description'
            product.seo_description = value
          when 'option1'
            product.option1 = value
          when 'option2'
            product.option2 = value
          when 'option3'
            product.option3 = value
          when 'default1'
            product.default1 = value
            Variant.where(:product_id => product.id, :option1 => nil).each do |p|
              p.option1 = value
              p.save
            end
          when 'default2'
            product.default2 = value
            Variant.where(:product_id => product.id, :option2 => nil).each do |p|
              p.option2 = value
              p.save
            end
          when 'default3'
            product.default3 = value
            Variant.where(:product_id => product.id, :option3 => nil).each do |p|
              p.option3 = value
              p.save
            end
          when 'status'
            product.status = value
        end
      end
      resp.success = save && product.save
      render :json => resp
    end
PUT /admin/products/:id