filter less than 3 dimensions

This commit is contained in:
Aleksandr Trushkin
2024-02-23 14:55:02 +03:00
parent fd9e5ade18
commit 5a10d21689
6 changed files with 53 additions and 14 deletions

View File

@ -50,25 +50,29 @@ func makeMatcherByConig(insensitive bool, cfgs ...config.MatcherPredicate) match
return m
}
func (m *Matcher) Match(value string) MatchResult {
func (m *Matcher) Match(value string) (r MatchResult, priority bool) {
switch {
case value == "Высота":
priority = true
fallthrough
case m.height.Match(value):
return MatchResultHeight
return MatchResultHeight, priority
case value == "Глубина":
return MatchResultDepth
priority = true
return MatchResultDepth, priority
case value == "Длина":
priority = true
fallthrough
case m.length.Match(value):
return MatchResultLength
return MatchResultLength, priority
case value == "Ширина":
priority = true
fallthrough
case m.width.Match(value):
return MatchResultWidth
return MatchResultWidth, priority
}
return MatchResultMiss
return MatchResultMiss, false
}
func (m *Matcher) GetRegisteredPatterns() map[string][]string {

View File

@ -52,6 +52,22 @@ func FixupSizes(s GoodsItemSize) (GoodsItemSize, bool) {
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 {
var value float64
sum := func(ds ...Dimension) {

View File

@ -403,7 +403,10 @@ func (c *client) getProductInfo(ctx context.Context, cartID int64) (pi entity.Go
Find(galleryPanelSelector).
Find(galleryImageSelector).
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 {
return
}