Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

fix slider so there are no longer duplicate products #119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jameshilliard
Copy link

This fixes a bug where you get 2 slider entries per product.

@jameshilliard
Copy link
Author

It would seem this fix is causing a crash when used with postgres

@JDutil
Copy link
Member

JDutil commented Jul 14, 2014

Yea you can't use uniq with postgres instead you need to use a DISTINCT clause like:
https://github.com/spree/spree/blob/master/core/app/helpers/spree/taxons_helper.rb#L7

@swcool
Copy link

swcool commented Oct 18, 2014

This duplicate display happens in slider, featured and latest. Instead of fixing in views for two files: _slider.html.erb and index.html.erb, I think a better way is to fix in controller within one place. Here is the file to fix

Spree::HomeController.class_eval do

  def index
    uniq_method = "DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position"

    slider = Spree::Taxon.where(:name => 'Slider').first
    @slider_products = slider.products.active if slider
    @slider_products = @slider_products.select(uniq_method)

    featured = Spree::Taxon.where(:name => 'Featured').first
    @featured_products = featured.products.active if featured
    @featured_products = @featured_products.select(uniq_method)

    latest = Spree::Taxon.where(:name => 'Latest').first
    @latest_products = latest.products.active if latest
    @latest_products = @latest_products.select(uniq_method)

  end

end

If people agree above solution, I think @jameshilliard or myself can submit a new pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants