Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] Search by name in stock #5506

Closed
vokshirg opened this issue Nov 7, 2023 · 7 comments
Closed

[Admin] Search by name in stock #5506

vokshirg opened this issue Nov 7, 2023 · 7 comments
Labels
confirmed Validated report good first issue Wanted, but lacking time to work on it and might be a good fit for a first contribution type:bug Error, flaw or fault

Comments

@vokshirg
Copy link

vokshirg commented Nov 7, 2023

Solidus Version:
4.2

To Reproduce
/admin/stock_items?variant_search_term=search_query&button=
OR

  1. Go to '/admin/stock_items'
  2. Try to search by any variant

Current behavior
exception:

ActiveRecord::StatementInvalid at /admin/stock_items
PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...n_values"."name" ILIKE '%Sulfate-free%') ORDER BY "spree_var...
                                                             ^
"SELECT DISTINCT \"spree_variants\".* FROM \"spree_variants\" LEFT OUTER JOIN \"spree_products\" ON \"spree_products\".\"id\" = \"spree_variants\".\"product_id\" LEFT OUTER JOIN \"spree_option_values_variants\" ON \"spree_option_values_variants\".\"variant_id\" = \"spree_variants\".\"id\" LEFT OUTER JOIN \"spree_option_values\" ON \"spree_option_values\".\"id\" = \"spree_option_values_variants\".\"option_value_id\" WHERE \"spree_variants\".\"deleted_at\" IS NULL AND ((((\"spree_variants\".\"sku\" ILIKE '%Sulfate-free%' OR \"spree_products\".\"name\" ILIKE '%Sulfate-free%') OR \"spree_products\".\"slug\" ILIKE '%Sulfate-free%') OR \"spree_option_values\".\"presentation\" ILIKE '%Sulfate-free%') OR \"spree_option_values\".\"name\" ILIKE '%Sulfate-free%') ORDER BY \"spree_variants\".\"sku\" ASC"

Expected behavior

correct search query

Screenshots

Screenshot 2023-11-07 at 15 43 13

@kennyadsl
Copy link
Member

Thanks for reporting. I think the issue is here: 6db4f52#r1383302271. We tried and by removing the .distinctcall the error disappear.

cc @softr8

This might be a good first contribution if anyone is interested.

@kennyadsl kennyadsl added good first issue Wanted, but lacking time to work on it and might be a good fit for a first contribution confirmed Validated report type:bug Error, flaw or fault labels Nov 7, 2023
@vokshirg
Copy link
Author

vokshirg commented Nov 7, 2023

Temp Hotfix for anybody else

# app/overrides/hairdom/controllers/spree/admin/stock_items_controller/fix_search.rb
module Hairdom
  module Spree
    module Admin
      module StockItemsController
        module FixSearch
          def variant_scope
            scope = ::Spree::Variant
                      .accessible_by(current_ability)
                      .order(:sku)
                      .includes(
                        :images,
                        stock_items: :stock_location,
                        product: :variant_images,
                        option_values: :option_type
                      )

            scope = scope.where(product: @product, is_master: !@product.has_variants?) if @product
            scope = scope.by_stock_location(params[:stock_location_id]) if params[:stock_location_id].present?

            scope
          end

          ::Spree::Admin::StockItemsController.prepend self
        end
      end
    end
  end
end

@mehboobali98
Copy link

Can I work on this? Thanks

@kennyadsl
Copy link
Member

@mehboobali98 you are welcome!

@FranciscoJBrito
Copy link

Hi @kennyadsl @vokshirg, is this issue still open? To work on it

@kennyadsl
Copy link
Member

@FranciscoJBrito yes!

@nvandoorn
Copy link
Contributor

Hey folks, I opened #5660 to address this. I don't think it's complete yet, so I marked it as draft, but at the minimum it has a useful feature spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Validated report good first issue Wanted, but lacking time to work on it and might be a good fit for a first contribution type:bug Error, flaw or fault
Projects
None yet
Development

No branches or pull requests

5 participants