Monday, 15 September 2014

ruby on rails - Duplicate product items being listed in Spree customized site -



ruby on rails - Duplicate product items being listed in Spree customized site -

i pretty novice programmer , i'm working on building web store customizing spree little bit. trying have home page shows few products designated "featured" on home page (based on taxon site administrator can set). however, issue i'm finding every product designated "featured" shows twice on site - have no thought why happening.

here index.html.erb

<div class="container"> <% if @featured_products.any? %> <div id="featured-products" class="row"> <h3><center>featured products</center></h3> <hr> <ul class="carousel"> <% @featured_products.each |product| %> <%= render 'product', :product => product %> <% end %> </ul> </div> <% end %>

here products partial:

<div class="col-md-3"> <li class="columns four" data-hook="featured_products_list_item"> <div class="product-image"> <%= link_to product_image(product), product%> </div> <%= link_to truncate(product.name, :length => 50), product, :class => 'product-name', :title => product.name %> <span><%= product.display_price %></span> </li> </div>

here home controller:

module spree class homecontroller < spree::storecontroller helper 'spree/products' respond_to :html def index @searcher = build_searcher(params) @products = @searcher.retrieve_products @taxonomies = spree::taxonomy.includes(root: :children) #addition spree fancy featured = spree::taxon.where(:name => 'featured').first @featured_products = featured.products.active if featured end end end

here products controller:

module spree class productscontroller < spree::storecontroller before_filter :load_product, :only => :show before_filter :load_taxon, :only => :index rescue_from activerecord::recordnotfound, :with => :render_404 helper 'spree/taxons' respond_to :html def index @searcher = build_searcher(params) @products = @searcher.retrieve_products @taxonomies = spree::taxonomy.includes(root: :children) end def show homecoming unless @product @variants = @product.variants_including_master.active(current_currency).includes([:option_values, :images]) @product_properties = @product.product_properties.includes(:property) @taxon = spree::taxon.find(params[:taxon_id]) if params[:taxon_id] end private def accurate_title @product ? @product.name : super end def load_product if try_spree_current_user.try(:has_spree_role?, "admin") @products = product.with_deleted else @products = product.active(current_currency) end @product = @products.friendly.find(params[:id]) end def load_taxon @taxon = spree::taxon.find(params[:taxon]) if params[:taxon].present? end end end

any ideas i'm doing wrong?! copied bit of code used in spree fancy build "featured products" section; however, mine seems listing each item twice.

thanks everyone/anyone!

i noticed happening not sure of root cause, anyways here prepare came with. https://github.com/spree/spree_fancy/pull/119

ruby-on-rails e-commerce spree

No comments:

Post a Comment