Class: Caboose::ProductsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::ProductsController
- Defined in:
- app/controllers/caboose/products_controller.rb
Instance Method Summary collapse
-
#admin_add ⇒ Object
POST /admin/products.
-
#admin_add_image ⇒ Object
POST /admin/products/:id/images.
-
#admin_add_multiple_variants ⇒ Object
POST /admin/products/:id/varaints/add-multiple.
-
#admin_add_to_category ⇒ Object
POST /admin/products/:id/categories.
-
#admin_add_upcs ⇒ Object
GET /admin/products/add-upcs - TODO remove this; it’s a temporary thing for woods-n-water.
-
#admin_add_variants ⇒ Object
POST /admin/products/:id/variants/add.
-
#admin_combine ⇒ Object
POST /admin/products/combine.
-
#admin_combine_assign_title ⇒ Object
GET /admin/products/combine-step2.
-
#admin_combine_select_products ⇒ Object
GET /admin/products/combine.
-
#admin_delete ⇒ Object
DELETE /admin/products/:id.
-
#admin_delete_form ⇒ Object
GET /admin/products/:id/delete.
-
#admin_edit_categories ⇒ Object
GET /admin/products/:id/categories.
-
#admin_edit_collections ⇒ Object
GET /admin/products/:id/collections.
-
#admin_edit_description ⇒ Object
GET /admin/products/:id/description.
-
#admin_edit_general ⇒ Object
GET /admin/products/:id/general.
-
#admin_edit_images ⇒ Object
GET /admin/products/:id/images.
-
#admin_edit_options ⇒ Object
GET /admin/products/:id/options.
-
#admin_edit_seo ⇒ Object
GET /admin/products/:id/seo.
-
#admin_edit_variant_columns ⇒ Object
GET /admin/products/:id/variant-cols.
-
#admin_edit_variant_sort_order ⇒ Object
GET /admin/products/:id/variants/sort-order.
-
#admin_edit_variants ⇒ Object
GET /admin/products/:id/variants GET /admin/products/:id/variants/:variant_id.
-
#admin_group_variants ⇒ Object
GET /admin/products/:id/variants/group.
-
#admin_index ⇒ Object
GET /admin/products.
-
#admin_json ⇒ Object
GET /admin/products/json.
-
#admin_json_single ⇒ Object
GET /admin/products/:id/json.
-
#admin_new ⇒ Object
GET /admin/products/new.
-
#admin_remove_from_category ⇒ Object
DELETE /admin/products/:id/categories/:category_id.
-
#admin_remove_variants ⇒ Object
POST /admin//products/:id/variants/remove.
-
#admin_sort ⇒ Object
GET /admin/products/sort.
-
#admin_status_options ⇒ Object
GET /products/status-options.
-
#admin_update ⇒ Object
PUT /admin/products/:id.
-
#admin_update_sort_order ⇒ Object
PUT /admin/products/update-sort-order.
-
#admin_update_variant_columns ⇒ Object
PUT /admin/products/:id/variant-cols.
-
#admin_update_variant_option1_sort_order ⇒ Object
PUT /admin/products/:id/variants/option1-sort-order.
-
#admin_update_variant_option2_sort_order ⇒ Object
PUT /admin/products/:id/variants/option1-sort-order.
-
#admin_update_variant_option3_sort_order ⇒ Object
PUT /admin/products/:id/variants/option1-sort-order.
-
#admin_update_vendor ⇒ Object
PUT /admin/products/:id/update-vendor.
-
#admin_update_vendor_status ⇒ Object
GET /admin/products/update-vendor-status/:id.
-
#admin_variants_json ⇒ Object
GET /admin/products/:id/variants/json.
-
#api_details ⇒ Object
GET /api/products/:id.
-
#api_list ⇒ Object
GET /api/products.
-
#api_variants ⇒ Object
GET /api/products/:id/variants.
- #default_variant_cols ⇒ Object
-
#index ⇒ Object
GET /products || GET /products/:id.
-
#info ⇒ Object
GET /product/info.
- #show ⇒ Object
Methods inherited from ApplicationController
#before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_add ⇒ Object
POST /admin/products
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'app/controllers/caboose/products_controller.rb', line 630 def admin_add return if !user_is_allowed('products', 'add') resp = Caboose::StdClass.new( :error => nil, :redirect => nil ) title = params[:title] if title.length == 0 resp.error = "The title cannot be empty." else p = Product.new(:title => title) p.save resp.redirect = "/admin/products/#{p.id}/general" end render :json => resp end |
#admin_add_image ⇒ Object
POST /admin/products/:id/images
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'app/controllers/caboose/products_controller.rb', line 518 def admin_add_image return if !user_is_allowed('products', 'edit') product_id = params[:id] if (params[:new_image].nil?) render :text => "<script type='text/javascript'>parent.modal.autosize(\"<p class='note error'>You must provide an image.</p>\", 'new_image_message');</script>" else img = ProductImage.new img.product_id = product_id img.image = params[:new_image] img.square_offset_x = 0 img.square_offset_y = 0 img.square_scale_factor = 1.00 img.save render :text => "<script type='text/javascript'>parent.window.location.reload(true);</script>" end end |
#admin_add_multiple_variants ⇒ Object
POST /admin/products/:id/varaints/add-multiple
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/controllers/caboose/products_controller.rb', line 189 def admin_add_multiple_variants product = Product.find(params[:id]) params[:variants_csv].split("\r\n").each do |variant| row = variant.split(',') render :json => { :success => false, :error => "Quantity is not defined for variant: #{row[0].strip}" } and return if row[1].nil? render :json => { :success => false, :error => "Price is not defined for variant: #{row[0].strip}" } and return if row[2].nil? attributes = { :alternate_id => row[0].strip, :quantity_in_stock => row[1].strip.to_i, :price => '%.2f' % row[2].strip.to_f, :status => 'Active' } if product.option1 && row[3].nil? render :json => { :success => false, :error => "#{product.option1} not defined for variant: #{attributes[:alternate_id]}" } and return elsif product.option1 attributes[:option1] = row[3].strip end if product.option2 && row[4].nil? render :json => { :success => false, :error => "#{product.option2} not defined for variant: #{attributes[:alternate_id]}" } and return elsif product.option2 attributes[:option2] = row[4].strip end if product.option3 && row[5].nil? render :json => { :success => false, :error => "#{product.option3} not defined for variant: #{attributes[:alternate_id]}" } and return elsif product.option3 attributes[:option3] = row[5].strip end if product.variants.find_by_alternate_id(attributes[:alternate_id]) product.variants.find_by_alternate_id(attributes[:alternate_id]).update_attributes(attributes) else Variant.create(attributes.merge(:product_id => product.id)) end end render :json => { :success => true } end |
#admin_add_to_category ⇒ Object
POST /admin/products/:id/categories
487 488 489 490 491 492 493 494 495 496 |
# File 'app/controllers/caboose/products_controller.rb', line 487 def admin_add_to_category return if !user_is_allowed('products', 'edit') cat_id = params[:category_id] product_id = params[:id] if !CategoryMembership.exists?(:category_id => cat_id, :product_id => product_id) CategoryMembership.create(:category_id => cat_id, :product_id => product_id) end render :json => true end |
#admin_add_upcs ⇒ Object
GET /admin/products/add-upcs - TODO remove this; it’s a temporary thing for woods-n-water
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'app/controllers/caboose/products_controller.rb', line 331 def admin_add_upcs params[:vendor_id] if params[:vendor_id] and params[:vendor_id].empty? conditions = if params[:vendor_id] "store_variants.alternate_id IS NULL and store_vendors.id = #{params[:vendor_id]}" else "store_variants.alternate_id IS NULL" end @products = Product.all( :include => [:variants, :vendor], :conditions => conditions ) render :layout => 'caboose/admin' end |
#admin_add_variants ⇒ Object
POST /admin/products/:id/variants/add
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'app/controllers/caboose/products_controller.rb', line 171 def admin_add_variants params[:variant_ids].each do |variant_id| variant = Variant.find(variant_id) # Delete current variant product if this is the last variant # variant.product.update_attribute(:status, 'deleted') if variant.product.variants.where('status != ?', 'deleted').count == 0 # Add reference to new product # varant.product_id = params[:id] end # Iterate over variants and add them to the product # Remove product that the variants are associated with; UNLESS it's the current product redirect_to "/admin/products/#{params[:id]}/variants" end |
#admin_combine ⇒ Object
POST /admin/products/combine
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'app/controllers/caboose/products_controller.rb', line 683 def admin_combine product_ids = params[:product_ids] p = Product.new p.title = params[:title] p.description = params[:description] p.option1 = params[:option1] p.option2 = params[:option2] p.option3 = params[:option3] p.default1 = params[:default1] p.default2 = params[:default2] p.default3 = params[:default3] p.status = 'Active' p.save product_ids.each do |pid| p = Product.find(pid) p.variants.each do |v| end end end |
#admin_combine_assign_title ⇒ Object
GET /admin/products/combine-step2
679 680 |
# File 'app/controllers/caboose/products_controller.rb', line 679 def admin_combine_assign_title end |
#admin_combine_select_products ⇒ Object
GET /admin/products/combine
675 676 |
# File 'app/controllers/caboose/products_controller.rb', line 675 def admin_combine_select_products end |
#admin_delete ⇒ Object
DELETE /admin/products/:id
651 652 653 654 655 656 657 658 659 |
# File 'app/controllers/caboose/products_controller.rb', line 651 def admin_delete return if !user_is_allowed('products', 'delete') p = Product.find(params[:id]).destroy p.status = 'Deleted' p.save render :json => Caboose::StdClass.new({ :redirect => '/admin/products' }) end |
#admin_delete_form ⇒ Object
GET /admin/products/:id/delete
558 559 560 561 562 |
# File 'app/controllers/caboose/products_controller.rb', line 558 def admin_delete_form return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_categories ⇒ Object
GET /admin/products/:id/categories
478 479 480 481 482 483 484 |
# File 'app/controllers/caboose/products_controller.rb', line 478 def admin_edit_categories return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) @top_categories = Category.where(:parent_id => 1).reorder('name').all @selected_ids = @product.categories.collect{ |cat| cat.id } render :layout => 'caboose/admin' end |
#admin_edit_collections ⇒ Object
GET /admin/products/:id/collections
537 538 539 540 541 |
# File 'app/controllers/caboose/products_controller.rb', line 537 def admin_edit_collections return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_description ⇒ Object
GET /admin/products/:id/description
362 363 364 365 366 |
# File 'app/controllers/caboose/products_controller.rb', line 362 def admin_edit_description return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_general ⇒ Object
GET /admin/products/:id/general
355 356 357 358 359 |
# File 'app/controllers/caboose/products_controller.rb', line 355 def admin_edit_general return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_images ⇒ Object
GET /admin/products/:id/images
511 512 513 514 515 |
# File 'app/controllers/caboose/products_controller.rb', line 511 def admin_edit_images return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_options ⇒ Object
GET /admin/products/:id/options
471 472 473 474 475 |
# File 'app/controllers/caboose/products_controller.rb', line 471 def return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_seo ⇒ Object
GET /admin/products/:id/seo
544 545 546 547 548 |
# File 'app/controllers/caboose/products_controller.rb', line 544 def admin_edit_seo return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_variant_columns ⇒ Object
GET /admin/products/:id/variant-cols
404 405 406 407 408 409 410 |
# File 'app/controllers/caboose/products_controller.rb', line 404 def admin_edit_variant_columns return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil? @cols = session['variant_cols'] render :layout => 'caboose/admin' end |
#admin_edit_variant_sort_order ⇒ Object
GET /admin/products/:id/variants/sort-order
551 552 553 554 555 |
# File 'app/controllers/caboose/products_controller.rb', line 551 def admin_edit_variant_sort_order return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_variants ⇒ Object
GET /admin/products/:id/variants GET /admin/products/:id/variants/:variant_id
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'app/controllers/caboose/products_controller.rb', line 370 def admin_edit_variants return if !user_is_allowed('products', 'edit') @product = Product.find(params[:id]) if @product.variants.nil? || @product.variants.count == 0 v = Variant.new v.option1 = @product.default1 if @product.option1 v.option2 = @product.default2 if @product.option2 v.option3 = @product.default3 if @product.option3 v.status = 'Active' @product.variants = [v] @product.save end @variant = params[:variant_id] ? Variant.find(params[:variant_id]) : @product.variants[0] session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil? @cols = session['variant_cols'] @highlight_variant_id = params[:highlight] ? params[:highlight].to_i : nil if @product..nil? || @product..count == 0 render 'caboose/products/admin_edit_variants_single', :layout => 'caboose/admin' else render 'caboose/products/admin_edit_variants', :layout => 'caboose/admin' end end |
#admin_group_variants ⇒ Object
GET /admin/products/:id/variants/group
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/caboose/products_controller.rb', line 129 def admin_group_variants @product = Product.find(params[:id]) return if !user_is_allowed('variants', 'edit') joins = [] where = [] values = [] if params[:category_ids] joins << [:category_memberships] where << 'store_category_memberships.category_id IN (?)' values << params[:category_ids] end if params[:vendor_ids] joins << [:vendor] where << 'store_vendors.id IN (?)' values << params[:vendor_ids] end if params[:title] where << 'LOWER(store_products.title) LIKE ?' values << "%#{params[:title].downcase}%" end # Query for all relevant products products = values.any? ? Product.joins(joins).where([where.join(' AND ')].concat(values)) : [] # Grab variants for each product @variants = products.collect { |product| product.variants }.flatten # Grab all categories; except for "all" and "uncategorized" @categories = Category.where('parent_id IS NOT NULL AND name IS NOT NULL').order(:url) # Grab all vendors @vendors = Vendor.where('name IS NOT NULL').order(:name) render :layout => 'caboose/admin' end |
#admin_index ⇒ Object
GET /admin/products
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'app/controllers/caboose/products_controller.rb', line 255 def admin_index return if !user_is_allowed('products', 'view') # Temporary patch for vendor name sorting; Fix this params[:sort] = 'store_vendors.name' if params[:sort] == 'vendor' @gen = Caboose::PageBarGenerator.new(params, { 'vendor_name' => '', 'search_like' => '', 'price' => params[:filters] && params[:filters][:missing_prices] ? 0 : '' }, { 'model' => 'Caboose::Product', 'sort' => 'title', 'desc' => false, 'base_url' => '/admin/products', 'items_per_page' => 25, 'use_url_params' => false, 'abbreviations' => { 'search_like' => 'store_products.title_concat_vendor_name_like' }, 'includes' => { 'vendor_name' => [ 'vendor' , 'name' ], 'price' => [ 'variants' , 'price' ] } }) # Make a copy of all the items; so it can be filtered more @all_products = @gen.all_records # Apply any extra filters if params[:filters] @all_products = @all_products.includes(:product_images).where('store_product_images.id IS NULL') if params[:filters][:missing_images] @all_products = @all_products.where('vendor_id IS NULL') if params[:filters][:no_vendor] end # Get the correct page of the results @products = @all_products.limit(@gen.limit).offset(@gen.offset) render :layout => 'caboose/admin' end |
#admin_json ⇒ Object
GET /admin/products/json
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'app/controllers/caboose/products_controller.rb', line 299 def admin_json return if !user_is_allowed('products', 'view') # Temporary patch for vendor name sorting; Fix this params[:sort] = 'store_vendors.name' if params[:sort] == 'vendor' pager = Caboose::PageBarGenerator.new(params, { 'vendor_name' => '', 'search_like' => '', 'price' => params[:filters] && params[:filters][:missing_prices] ? 0 : '' }, { 'model' => 'Caboose::Product', 'sort' => 'title', 'desc' => false, 'base_url' => '/admin/products', 'items_per_page' => 25, 'use_url_params' => false, 'abbreviations' => { 'search_like' => 'store_products.title_concat_vendor_name_like' }, 'includes' => { 'vendor_name' => [ 'vendor' , 'name' ], 'price' => [ 'variants' , 'price' ] } }) render :json => { :pager => pager, :models => pager.items } end |
#admin_json_single ⇒ Object
GET /admin/products/:id/json
349 350 351 352 |
# File 'app/controllers/caboose/products_controller.rb', line 349 def admin_json_single p = Product.find(params[:id]) render :json => p end |
#admin_new ⇒ Object
GET /admin/products/new
624 625 626 627 |
# File 'app/controllers/caboose/products_controller.rb', line 624 def admin_new return if !user_is_allowed('products', 'add') render :layout => 'caboose/admin' end |
#admin_remove_from_category ⇒ Object
DELETE /admin/products/:id/categories/:category_id
499 500 501 502 503 504 505 506 507 508 |
# File 'app/controllers/caboose/products_controller.rb', line 499 def admin_remove_from_category return if !user_is_allowed('products', 'edit') cat_id = params[:category_id] product_id = params[:id] if CategoryMembership.exists?(:category_id => cat_id, :product_id => product_id) CategoryMembership.where(:category_id => cat_id, :product_id => product_id).destroy_all end render :json => true end |
#admin_remove_variants ⇒ Object
POST /admin//products/:id/variants/remove
234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'app/controllers/caboose/products_controller.rb', line 234 def admin_remove_variants params[:variant_ids].each do |variant_id| variant = Variant.find(variant_id) # variant.update_attribute(:status, 'deleted') # variant.product.update_attribute(:status, 'deleted') if variant.product.variants.where('status != ?', 'deleted').count == 0 end # Remove passed variants # redirect_to "/admin/products/#{params[:id]}/variants/group" render :json => true end |
#admin_sort ⇒ Object
GET /admin/products/sort
711 712 713 714 715 716 717 |
# File 'app/controllers/caboose/products_controller.rb', line 711 def admin_sort @products = Product.active @vendors = Vendor.active @categories = Category.all render :layout => 'caboose/admin' end |
#admin_status_options ⇒ Object
GET /products/status-options
662 663 664 665 666 667 668 669 670 671 672 |
# File 'app/controllers/caboose/products_controller.rb', line 662 def arr = ['Active', 'Inactive', 'Deleted'] = [] arr.each do |status| << { :value => status, :text => status } end render :json => end |
#admin_update ⇒ Object
PUT /admin/products/:id
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'app/controllers/caboose/products_controller.rb', line 565 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' then product.alternate_id = value when 'title' then product.title = value when 'caption' then product. = value when 'featured' then product.featured = value when 'description' then product.description = value when 'vendor_id' then product.vendor_id = value when 'handle' then product.handle = value when 'seo_title' then product.seo_title = value when 'seo_description' then product.seo_description = value when 'status' then product.status = value when 'category_id' then product.toggle_category(value[0], value[1]) when 'option1' then product.option1 = value when 'option2' then product.option2 = value when 'option3' then 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 '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 end end resp.success = save && product.save render :json => resp end |
#admin_update_sort_order ⇒ Object
PUT /admin/products/update-sort-order
720 721 722 723 724 725 |
# File 'app/controllers/caboose/products_controller.rb', line 720 def admin_update_sort_order params[:product_ids].each_with_index do |product_id, index| Product.find(product_id.to_i).update_attribute(:sort_order, index) end render :json => { :success => true } end |
#admin_update_variant_columns ⇒ Object
PUT /admin/products/:id/variant-cols
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'app/controllers/caboose/products_controller.rb', line 413 def admin_update_variant_columns return if !user_is_allowed('products', 'edit') session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil? resp = Caboose::StdClass.new({'attributes' => {}}) product = Product.find(params[:id]) save = true params.each do |name,value| value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value) case name when 'option1' , 'option2' , 'option3' , 'status' , 'alternate_id' , 'sku' , 'barcode' , 'price' , 'quantity_in_stock' , 'weight' , 'length' , 'width' , 'height' , 'cylinder' , 'requires_shipping' , 'allow_backorder' , 'taxable' session['variant_cols'][name] = value end end resp.success = save && product.save render :json => resp end |
#admin_update_variant_option1_sort_order ⇒ Object
PUT /admin/products/:id/variants/option1-sort-order
728 729 730 731 732 733 734 735 736 |
# File 'app/controllers/caboose/products_controller.rb', line 728 def admin_update_variant_option1_sort_order product_id = params[:id] params[:values].each_with_index do |value, i| Variant.where(:product_id => product_id, :option1 => value).all.each do |v| v.update_attribute(:option1_sort_order, i) end end render :json => { :success => true } end |
#admin_update_variant_option2_sort_order ⇒ Object
PUT /admin/products/:id/variants/option1-sort-order
739 740 741 742 743 744 745 746 747 |
# File 'app/controllers/caboose/products_controller.rb', line 739 def admin_update_variant_option2_sort_order product_id = params[:id] params[:values].each_with_index do |value, i| Variant.where(:product_id => product_id, :option2 => value).all.each do |v| v.update_attribute(:option2_sort_order, i) end end render :json => { :success => true } end |
#admin_update_variant_option3_sort_order ⇒ Object
PUT /admin/products/:id/variants/option1-sort-order
750 751 752 753 754 755 756 757 758 |
# File 'app/controllers/caboose/products_controller.rb', line 750 def admin_update_variant_option3_sort_order product_id = params[:id] params[:values].each_with_index do |value, i| Variant.where(:product_id => product_id, :option3 => value).all.each do |v| v.update_attribute(:option3_sort_order, i) end end render :json => { :success => true } end |
#admin_update_vendor ⇒ Object
PUT /admin/products/:id/update-vendor
706 707 708 |
# File 'app/controllers/caboose/products_controller.rb', line 706 def admin_update_vendor render :json => { :success => Product.find(params[:id]).update_attribute(:vendor_id, params[:vendor_id]) } end |
#admin_update_vendor_status ⇒ Object
GET /admin/products/update-vendor-status/:id
248 249 250 251 252 |
# File 'app/controllers/caboose/products_controller.rb', line 248 def admin_update_vendor_status vendor = Vendor.find(params[:id]) vendor.status = params[:status] render :json => vendor.save end |
#admin_variants_json ⇒ Object
GET /admin/products/:id/variants/json
397 398 399 400 401 |
# File 'app/controllers/caboose/products_controller.rb', line 397 def admin_variants_json render :json => false if !user_is_allowed('products', 'edit') p = Product.find(params[:id]) render :json => p.variants end |
#api_details ⇒ Object
GET /api/products/:id
115 116 117 |
# File 'app/controllers/caboose/products_controller.rb', line 115 def api_details render :json => Product.find(params[:id]) end |
#api_list ⇒ Object
GET /api/products
110 111 112 |
# File 'app/controllers/caboose/products_controller.rb', line 110 def api_list render :json => Product.where(:status => 'Active') end |
#api_variants ⇒ Object
GET /api/products/:id/variants
120 121 122 |
# File 'app/controllers/caboose/products_controller.rb', line 120 def api_variants render :json => Product.find(params[:id]).variants end |
#default_variant_cols ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'app/controllers/caboose/products_controller.rb', line 448 def default_variant_cols return { 'option1' => true, 'option2' => true, 'option3' => true, 'status' => true, 'alternate_id' => true, 'sku' => true, 'barcode' => false, 'price' => true, 'quantity' => true, 'weight' => false, 'length' => false, 'width' => false, 'height' => false, 'cylinder' => false, 'requires_shipping' => false, 'allow_backorder' => false, 'taxable' => false } end |
#index ⇒ Object
GET /products || GET /products/:id
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/caboose/products_controller.rb', line 13 def index # If id exists, is an integer and a product exists with the specified id then get the product if params[:id] && params[:id].to_i > 0 && Product.exists?(params[:id]) @product = Product.find(params[:id]) render 'product/not_available' and return if @product.status == 'Inactive' @category = @product.categories.first @review = Review.new @reviews = Review.where(:product_id => @product.id).limit(10).order("id DESC") || nil @logged_in_user = logged_in_user render 'caboose/products/details' and return end # Filter params from url url_without_params = request.fullpath.split('?').first # Find the category category = Category.where(:url => url_without_params).first # Set category ID params['category_id'] = category.id # If this is the top-most category, collect all it's immediate children IDs params['category_id'] = category.children.collect { |child| child.id } if category.id == 1 # Shove the original category ID into the first position if the param is an array params['category_id'].unshift(category.id) if params['category_id'].is_a?(Array) # Otherwise looking at a category or search parameters @pager = Caboose::Pager.new(params, { 'category_id' => '', 'vendor_id' => '', 'vendor_name' => '', 'vendor_status' => 'Active', 'status' => 'Active', 'variant_status' => 'Active', 'price_gte' => '', 'price_lte' => '', 'alternate_id' => '', 'search_like' => '' }, { 'model' => 'Caboose::Product', 'sort' => if params[:sort] then params[:sort] else 'store_products.sort_order' end, 'base_url' => url_without_params, 'items_per_page' => 15, 'use_url_params' => false, 'abbreviations' => { 'search_like' => 'title_concat_store_products.alternate_id_concat_vendor_name_concat_category_name_like', }, 'includes' => { 'category_id' => [ 'categories' , 'id' ], 'category_name' => [ 'categories' , 'name' ], 'vendor_id' => [ 'vendor' , 'id' ], 'vendor_name' => [ 'vendor' , 'name' ], 'vendor_status' => [ 'vendor' , 'status' ], 'price_gte' => [ 'variants' , 'price' ], 'price_lte' => [ 'variants' , 'price' ], 'variant_status' => [ 'variants' , 'status' ] } }) @sort_options = [ { :name => 'Default', :value => 'store_products.sort_order' }, { :name => 'Price (Low to High)', :value => 'store_variants.price ASC' }, { :name => 'Price (High to Low)', :value => 'store_variants.price DESC' }, { :name => 'Alphabetical (A-Z)', :value => 'store_products.title ASC' }, { :name => 'Alphabetical (Z-A)', :value => 'store_products.title DESC' }, ] SearchFilter.delete_all @filter = SearchFilter.find_from_url(request.fullpath, @pager, ['page']) @products = @pager.items @category = if @filter['category_id'] then Category.find(@filter['category_id'].to_i) else nil end @pager.set_item_count end |
#info ⇒ Object
GET /product/info
99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/caboose/products_controller.rb', line 99 def info p = Product.find(params[:id]) render :json => { :product => p, :option1_values => p.option1_values, :option2_values => p.option2_values, :option3_values => p.option3_values } end |
#show ⇒ Object
95 96 |
# File 'app/controllers/caboose/products_controller.rb', line 95 def show end |