Exemple #1
0
func ConvertProductsToViewModel(product models.Product) viewmodels.Product {

	result := viewmodels.Product{
		Id:          product.Id(),
		ImageUrl:    product.ImageUrl(),
		Name:        product.Name(),
		Type:        product.Typ(),
		Description: product.Description(),
		Price:       product.Price(),
	}

	return result
}
Exemple #2
0
func ConvertProductToViewModel(product models.Product) viewmodels.Product {
	result := viewmodels.Product{
		Name:             product.Name(),
		DescriptionShort: product.DescriptionShort(),
		DescriptionLong:  product.DescriptionLong(),
		PricePerLitre:    product.PricePerLitre(),
		PricePer10Litre:  product.PricePer10Litre(),
		Origin:           product.Origin(),
		IsOrganic:        product.IsOrganic(),
		ImageUrl:         product.ImageUrl(),
		Id:               product.Id(),
	}

	return result
}
Exemple #3
0
func Test_ConvertsProductToViewModel(t *testing.T) {
	product := models.Product{}
	product.SetName("the name")
	product.SetDescriptionShort("the short description")
	product.SetDescriptionLong("the long description")
	product.SetPricePerLitre(42.127)
	product.SetPricePer10Litre(27.314)
	product.SetOrigin("the origin")
	product.SetIsOrganic(true)
	product.SetImageUrl("the image URL")
	product.SetId(42)

	result := ConvertProductToViewModel(product)

	if product.Name() != result.Name {
		t.Fail()
	}
	if product.DescriptionShort() != result.DescriptionShort {
		t.Fail()
	}
	if product.DescriptionLong() != result.DescriptionLong {
		t.Fail()
	}
	if product.PricePerLitre() != result.PricePerLitre {
		t.Fail()
	}
	if product.PricePer10Litre() != result.PricePer10Litre {
		t.Fail()
	}
	if product.Origin() != result.Origin {
		t.Fail()
	}
	if product.IsOrganic() != result.IsOrganic {
		t.Fail()
	}
	if product.ImageUrl() != result.ImageUrl {
		t.Fail()
	}
	if product.Id() != result.Id {
		t.Fail()
	}
}
Exemple #4
0
func EnsureData(w http.ResponseWriter, c appengine.Context) {
	q := datastore.NewQuery("Product").Ancestor(productKey(c)).Limit(1)
	products := make([]models.Product, 0, 1)
	if _, err := q.GetAll(c, &products); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	var prodExists bool = false

	// if you only need e:
	for _, e := range products {
		c.Infof("Product:%v", e)
		prodExists = true
		break
	}

	if !prodExists {
		prod := new(models.Product)
		prod.Height = "6 - 8 inches"
		prod.HardinessZone = "4 - 9"
		prod.BloomTime = "May - June"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Strawberry-Gasana.JPG"
		prod.Description = "Everbearing. Great for containers! Or in the ground."
		prod.Name = "FRAGARIA (STRAWBERRY)  ‘GASANA’"
		prod.Class = "Fruit Crops"
		prod.Light = "Sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.68"

		InsertProduct(c, *prod, w)

		prod = new(models.Product)
		prod.Height = "6 - 8 inches"
		prod.HardinessZone = "4 - 9"
		prod.BloomTime = "May - June"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Strawberry-Gasana.JPG"
		prod.Description = "Everbearing. Great for containers! Or in the ground."
		prod.Name = "FRAGARIA (STRAWBERRY)  ‘GASANA’"
		prod.Class = "Fruit Crops"
		prod.Light = "Sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.68"

		InsertProduct(c, *prod, w)

		prod = new(models.Product)
		prod.Height = "9 - 12 inches"
		prod.HardinessZone = "4 - 8"
		prod.BloomTime = "Early Spring, Summer, Fall"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Achillea-Little-Moonshine-(2).JPG"
		prod.Description = "This exciting new introduction from Blooms of Bressingham has the bright yellow flowers of 'Moonshine' but at half the height! Great for containers and in the front of the border."
		prod.Name = "ACHILLEA  ‘LITTLE MOONSHINE’"
		prod.Class = "Hardy Perennials"
		prod.Light = "full sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.65"
		prod.Royalty = "$.16"
		prod.Colors = "Vibrant Yellow"
		prod.PatentStatus = "USPPAF"
		InsertProduct(c, *prod, w)

		prod = new(models.Product)
		prod.Height = "12 inches"
		prod.HardinessZone = "4 - 9"
		prod.BloomTime = "May - July"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Achillea-New-Vinage-Red-(4).JPG"
		prod.Description = "This new series from Ball Seed offers a compact and tidy habit with deep red flowers all summer."
		prod.Name = "ACHILLEA  NEW VINTAGE™ SERIES ‘RED’"
		prod.Class = "Hardy Perennials"
		prod.Light = "full sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.62"
		prod.Royalty = "$.08"
		prod.Colors = "Deep Red"
		prod.PatentStatus = "USPPAF"
		InsertProduct(c, *prod, w)
	}

}