Add product features, Heleket crypto payments and order status icons.

This commit is contained in:
shop
2026-06-27 16:29:33 +03:00
parent 361d35e6b4
commit 98a0bb01e2
31 changed files with 1673 additions and 126 deletions
+19 -8
View File
@@ -22,7 +22,10 @@ func NewProductRepository(pool *pgxpool.Pool) *ProductRepository {
const productSelect = `
SELECT p.id, p.name, p.description, p.details, p.price, COALESCE(p.sale_price, 0),
p.image_url, COALESCE(c.name, p.category, 'Разное'), p.category_id,
COALESCE(c.slug, ''), p.is_active, p.created_at, p.updated_at
COALESCE(c.slug, ''), p.is_active,
COALESCE(p.attr_size, ''), COALESCE(p.attr_color, ''), COALESCE(p.attr_material, ''),
COALESCE(p.attr_weight, ''), COALESCE(p.attr_brand, ''),
p.created_at, p.updated_at
FROM products p
LEFT JOIN categories c ON c.id = p.category_id
`
@@ -32,7 +35,9 @@ func (r *ProductRepository) scanProduct(row pgx.Row) (models.Product, error) {
var catID sql.NullInt64
err := row.Scan(
&p.ID, &p.Name, &p.Description, &p.Details, &p.Price, &p.SalePrice,
&p.ImageURL, &p.Category, &catID, &p.CategorySlug, &p.IsActive, &p.CreatedAt, &p.UpdatedAt,
&p.ImageURL, &p.Category, &catID, &p.CategorySlug, &p.IsActive,
&p.AttrSize, &p.AttrColor, &p.AttrMaterial, &p.AttrWeight, &p.AttrBrand,
&p.CreatedAt, &p.UpdatedAt,
)
if catID.Valid {
id := int(catID.Int64)
@@ -94,10 +99,12 @@ func (r *ProductRepository) GetActiveByID(ctx context.Context, id int) (models.P
func (r *ProductRepository) Create(ctx context.Context, p *models.Product) error {
return r.pool.QueryRow(ctx, `
INSERT INTO products (name, description, details, price, sale_price, image_url, category, category_id, is_active)
VALUES ($1, $2, $3, $4, NULLIF($5, 0), $6, $7, $8, $9)
INSERT INTO products (name, description, details, price, sale_price, image_url, category, category_id, is_active,
attr_size, attr_color, attr_material, attr_weight, attr_brand)
VALUES ($1, $2, $3, $4, NULLIF($5, 0), $6, $7, $8, $9, $10, $11, $12, $13, $14)
RETURNING id, created_at, updated_at
`, p.Name, p.Description, p.Details, p.Price, p.SalePrice, p.ImageURL, p.Category, p.CategoryID, p.IsActive,
p.AttrSize, p.AttrColor, p.AttrMaterial, p.AttrWeight, p.AttrBrand,
).Scan(&p.ID, &p.CreatedAt, &p.UpdatedAt)
}
@@ -105,9 +112,11 @@ func (r *ProductRepository) Update(ctx context.Context, p *models.Product) error
tag, err := r.pool.Exec(ctx, `
UPDATE products SET name = $1, description = $2, details = $3, price = $4,
sale_price = NULLIF($5, 0), image_url = $6, category = $7, category_id = $8,
is_active = $9, updated_at = NOW()
WHERE id = $10
`, p.Name, p.Description, p.Details, p.Price, p.SalePrice, p.ImageURL, p.Category, p.CategoryID, p.IsActive, p.ID)
is_active = $9, attr_size = $10, attr_color = $11, attr_material = $12,
attr_weight = $13, attr_brand = $14, updated_at = NOW()
WHERE id = $15
`, p.Name, p.Description, p.Details, p.Price, p.SalePrice, p.ImageURL, p.Category, p.CategoryID, p.IsActive,
p.AttrSize, p.AttrColor, p.AttrMaterial, p.AttrWeight, p.AttrBrand, p.ID)
if err != nil {
return err
}
@@ -200,7 +209,9 @@ func (r *ProductRepository) collectProducts(rows pgx.Rows) ([]models.Product, er
var catID sql.NullInt64
if err := rows.Scan(
&p.ID, &p.Name, &p.Description, &p.Details, &p.Price, &p.SalePrice,
&p.ImageURL, &p.Category, &catID, &p.CategorySlug, &p.IsActive, &p.CreatedAt, &p.UpdatedAt,
&p.ImageURL, &p.Category, &catID, &p.CategorySlug, &p.IsActive,
&p.AttrSize, &p.AttrColor, &p.AttrMaterial, &p.AttrWeight, &p.AttrBrand,
&p.CreatedAt, &p.UpdatedAt,
); err != nil {
return nil, err
}