calculate baseprice
This commit is contained in:
@@ -134,6 +134,7 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
Description: description,
|
||||
Category: category,
|
||||
IsPublic: true,
|
||||
BasePrice: rc.GetBasePrice(variants),
|
||||
Image: dstImage,
|
||||
Pdf: dstPdf,
|
||||
Variants: variants,
|
||||
@@ -153,6 +154,22 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
//return services.ShopItems.NewShopItem(name, abstract, description, price, tagIds)
|
||||
}
|
||||
|
||||
func (rc *shopItemController) GetBasePrice(variants []models.ItemVariant) float64 {
|
||||
result := 0.0
|
||||
|
||||
for idx, variant := range variants {
|
||||
if idx == 0 {
|
||||
result = variant.Price
|
||||
continue
|
||||
}
|
||||
|
||||
if variant.Price < result {
|
||||
result = variant.Price
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (rc *shopItemController) Create(c *gin.Context) {
|
||||
shopItem, err := rc.NewShopItemFromForm(c)
|
||||
|
||||
Reference in New Issue
Block a user