filter less than 3 dimensions
This commit is contained in:
@ -14,12 +14,16 @@ type dimensionDispatcher struct {
|
||||
m *dimension.Matcher
|
||||
}
|
||||
|
||||
func (d dimensionDispatcher) isDimensionParam(value string) bool {
|
||||
return d.m.Match(value) != dimension.MatchResultMiss
|
||||
func pickFirst[T, V any](t T, v V) T {
|
||||
return t
|
||||
}
|
||||
|
||||
func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in *entity.GoodsItemSize) (updated bool) {
|
||||
matchResult := d.m.Match(key)
|
||||
func (d dimensionDispatcher) isDimensionParam(value string) bool {
|
||||
return pickFirst(d.m.Match(value)) != dimension.MatchResultMiss
|
||||
}
|
||||
|
||||
func (d dimensionDispatcher) applyDimensionValue(ctx context.Context, key, value string, in *entity.GoodsItemSize) (updated bool) {
|
||||
matchResult, priority := d.m.Match(key)
|
||||
if matchResult == dimension.MatchResultMiss {
|
||||
return false
|
||||
}
|
||||
@ -29,7 +33,7 @@ func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in
|
||||
if strings.Contains(value, "/") {
|
||||
dimensionValues := strings.Split(value, "/")
|
||||
for _, dv := range dimensionValues {
|
||||
updated = updated || d.dispatch(ctx, key, dv, in)
|
||||
updated = updated || d.applyDimensionValue(ctx, key, dv, in)
|
||||
}
|
||||
} else {
|
||||
out, err := entity.ParseDimention(value, entity.DimensionLocalRU)
|
||||
@ -42,10 +46,22 @@ func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in
|
||||
|
||||
switch matchResult {
|
||||
case dimension.MatchResultHeight:
|
||||
if !priority && in.Height.Value != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
in.Height = out
|
||||
case dimension.MatchResultLength:
|
||||
if !priority && in.Length.Value != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
in.Length = out
|
||||
case dimension.MatchResultWidth:
|
||||
if !priority && in.Width.Value != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
in.Width = out
|
||||
case dimension.MatchResultDepth:
|
||||
in.UnmatchedDepth = out
|
||||
|
||||
@ -144,7 +144,7 @@ func (h exportHandlers) YMLCatalog(ctx context.Context, cmd *cli.Command) error
|
||||
switch {
|
||||
case addToSkip(item.Description == "", reasonNoDescription, sublog):
|
||||
continue
|
||||
case addToSkip(item.Sizes == (entity.GoodsItemSize{}), reasonNoSize, sublog):
|
||||
case addToSkip(!item.Sizes.AllSizesSet(), reasonNoSize, sublog):
|
||||
continue
|
||||
case addToSkip(item.Sizes.GetSum(entity.DimensionKindCentimeter) > maximumAllowedSizes, reasonTooLarge, sublog):
|
||||
continue
|
||||
|
||||
@ -351,7 +351,7 @@ func (itemsHandlers) FixSizes(ctx context.Context, cmd *cli.Command) error {
|
||||
valueBeenUpdated = true
|
||||
}
|
||||
|
||||
if dimensionDispatcher.dispatch(ctx, key, value, &item.Sizes) {
|
||||
if dimensionDispatcher.applyDimensionValue(ctx, key, value, &item.Sizes) {
|
||||
valueBeenUpdated = true
|
||||
log.Debug().Str("key", key).Any("sizes", item.Sizes).Msg("been updated")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user