Example #1
0
func (s *ProductService) UpdateProduct(product *model.Product) {
	if product == nil {
		return
	}
	// update product information
	product.Capital = s.getCapital(product.Name)
	if _, err := productdao.UpdateProduct(product); err != nil {
		panic(err.Error())
	}

	// update it's properties
	if product.Colors != nil {
		productdao.UpdateProductProperties(product.Id, "color", product.Colors...)
	}
	if product.Sizes != nil {
		productdao.UpdateProductProperties(product.Id, "size", product.Sizes...)
	}

	// update stock information
	if product.Stocks != nil {
		// TODO change to edit/create/delete;
		inventorydao.ClearProductStock(product.Id) // clear
		product.Stocks.Loop(func(color, size string, stock int) {
			inventorydao.SetProductStock(product.Id, color, size, stock)
		})
	}

	// update suggest
	fmt.Println("^^^^^^ update product, ", product)
	fmt.Println("Productid is: ", product.ProductId)
	suggest.Update(suggest.Product, product.Name, product.Id, product.ProductId)

}
Example #2
0
// --------------------------------------------------------------------------------
func (s *ProductService) RebuildProductPinyinCapital() {
	fmt.Println("________________________________________________________________________________")
	fmt.Println("Rebuild Product Capital")

	qp := db.NewQueryParser().Limit(10000).Where()
	products, err := s.List(qp, 0)
	if err != nil {
		panic(err.Error())
	}
	for _, product := range products {
		product.Capital = s.getCapital(product.Name)
		if _, err := productdao.UpdateProduct(product); err != nil {
			panic(err.Error())
		}
		fmt.Printf("> processing %v capital is: %v\n", product.Name, product.Capital)
	}
	fmt.Println("all done")
}