Browse Source

EDIT: product information

portowyi 1 year ago
parent
commit
dc6c8e5549
3 changed files with 50 additions and 8 deletions
  1. 7 2
      controller/products.go
  2. 36 6
      cron-job/cronJobs.go
  3. 7 0
      model/product.go

+ 7 - 2
controller/products.go

@@ -10,7 +10,6 @@ import (
 func LoadProductsInfo(context *gin.Context) {
 	var products model.ProductsArray
 	err := context.ShouldBindJSON(&products)
-
 	if err != nil {
 		context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
 		return
@@ -35,6 +34,13 @@ func LoadProductsInfo(context *gin.Context) {
 			NumberSuffix:  prod.NumberSuffix,
 			CategoryId:    prod.CategoryId,
 			IdNumbers:     prod.IdNumbers,
+			Certificates:  prod.Certificates,
+			Multiple:      prod.Multiple,
+			Length:        prod.Length,
+			Weight:        prod.Weight,
+			Height:        prod.Height,
+			Width:         prod.Width,
+			Deficit:       prod.Deficit,
 		}
 		_, err := product.Save()
 		if err != nil {
@@ -44,5 +50,4 @@ func LoadProductsInfo(context *gin.Context) {
 	}
 
 	context.JSON(http.StatusCreated, gin.H{"ok": "Saved"})
-
 }

+ 36 - 6
cron-job/cronJobs.go

@@ -16,8 +16,6 @@ import (
 
 func CreateXMLFeed() {
 
-	const CrossDockingCategoryId = "999"
-
 	type Category struct {
 		Text     string `xml:",chardata"`
 		Id       string `xml:"id,attr"`
@@ -32,7 +30,7 @@ func CreateXMLFeed() {
 
 	type Offer struct {
 		Id         string  `xml:"id,attr"`
-		Avalieble  string  `xml:"available,attr"`
+		Available  string  `xml:"available,attr"`
 		Name       string  `xml:"name"`
 		URL        string  `xml:"url"`
 		CategoryId string  `xml:"categoryId"`
@@ -85,7 +83,6 @@ func CreateXMLFeed() {
 		shop.Category = append(shop.Category, category)
 	}
 
-	// +++ Предопределенная категория для кросс-докинга
 	var categoryCrossDocking = Category{
 		Text:     "Кросс-Докинг",
 		ParentId: "1",
@@ -93,12 +90,11 @@ func CreateXMLFeed() {
 		URL:      "999",
 	}
 	shop.Category = append(shop.Category, categoryCrossDocking)
-	// --- Предопределенная категория для кросс-докинга
 
 	for _, value := range rows {
 		var offer = Offer{
 			Id:         value.CodeCarCaDe,
-			Avalieble:  "true",
+			Available:  "true",
 			Name:       value.Name,
 			URL:        "https://b2bn.kngnn.ru/?item-code=" + value.CodeUT10,
 			CategoryId: value.CategoryId,
@@ -170,6 +166,30 @@ func CreateXMLFeed() {
 			Text: value.NumberSuffix,
 			Name: "number_suffix",
 		})
+		offer.Param = append(offer.Param, Param{
+			Text: strconv.FormatBool(value.Deficit),
+			Name: "deficit",
+		})
+		offer.Param = append(offer.Param, Param{
+			Text: strconv.FormatFloat(value.Width, 'f', 6, 64),
+			Name: "width",
+		})
+		offer.Param = append(offer.Param, Param{
+			Text: strconv.FormatFloat(value.Height, 'f', 6, 64),
+			Name: "height",
+		})
+		offer.Param = append(offer.Param, Param{
+			Text: strconv.FormatFloat(value.Weight, 'f', 6, 64),
+			Name: "weight",
+		})
+		offer.Param = append(offer.Param, Param{
+			Text: strconv.FormatFloat(value.Length, 'f', 6, 64),
+			Name: "length",
+		})
+		offer.Param = append(offer.Param, Param{
+			Text: strconv.FormatFloat(value.Multiple, 'f', 6, 64),
+			Name: "multiple",
+		})
 
 		if value.IdNumbers != nil {
 			numbers := strings.Split(*value.IdNumbers, ";")
@@ -181,6 +201,16 @@ func CreateXMLFeed() {
 			}
 		}
 
+		if value.Certificates != nil {
+			certificates := strings.Split(*value.IdNumbers, ";")
+			for idx, cert := range certificates {
+				offer.Param = append(offer.Param, Param{
+					Text: cert,
+					Name: "certificate" + strconv.Itoa(idx+1),
+				})
+			}
+		}
+
 		shop.Offer = append(shop.Offer, offer)
 
 	}

+ 7 - 0
model/product.go

@@ -21,6 +21,13 @@ type Product struct {
 	NumberArticle string  `gorm:"size:25" json:"number_article"`
 	NumberSuffix  string  `gorm:"size:3" json:"number_suffix"`
 	CategoryId    string  `gorm:"size:5" json:"categoryId"`
+	Deficit       bool    `json:"deficit"`
+	Weight        float64 `json:"weight"`
+	Height        float64 `json:"height"`
+	Length        float64 `json:"length"`
+	Width         float64 `json:"width"`
+	Multiple      float64 `json:"multiple"`
+	Certificates  *string `gorm:"type:text" json:"certificates"`
 	IdNumbers     *string `gorm:"size:256" json:"id_numbers"`
 }