pejhancctv/utils/productCount.go

20 lines
472 B
Go

package utils
import (
"app/database"
"app/models"
)
func GetProductCount(id int64, cart_id uint) (uint, error) {
var count int64
db := database.Db()
var product models.Cart_items
// Query the count of products with the given name
if err := db.Model(&product).Where("product_id = ?", id).Where("is_removed = ?", false).Where("status = ? ", "pending").Where("cart_id = ?", cart_id).Count(&count).Error; err != nil {
return 0, err
}
return uint(count), nil
}