feat: active & deactivate the price for product

This commit is contained in:
2026-05-14 16:20:59 +02:00
parent 0fe8a06bfa
commit e0c354d76c
4 changed files with 66 additions and 15 deletions
+4 -4
View File
@@ -69,8 +69,8 @@ func (d *Database) CreateProduct(product any) error {
p.SetUpdatedAt(result.UpdatedAt)
for i, price := range p.GetPrices() {
err := d.GDB.Exec(`INSERT INTO product_prices (product_id, quantity, price) VALUES (?, ?, ?)`,
result.ID, price.Quantity, price.Price).Error
err := d.GDB.Exec(`INSERT INTO product_prices (product_id, quantity, price, active_price) VALUES (?, ?, ?, ?)`,
result.ID, price.Quantity, price.Price, price.ActivePrice).Error
if err != nil {
log.Printf("❌ [DB CreateProduct] Erreur insertion prix[%d]: %v", i, err)
return fmt.Errorf("erreur insertion prix: %v", err)
@@ -190,8 +190,8 @@ func (d *Database) UpdateProduct(productID int, name, category, description, uni
d.GDB.Exec(`DELETE FROM product_prices WHERE product_id = ?`, productID)
for _, price := range prices {
if err := d.GDB.Exec(`INSERT INTO product_prices (product_id, quantity, price) VALUES (?, ?, ?)`,
productID, price.Quantity, price.Price).Error; err != nil {
if err := d.GDB.Exec(`INSERT INTO product_prices (product_id, quantity, price, active_price) VALUES (?, ?, ?, ?)`,
productID, price.Quantity, price.Price, price.ActivePrice).Error; err != nil {
log.Printf("❌ [UpdateProduct] Erreur prix: %v", err)
}
}