i-love-flamingo / flamingo-commerce

Flexible E-Commerce Framework on top of Flamingo. Used to build E-Commerce "Portals" and connect it with the help of individual Adapters to other services.

Home Page:https://www.flamingo.me/flamingo-commerce.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different formatting of attribute values returned by Value() and Values() of Attribute of BasicProductData

richard-ra opened this issue · comments

Hi.
While investigating a bug which was caused by the fact that Value() returns the raw value of the attribute but with whitespaces trimmed on both ends, I noticed that the Values() method returns a list of attribute values but the values do not have the whitespaces removed.

func (at Attribute) Value() string {
return strings.Trim(fmt.Sprintf("%v", at.RawValue), " ")
}

and

func (at Attribute) Values() []string {
var result []string
list, ok := at.RawValue.([]interface{})
if ok {
for _, entry := range list {
result = append(result, fmt.Sprintf("%v", entry))
}
}
return result
}

Hey
Thanks that is inconsitent.
See attached PR for a fix.

You had problems with the Trimming in general?

(We are planning to adjust the attribute modelling in the future simelar to the attributs model in caegory - but since this is breaking thats up for v4)

Hi,

The only reason I realised that Value() returns the value with trimmed whitespaces was because we have the case where we compare the return value of Value() to the attribute value/s in 'variantVariationAttributesSorting':

VariantVariationAttributesSorting map[string][]string

Since the source of the attribute data is the same, this means that when the comparison happened, we never got a match if the attribute value had a ' ' at the beginning or end. The solution in this case was to also trim whitespaces for the attribute values in 'variantVariationAttributesSorting' before comparing.

Furthermore, this issue only occurred because of a user error when managing the attribute value in the PIM where a whitespace was entered at the beginning of the value by mistake.

Thank you and let me know if there are any more questions

Hey thank you for the Details.
So the attached branch should fix that right?

Any other support needed please let us know

I looked at it and it looks fine but isn't the newly added 'else' statement a breaking change as currently "Values()" returns an empty array if rawValue is a single value and that statement would make the array always contain a value? I'm currently doing frontend development (at AOE) so go is not my strong suit so I might be wrong.