Tyler Kocheff
10/14/2021, 4:35 PM.page number on like 23, I can return page 2 (on page one in the app's view). The params appear to be returning correctly in the controller and in the view. Is something weird happening with the kaminari paginator that I'm missing?Edwin Cruz
10/14/2021, 5:52 PM[18] pry(main)> Spree::Config.searcher_class.new({}).retrieve_products.joins('LEFT JOIN "spree_product_properties" ON "spree_product_properties"."product_id" = "spree_products"."id" AND "spree_product_properties"."property_id" = 1').select('"spree_products".*, "spree_product_properties"."value" AS "product_property"').reorder(:product_property).to_a.map(&:product_property)
Spree::Product Load (7.8ms) SELECT DISTINCT "spree_products".*, "spree_product_properties"."value" AS "product_property" FROM "spree_products" INNER JOIN "spree_variants" ON "spree_variants"."is_master" = $1 AND "spree_variants"."product_id" = "spree_products"."id" INNER JOIN "spree_variants" "variants_including_masters_spree_products_join" ON "variants_including_masters_spree_products_join"."deleted_at" IS NULL AND "variants_including_masters_spree_products_join"."product_id" = "spree_products"."id" INNER JOIN "spree_prices" ON "spree_prices"."deleted_at" IS NULL AND "spree_prices"."variant_id" = "variants_including_masters_spree_products_join"."id" LEFT JOIN "spree_product_properties" ON "spree_product_properties"."product_id" = "spree_products"."id" AND "spree_product_properties"."property_id" = 1 WHERE "spree_products"."deleted_at" IS NULL AND EXISTS (SELECT "spree_prices".* FROM "spree_prices" WHERE "spree_prices"."deleted_at" IS NULL AND "spree_variants"."id" = "spree_prices"."variant_id") AND ("spree_products".available_on <= '2021-10-14 17:51:15.043779') AND ("spree_products".discontinue_on IS NULL OR"spree_products".discontinue_on >= '2021-10-14 17:51:15.044003') AND "spree_prices"."deleted_at" IS NULL AND "spree_prices"."currency" = $2 AND "spree_prices"."country_iso" IS NULL ORDER BY "product_property" ASC LIMIT $3 OFFSET $4 [["is_master", true], ["currency", "MXN"], ["LIMIT", 12], ["OFFSET", 0]]
=> ["Mug", "Mug", "Snapback Cap", "Tote", "Tote", nil, nil, nil, nil, nil, nil, nil]
[19] pry(main)>
All you need to do is to change the AND "spree_product_properties"."property_id" = 1' for the real property id you want to sort products byEdwin Cruz
10/14/2021, 5:53 PMEdwin Cruz
10/14/2021, 6:51 PMSpree::Config.searcher_class.new({}).retrieve_products.with_property(Spree::ProductProperty.first.property).select("spree_products.*, spree_product_properties.value product_property").reorder(:product_property)Tyler Kocheff
10/14/2021, 7:53 PMEdwin Cruz
10/14/2021, 8:10 PMdef sort_by_attributes
return @products unless params[:sorting].present?
sortBy = params[:sorting].presence || 'name'
if ['name', 'amount'].include?(sortBy)
@products.select("spree_products.*, spree_prices.amount").reorder("#{sortBy} ASC")
else
property = Spree::Property.find_by(name: params[:sorting])
@products.with_property(property).select("spree_products.*, spree_product_properties.value product_property").reorder(:product_property)
end
endTyler Kocheff
10/15/2021, 4:12 PM.select query method because I'm getting this and so far I haven't had luck modifying it.
PG::UndefinedColumn: ERROR: column "product_property" does not exist
LINE 1: SELECT DISTINCT "product_property" AS alias_0, "spree_produc...Edwin Cruz
10/15/2021, 4:18 PM.reorder('spree_product_properties.value')Tyler Kocheff
10/15/2021, 5:29 PMEdwin Cruz
10/15/2021, 5:38 PM