filter less than 3 dimensions
This commit is contained in:
@ -14,12 +14,16 @@ type dimensionDispatcher struct {
|
|||||||
m *dimension.Matcher
|
m *dimension.Matcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dimensionDispatcher) isDimensionParam(value string) bool {
|
func pickFirst[T, V any](t T, v V) T {
|
||||||
return d.m.Match(value) != dimension.MatchResultMiss
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in *entity.GoodsItemSize) (updated bool) {
|
func (d dimensionDispatcher) isDimensionParam(value string) bool {
|
||||||
matchResult := d.m.Match(key)
|
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 {
|
if matchResult == dimension.MatchResultMiss {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -29,7 +33,7 @@ func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in
|
|||||||
if strings.Contains(value, "/") {
|
if strings.Contains(value, "/") {
|
||||||
dimensionValues := strings.Split(value, "/")
|
dimensionValues := strings.Split(value, "/")
|
||||||
for _, dv := range dimensionValues {
|
for _, dv := range dimensionValues {
|
||||||
updated = updated || d.dispatch(ctx, key, dv, in)
|
updated = updated || d.applyDimensionValue(ctx, key, dv, in)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out, err := entity.ParseDimention(value, entity.DimensionLocalRU)
|
out, err := entity.ParseDimention(value, entity.DimensionLocalRU)
|
||||||
@ -42,10 +46,22 @@ func (d dimensionDispatcher) dispatch(ctx context.Context, key, value string, in
|
|||||||
|
|
||||||
switch matchResult {
|
switch matchResult {
|
||||||
case dimension.MatchResultHeight:
|
case dimension.MatchResultHeight:
|
||||||
|
if !priority && in.Height.Value != 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
in.Height = out
|
in.Height = out
|
||||||
case dimension.MatchResultLength:
|
case dimension.MatchResultLength:
|
||||||
|
if !priority && in.Length.Value != 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
in.Length = out
|
in.Length = out
|
||||||
case dimension.MatchResultWidth:
|
case dimension.MatchResultWidth:
|
||||||
|
if !priority && in.Width.Value != 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
in.Width = out
|
in.Width = out
|
||||||
case dimension.MatchResultDepth:
|
case dimension.MatchResultDepth:
|
||||||
in.UnmatchedDepth = out
|
in.UnmatchedDepth = out
|
||||||
|
|||||||
@ -144,7 +144,7 @@ func (h exportHandlers) YMLCatalog(ctx context.Context, cmd *cli.Command) error
|
|||||||
switch {
|
switch {
|
||||||
case addToSkip(item.Description == "", reasonNoDescription, sublog):
|
case addToSkip(item.Description == "", reasonNoDescription, sublog):
|
||||||
continue
|
continue
|
||||||
case addToSkip(item.Sizes == (entity.GoodsItemSize{}), reasonNoSize, sublog):
|
case addToSkip(!item.Sizes.AllSizesSet(), reasonNoSize, sublog):
|
||||||
continue
|
continue
|
||||||
case addToSkip(item.Sizes.GetSum(entity.DimensionKindCentimeter) > maximumAllowedSizes, reasonTooLarge, sublog):
|
case addToSkip(item.Sizes.GetSum(entity.DimensionKindCentimeter) > maximumAllowedSizes, reasonTooLarge, sublog):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -351,7 +351,7 @@ func (itemsHandlers) FixSizes(ctx context.Context, cmd *cli.Command) error {
|
|||||||
valueBeenUpdated = true
|
valueBeenUpdated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if dimensionDispatcher.dispatch(ctx, key, value, &item.Sizes) {
|
if dimensionDispatcher.applyDimensionValue(ctx, key, value, &item.Sizes) {
|
||||||
valueBeenUpdated = true
|
valueBeenUpdated = true
|
||||||
log.Debug().Str("key", key).Any("sizes", item.Sizes).Msg("been updated")
|
log.Debug().Str("key", key).Any("sizes", item.Sizes).Msg("been updated")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,25 +50,29 @@ func makeMatcherByConig(insensitive bool, cfgs ...config.MatcherPredicate) match
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Matcher) Match(value string) MatchResult {
|
func (m *Matcher) Match(value string) (r MatchResult, priority bool) {
|
||||||
switch {
|
switch {
|
||||||
case value == "Высота":
|
case value == "Высота":
|
||||||
|
priority = true
|
||||||
fallthrough
|
fallthrough
|
||||||
case m.height.Match(value):
|
case m.height.Match(value):
|
||||||
return MatchResultHeight
|
return MatchResultHeight, priority
|
||||||
case value == "Глубина":
|
case value == "Глубина":
|
||||||
return MatchResultDepth
|
priority = true
|
||||||
|
return MatchResultDepth, priority
|
||||||
case value == "Длина":
|
case value == "Длина":
|
||||||
|
priority = true
|
||||||
fallthrough
|
fallthrough
|
||||||
case m.length.Match(value):
|
case m.length.Match(value):
|
||||||
return MatchResultLength
|
return MatchResultLength, priority
|
||||||
case value == "Ширина":
|
case value == "Ширина":
|
||||||
|
priority = true
|
||||||
fallthrough
|
fallthrough
|
||||||
case m.width.Match(value):
|
case m.width.Match(value):
|
||||||
return MatchResultWidth
|
return MatchResultWidth, priority
|
||||||
}
|
}
|
||||||
|
|
||||||
return MatchResultMiss
|
return MatchResultMiss, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Matcher) GetRegisteredPatterns() map[string][]string {
|
func (m *Matcher) GetRegisteredPatterns() map[string][]string {
|
||||||
|
|||||||
@ -52,6 +52,22 @@ func FixupSizes(s GoodsItemSize) (GoodsItemSize, bool) {
|
|||||||
return s, true
|
return s, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s GoodsItemSize) AllSizesSet() bool {
|
||||||
|
var count int
|
||||||
|
for _, d := range []Dimension{
|
||||||
|
s.Width,
|
||||||
|
s.Height,
|
||||||
|
s.Length,
|
||||||
|
s.UnmatchedDepth,
|
||||||
|
} {
|
||||||
|
if d.IsZero() {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count >= 3
|
||||||
|
}
|
||||||
|
|
||||||
func (s GoodsItemSize) GetSum(kind DimensionKind) float64 {
|
func (s GoodsItemSize) GetSum(kind DimensionKind) float64 {
|
||||||
var value float64
|
var value float64
|
||||||
sum := func(ds ...Dimension) {
|
sum := func(ds ...Dimension) {
|
||||||
|
|||||||
@ -403,7 +403,10 @@ func (c *client) getProductInfo(ctx context.Context, cartID int64) (pi entity.Go
|
|||||||
Find(galleryPanelSelector).
|
Find(galleryPanelSelector).
|
||||||
Find(galleryImageSelector).
|
Find(galleryImageSelector).
|
||||||
Each(func(i int, s *goquery.Selection) {
|
Each(func(i int, s *goquery.Selection) {
|
||||||
imageURL, ok := s.Attr("src")
|
imageURL, ok := s.Attr("data-src")
|
||||||
|
if !ok {
|
||||||
|
imageURL, ok = s.Attr("src")
|
||||||
|
}
|
||||||
if !ok || len(imageURL) == 0 {
|
if !ok || len(imageURL) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user