support datafields in projection
This commit is contained in:
1 parent
b128608316
commit
d04679daf5
4 files changed
+64
-7
No files matched your search
@@ -115,6 +115,23 @@ func Apply(s Schema, source map[string]any) (Projection, error) {
|
||||
truthy = DefaultTrueValues()
|
||||
}
|
||||
|
||||
var attrs json.RawMessage
|
||||
if len(s.AttributesFields) > 0 {
|
||||
m := make(map[string]any)
|
||||
for _, key := range s.AttributesFields {
|
||||
if val, ok := source[key]; ok && val != nil {
|
||||
m[key] = val
|
||||
}
|
||||
}
|
||||
if len(m) > 0 {
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return Projection{}, fmt.Errorf("%w: marshal attributes: %w", ErrProjectionBuild, err)
|
||||
}
|
||||
attrs = b
|
||||
}
|
||||
}
|
||||
|
||||
p := Projection{
|
||||
ItemID: uint32Of(source, s.ItemIdField),
|
||||
ID: id,
|
||||
@@ -122,6 +139,7 @@ func Apply(s Schema, source map[string]any) (Projection, error) {
|
||||
Title: stringOf(source, s.TitleField),
|
||||
PriceIncVat: price,
|
||||
Currency: cur,
|
||||
Attributes: attrs,
|
||||
TaxClass: tax,
|
||||
InventoryTracked: boolOf(source, s.InventoryTrackedF, truthy),
|
||||
DropShip: boolOf(source, s.DropShipF, truthy),
|
||||
|
||||
Reference in new issue
Block a user