Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -579,7 +579,7 @@ func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router
|
||||
bindV3(r, pgDB,
|
||||
"/api/product-images/{id}/content", "GET",
|
||||
"order", "view",
|
||||
wrapV3(http.HandlerFunc(routes.GetProductImageContentHandler(pgDB))),
|
||||
http.HandlerFunc(routes.GetProductImageContentHandler(pgDB)),
|
||||
)
|
||||
|
||||
// ============================================================
|
||||
|
||||
@@ -161,6 +161,10 @@ func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
|
||||
if dim1 == "" {
|
||||
dim1 = strings.TrimSpace(r.URL.Query().Get("color"))
|
||||
}
|
||||
dim1ID := strings.TrimSpace(r.URL.Query().Get("dim1_id"))
|
||||
if dim1ID == "" {
|
||||
dim1ID = strings.TrimSpace(r.URL.Query().Get("itemdim1"))
|
||||
}
|
||||
dim3 := strings.TrimSpace(r.URL.Query().Get("dim3"))
|
||||
if dim3 == "" {
|
||||
dim3 = strings.TrimSpace(r.URL.Query().Get("yaka"))
|
||||
@@ -168,6 +172,10 @@ func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
|
||||
if dim3 == "" {
|
||||
dim3 = strings.TrimSpace(r.URL.Query().Get("renk2"))
|
||||
}
|
||||
dim3ID := strings.TrimSpace(r.URL.Query().Get("dim3_id"))
|
||||
if dim3ID == "" {
|
||||
dim3ID = strings.TrimSpace(r.URL.Query().Get("itemdim3"))
|
||||
}
|
||||
|
||||
if code == "" {
|
||||
|
||||
@@ -224,7 +232,9 @@ ORDER BY
|
||||
"req_id", reqID,
|
||||
"code", code,
|
||||
"dim1", dim1,
|
||||
"dim1_id", dim1ID,
|
||||
"dim3", dim3,
|
||||
"dim3_id", dim3ID,
|
||||
"err", err.Error(),
|
||||
)
|
||||
|
||||
@@ -240,7 +250,9 @@ ORDER BY
|
||||
matchedByName := make([]ProductImageItem, 0, 16)
|
||||
matchedByNameDim1Only := make([]ProductImageItem, 0, 16)
|
||||
dim1Upper := strings.ToUpper(strings.TrimSpace(dim1))
|
||||
dim1IDUpper := strings.ToUpper(strings.TrimSpace(dim1ID))
|
||||
dim3Upper := strings.ToUpper(strings.TrimSpace(dim3))
|
||||
dim3IDUpper := strings.ToUpper(strings.TrimSpace(dim3ID))
|
||||
|
||||
for rows.Next() {
|
||||
|
||||
@@ -264,12 +276,16 @@ ORDER BY
|
||||
rowDim1ByID[it.ID] = strings.TrimSpace(rowDim1)
|
||||
|
||||
dimMatched := true
|
||||
if dim1Upper != "" {
|
||||
if dim1IDUpper != "" {
|
||||
dimMatched = dimMatched && (rowDim1 == dim1IDUpper)
|
||||
} else if dim1Upper != "" {
|
||||
// Bazı eski kayıtlarda dimval1 gerçek renk kodu yerine numeric id tutulmuş olabilir.
|
||||
// Bu yüzden dimval karşılaştırması yardımcı; asıl fallback file_name token eşleşmesidir.
|
||||
dimMatched = dimMatched && (rowDim1 == dim1Upper)
|
||||
}
|
||||
if dim3Upper != "" {
|
||||
if dim3IDUpper != "" {
|
||||
dimMatched = dimMatched && (rowDim3 == dim3IDUpper || rowDim2 == dim3IDUpper)
|
||||
} else if dim3Upper != "" {
|
||||
dimMatched = dimMatched && (rowDim3 == dim3Upper || rowDim2 == dim3Upper)
|
||||
}
|
||||
if dimMatched {
|
||||
@@ -284,14 +300,14 @@ ORDER BY
|
||||
}
|
||||
}
|
||||
|
||||
if dim1Upper != "" || dim3Upper != "" {
|
||||
if dim3Upper != "" {
|
||||
if dim1Upper != "" || dim1IDUpper != "" || dim3Upper != "" || dim3IDUpper != "" {
|
||||
if dim3Upper != "" || dim3IDUpper != "" {
|
||||
// dim3 verildiginde kesin varyant listesi oncelikli.
|
||||
if len(matchedByName) > 0 {
|
||||
if dim3Upper != "" && len(matchedByName) > 0 {
|
||||
items = matchedByName
|
||||
} else if len(matchedByDim) > 0 {
|
||||
items = matchedByDim
|
||||
} else if len(matchedByNameDim1Only) > 0 {
|
||||
} else if dim3Upper != "" && len(matchedByNameDim1Only) > 0 {
|
||||
// dim3 pattern'i olmayan legacy tek-renk isimlerde dim1-only fallback.
|
||||
hasDim3Pattern := false
|
||||
for _, it := range matchedByNameDim1Only {
|
||||
@@ -321,36 +337,40 @@ ORDER BY
|
||||
items = []ProductImageItem{}
|
||||
}
|
||||
} else {
|
||||
targetDimval1 := make(map[string]struct{}, 4)
|
||||
for _, it := range matchedByName {
|
||||
if dv := rowDim1ByID[it.ID]; dv != "" {
|
||||
targetDimval1[dv] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(targetDimval1) == 0 {
|
||||
for _, it := range matchedByNameDim1Only {
|
||||
if dim1IDUpper != "" && len(matchedByDim) > 0 {
|
||||
items = matchedByDim
|
||||
} else {
|
||||
targetDimval1 := make(map[string]struct{}, 4)
|
||||
for _, it := range matchedByName {
|
||||
if dv := rowDim1ByID[it.ID]; dv != "" {
|
||||
targetDimval1[dv] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(targetDimval1) > 0 {
|
||||
clustered := make([]ProductImageItem, 0, len(items))
|
||||
for _, it := range items {
|
||||
if _, ok := targetDimval1[rowDim1ByID[it.ID]]; ok && filePrimaryMatchesDim1(it.FileName, dim1Upper) {
|
||||
clustered = append(clustered, it)
|
||||
if len(targetDimval1) == 0 {
|
||||
for _, it := range matchedByNameDim1Only {
|
||||
if dv := rowDim1ByID[it.ID]; dv != "" {
|
||||
targetDimval1[dv] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
items = clustered
|
||||
} else if len(matchedByDim) > 0 {
|
||||
items = matchedByDim
|
||||
} else if len(matchedByName) > 0 {
|
||||
items = matchedByName
|
||||
} else if len(matchedByNameDim1Only) > 0 {
|
||||
items = matchedByNameDim1Only
|
||||
} else {
|
||||
items = []ProductImageItem{}
|
||||
|
||||
if len(targetDimval1) > 0 {
|
||||
clustered := make([]ProductImageItem, 0, len(items))
|
||||
for _, it := range items {
|
||||
if _, ok := targetDimval1[rowDim1ByID[it.ID]]; ok && filePrimaryMatchesDim1(it.FileName, dim1Upper) {
|
||||
clustered = append(clustered, it)
|
||||
}
|
||||
}
|
||||
items = clustered
|
||||
} else if len(matchedByDim) > 0 {
|
||||
items = matchedByDim
|
||||
} else if len(matchedByName) > 0 {
|
||||
items = matchedByName
|
||||
} else if len(matchedByNameDim1Only) > 0 {
|
||||
items = matchedByNameDim1Only
|
||||
} else {
|
||||
items = []ProductImageItem{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -359,7 +379,9 @@ ORDER BY
|
||||
"req_id", reqID,
|
||||
"code", code,
|
||||
"dim1", dim1,
|
||||
"dim1_id", dim1ID,
|
||||
"dim3", dim3,
|
||||
"dim3_id", dim3ID,
|
||||
"count", len(items),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user