class Object
Public Instance Methods
index()
click to toggle source
# File lib/gemgento/admin/product_positions.rb, line 15 def index if params[:category_id] @category = Gemgento::Category.find(params[:category_id]) elsif Gemgento::Category.top_level.navigation.any? @category = Gemgento::Category.top_level.navigation.first else @category = Gemgento::Category.root end @store = params[:store_id].blank? ? nil : Gemgento::Store.find(params[:store_id]) @products = @category.products(@store).active.catalog_visible end
update()
click to toggle source
# File lib/gemgento/admin/product_positions.rb, line 28 def update @category = Gemgento::Category.where(id: params[:category_id]).first @stores = params[:store_id].blank? ? Gemgento::Store.all : Gemgento::Store.where(id: params[:store_id]) @stores.each do |store| params[:products].split(',').each_with_index do |id, index| product_category = Gemgento::ProductCategory.find_by(category_id: @category.id, product_id: id, store_id: store.id) next if product_category.nil? product_category.position = index product_category.sync_needed = false product_category.save! end Gemgento::API::SOAP::Catalog::Category.update_product_positions(@category, store) end flash[:notice] = 'Product positions successfully updated.' redirect_to admin_product_positions_path(category_id: @category.id, store_id: params[:store_id]) end