本文整理汇总了Golang中github.com/qor/qor-example/app/models.ColorVariation类的典型用法代码示例。如果您正苦于以下问题:Golang ColorVariation类的具体用法?Golang ColorVariation怎么用?Golang ColorVariation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ColorVariation类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createProducts
func createProducts() {
for _, p := range Seeds.Products {
category := findCategoryByName(p.CategoryName)
product := models.Product{}
product.CategoryID = category.ID
product.Name = p.Name
product.NameWithSlug = slug.Slug{p.NameWithSlug}
product.Code = p.Code
product.Price = p.Price
product.Description = p.Description
product.MadeCountry = p.MadeCountry
if err := db.DB.Create(&product).Error; err != nil {
log.Fatalf("create product (%v) failure, got err %v", product, err)
}
for _, cv := range p.ColorVariations {
color := findColorByName(cv.ColorName)
colorVariation := models.ColorVariation{}
colorVariation.ProductID = product.ID
colorVariation.ColorID = color.ID
if err := db.DB.Create(&colorVariation).Error; err != nil {
log.Fatalf("create color_variation (%v) failure, got err %v", colorVariation, err)
}
for _, i := range cv.Images {
image := models.ColorVariationImage{}
if file, err := openFileByURL(i.URL); err != nil {
fmt.Printf("open file (%q) failure, got err %v", i.URL, err)
} else {
defer file.Close()
image.Image.Scan(file)
}
image.ColorVariationID = colorVariation.ID
if err := db.DB.Create(&image).Error; err != nil {
log.Fatalf("create color_variation_image (%v) failure, got err %v", image, err)
}
}
for _, sv := range p.SizeVariations {
size := findSizeByName(sv.SizeName)
sizeVariation := models.SizeVariation{}
sizeVariation.ColorVariationID = colorVariation.ID
sizeVariation.SizeID = size.ID
sizeVariation.AvailableQuantity = 20
if err := db.DB.Create(&sizeVariation).Error; err != nil {
log.Fatalf("create size_variation (%v) failure, got err %v", sizeVariation, err)
}
}
}
}
}
示例2: ProductShow
func ProductShow(ctx *gin.Context) {
var (
product models.Product
colorVariation models.ColorVariation
seoSetting models.SEOSetting
codes = strings.Split(ctx.Param("code"), "_")
productCode = codes[0]
colorCode string
)
if len(codes) > 1 {
colorCode = codes[1]
}
if DB(ctx).Where(&models.Product{Code: productCode}).First(&product).RecordNotFound() {
http.Redirect(ctx.Writer, ctx.Request, "/", http.StatusFound)
}
DB(ctx).Preload("Product").Preload("Color").Preload("SizeVariations.Size").Where(&models.ColorVariation{ProductID: product.ID, ColorCode: colorCode}).First(&colorVariation)
DB(ctx).First(&seoSetting)
config.View.Funcs(funcsMap(ctx)).Execute(
"product_show",
gin.H{
"ActionBarTag": admin.ActionBar.Render(ctx.Writer, ctx.Request),
"Product": product,
"ColorVariation": colorVariation,
"SeoTag": seoSetting.ProductPage.Render(seoSetting, product),
"MicroProduct": seo.MicroProduct{
Name: product.Name,
Description: product.Description,
BrandName: product.Category.Name,
SKU: product.Code,
Price: float64(product.Price),
Image: colorVariation.MainImageURL(),
}.Render(),
"CurrentUser": CurrentUser(ctx),
"CurrentLocale": CurrentLocale(ctx),
},
ctx.Request,
ctx.Writer,
)
}