fix products listing

This commit is contained in:
2026-03-24 14:39:13 +01:00
parent 3b80fa6dbe
commit 73cc936d56
8 changed files with 22 additions and 108 deletions

View File

@@ -1,6 +1,7 @@
package listProductsRepo
import (
"git.ma-al.com/goc_daniel/b2b/app/config"
"git.ma-al.com/goc_daniel/b2b/app/db"
"git.ma-al.com/goc_daniel/b2b/app/model"
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
@@ -22,20 +23,6 @@ func (repo *ListProductsRepo) GetListing(id_lang uint, p find.Paging, filt *filt
var listing []model.ProductInList
var total int64
// var resultIDs []uint
// q := db.DB.
// // SQL_CALC_FOUND_ROWS is a neat trick which works on MariaDB and
// // MySQL. It works when followed by `SELECT FOUND_ROWS();`. To learn
// // more see: https://mariarawmodel.com/kb/en/found_rows/
// // WARN: This might not work on different SQL databases
// Select("DISTINCT SQL_CALC_FOUND_ROWS id").
// // Debug().
// Scopes(view.FromDBViewForDisplay(langID, countryIso)).
// Scopes(scopesForFiltersOnDisplay(db.DB, langID, countryIso, filt)).
// Scopes(filt.OfCategory(filters.ORDER_FILTER)...).
// Limit(p.Limit()).
// Offset(p.Offset())
subQuery := db.DB.
Table("ps_image").
Select("id_product, MIN(id_image) AS id_image").
@@ -44,12 +31,12 @@ func (repo *ListProductsRepo) GetListing(id_lang uint, p find.Paging, filt *filt
err := db.DB.
Table("ps_product").
Select(`
ps_product.id_product AS id,
ps_product.id_product AS product_id,
ps_product_lang.name AS name,
ps_product.active AS active,
ps_product_lang.link_rewrite AS link_rewrite,
COALESCE(ps_image_shop.id_image, any_image.id_image) AS id_image
`).
COALESCE(CONCAT( ?, '/', ps_image_shop.id_image, '-small_default/', ps_product_lang.link_rewrite, '.webp'), CONCAT( ?, '/', any_image.id_image, '-small_default/', ps_product_lang.link_rewrite, '.webp')) AS id_image
`, config.Get().Image.ImagePrefix, config.Get().Image.ImagePrefix).
Joins(`
LEFT JOIN ps_product_lang
ON ps_product_lang.id_product = ps_product.id_product