本文整理汇总了Golang中github.com/qor/qor-example/app/models.ColorVariation.ProductID方法的典型用法代码示例。如果您正苦于以下问题:Golang ColorVariation.ProductID方法的具体用法?Golang ColorVariation.ProductID怎么用?Golang ColorVariation.ProductID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/qor/qor-example/app/models.ColorVariation
的用法示例。
在下文中一共展示了ColorVariation.ProductID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
}
}
}