debug
This commit is contained in:
@@ -62,7 +62,7 @@ type Product struct {
|
|||||||
DeliveryDays uint `gorm:"column:delivery_days" json:"delivery_days" form:"delivery_days"`
|
DeliveryDays uint `gorm:"column:delivery_days" json:"delivery_days" form:"delivery_days"`
|
||||||
}
|
}
|
||||||
type ProductInList struct {
|
type ProductInList struct {
|
||||||
ID uint `gorm:"column:id_product;primaryKey" json:"product_id" form:"product_id"`
|
ProductID uint `gorm:"column:ID;primaryKey" json:"product_id" form:"product_id"`
|
||||||
Name string `gorm:"column:name" json:"name" form:"name"`
|
Name string `gorm:"column:name" json:"name" form:"name"`
|
||||||
ImageID uint `gorm:"column:id_image"`
|
ImageID uint `gorm:"column:id_image"`
|
||||||
LinkRewrite string `gorm:"column:link_rewrite"`
|
LinkRewrite string `gorm:"column:link_rewrite"`
|
||||||
|
|||||||
@@ -21,33 +21,6 @@ func (repo *ListProductsRepo) GetListing(id_shop uint, id_lang uint, p find.Pagi
|
|||||||
var listing []model.ProductInList
|
var listing []model.ProductInList
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
// Apply filters here
|
|
||||||
q := db.DB.Raw(`
|
|
||||||
SELECT
|
|
||||||
ps_product.id_product AS ID,
|
|
||||||
ps_product_lang.name AS Name,
|
|
||||||
ps_product.active AS Active,
|
|
||||||
ps_product_lang.link_rewrite AS LinkRewrite,
|
|
||||||
COALESCE (
|
|
||||||
ps_image_shop.id_image, any_image.id_image
|
|
||||||
) AS ImageID
|
|
||||||
FROM ps_product
|
|
||||||
LEFT JOIN ps_product_lang
|
|
||||||
ON ps_product_lang.id_product = ps_product.id_product
|
|
||||||
AND ps_product_lang.id_shop = ?
|
|
||||||
AND ps_product_lang.id_lang = ?
|
|
||||||
LEFT JOIN ps_image_shop
|
|
||||||
ON ps_image_shop.id_product = ps_product.id_product
|
|
||||||
AND ps_image_shop.id_shop = ?
|
|
||||||
AND ps_image_shop.cover = 1
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT id_product, MIN(id_image) AS id_image
|
|
||||||
FROM ps_image
|
|
||||||
GROUP BY id_product
|
|
||||||
) any_image
|
|
||||||
ON ps_product.id_product = any_image.id_product`,
|
|
||||||
id_shop, id_lang, id_shop)
|
|
||||||
|
|
||||||
// var resultIDs []uint
|
// var resultIDs []uint
|
||||||
// q := db.DB.
|
// q := db.DB.
|
||||||
// // SQL_CALC_FOUND_ROWS is a neat trick which works on MariaDB and
|
// // SQL_CALC_FOUND_ROWS is a neat trick which works on MariaDB and
|
||||||
@@ -62,15 +35,41 @@ func (repo *ListProductsRepo) GetListing(id_shop uint, id_lang uint, p find.Pagi
|
|||||||
// Limit(p.Limit()).
|
// Limit(p.Limit()).
|
||||||
// Offset(p.Offset())
|
// Offset(p.Offset())
|
||||||
|
|
||||||
err := q.Count(&total).Error
|
err := db.DB.Raw(`
|
||||||
|
SELECT
|
||||||
|
ps_product.id_product AS 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
|
||||||
|
FROM ps_product
|
||||||
|
LEFT JOIN ps_product_lang
|
||||||
|
ON ps_product_lang.id_product = ps_product.id_product
|
||||||
|
AND ps_product_lang.id_shop = ?
|
||||||
|
AND ps_product_lang.id_lang = ?
|
||||||
|
LEFT JOIN ps_image_shop
|
||||||
|
ON ps_image_shop.id_product = ps_product.id_product
|
||||||
|
AND ps_image_shop.id_shop = ?
|
||||||
|
AND ps_image_shop.cover = 1
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT id_product, MIN(id_image) AS id_image
|
||||||
|
FROM ps_image
|
||||||
|
GROUP BY id_product
|
||||||
|
) any_image
|
||||||
|
ON ps_product.id_product = any_image.id_product
|
||||||
|
LIMIT ? OFFSET ?`,
|
||||||
|
id_shop, id_lang, id_shop, p.Limit(), p.Offset()).
|
||||||
|
Scan(&listing).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return find.Found[model.ProductInList]{}, err
|
return find.Found[model.ProductInList]{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = q.
|
err = db.DB.Raw(`
|
||||||
Limit(p.Limit()).
|
SELECT COUNT(*)
|
||||||
Offset(p.Offset()).
|
FROM ps_product`).
|
||||||
Scan(&listing).Error
|
Scan(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return find.Found[model.ProductInList]{}, err
|
return find.Found[model.ProductInList]{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user