mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat: add DistributionProductDetailJSON to GroupBrandProductItemRecord and update related logic
This commit is contained in:
parent
e4e16458a0
commit
16b2703cba
@ -407,8 +407,9 @@ type GroupBrandProductRecord struct {
|
||||
|
||||
// GroupBrandProductItemRecord is one product and its SPU number in a brand group.
|
||||
type GroupBrandProductItemRecord struct {
|
||||
ProductID string
|
||||
SPUNo string
|
||||
ProductID string
|
||||
SPUNo string
|
||||
DistributionProductDetailJSON string
|
||||
}
|
||||
|
||||
// CreateCatalogCategoryTree inserts a catalog-category subtree of arbitrary
|
||||
@ -4543,7 +4544,8 @@ SELECT c.id,
|
||||
ELSE b.name
|
||||
END AS brand_name,
|
||||
p.id,
|
||||
COALESCE(p.spu_no, '') AS spu_no
|
||||
COALESCE(p.spu_no, '') AS spu_no,
|
||||
p.distribution_product_detail::text
|
||||
FROM product.catalog_category AS c
|
||||
JOIN product.product_catalog_bindings AS binding ON binding.category_id = c.id
|
||||
AND binding.deleted_at IS NULL
|
||||
@ -4585,8 +4587,8 @@ ORDER BY c.id ASC,
|
||||
lastBrandKey := make(map[string]string, len(groupsByID))
|
||||
for rows.Next() {
|
||||
var groupID, brandID, productID int64
|
||||
var name, spuNo string
|
||||
if err := rows.Scan(&groupID, &brandID, &name, &productID, &spuNo); err != nil {
|
||||
var name, spuNo, distributionProductDetailJSON string
|
||||
if err := rows.Scan(&groupID, &brandID, &name, &productID, &spuNo, &distributionProductDetailJSON); err != nil {
|
||||
return fmt.Errorf("scan group brand product: %w", err)
|
||||
}
|
||||
groupKey := formatID(groupID)
|
||||
@ -4609,8 +4611,9 @@ ORDER BY c.id ASC,
|
||||
}
|
||||
brand := &group.BrandProducts[len(group.BrandProducts)-1]
|
||||
brand.Products = append(brand.Products, GroupBrandProductItemRecord{
|
||||
ProductID: formatID(productID),
|
||||
SPUNo: spuNo,
|
||||
ProductID: formatID(productID),
|
||||
SPUNo: spuNo,
|
||||
DistributionProductDetailJSON: distributionProductDetailJSON,
|
||||
})
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
|
||||
@ -48,11 +48,13 @@ func TestGroupNodeIncludesBrandProductsOnlyForLeafGroups(t *testing.T) {
|
||||
BrandID: "3001",
|
||||
BrandName: "Brand",
|
||||
Products: []repository.GroupBrandProductItemRecord{{
|
||||
ProductID: "2002",
|
||||
SPUNo: "SPU-2",
|
||||
ProductID: "2002",
|
||||
SPUNo: "SPU-2",
|
||||
DistributionProductDetailJSON: `{"channel":"partner"}`,
|
||||
}, {
|
||||
ProductID: "2001",
|
||||
SPUNo: "SPU-1",
|
||||
ProductID: "2001",
|
||||
SPUNo: "SPU-1",
|
||||
DistributionProductDetailJSON: `[1,2]`,
|
||||
}},
|
||||
}},
|
||||
})
|
||||
@ -62,6 +64,9 @@ func TestGroupNodeIncludesBrandProductsOnlyForLeafGroups(t *testing.T) {
|
||||
if got := leaf.GetBrands()[0].GetProducts(); len(got) != 2 || got[0].GetProductId() != "2002" || got[0].GetSpuNo() != "SPU-2" || got[1].GetProductId() != "2001" || got[1].GetSpuNo() != "SPU-1" {
|
||||
t.Fatalf("brand products = %#v", got)
|
||||
}
|
||||
if got := leaf.GetBrands()[0].GetProducts(); got[0].GetDistributionProductDetail() != `{"channel":"partner"}` || got[1].GetDistributionProductDetail() != `[1,2]` {
|
||||
t.Fatalf("distribution product details = %#v", got)
|
||||
}
|
||||
|
||||
emptyLeaf := toProtoGroupNode(&repository.CategoryRecord{ID: "1003", Level: 2, IsLeaf: true})
|
||||
if got := emptyLeaf.GetBrands(); got == nil || len(got) != 0 {
|
||||
|
||||
@ -3296,8 +3296,9 @@ func toProtoGroupNode(group *repository.CategoryRecord) *productv1.GroupNode {
|
||||
protoBrand.Products = make([]*productv1.GroupBrandProduct, 0, len(brand.Products))
|
||||
for _, product := range brand.Products {
|
||||
protoBrand.Products = append(protoBrand.Products, &productv1.GroupBrandProduct{
|
||||
ProductId: product.ProductID,
|
||||
SpuNo: product.SPUNo,
|
||||
ProductId: product.ProductID,
|
||||
SpuNo: product.SPUNo,
|
||||
DistributionProductDetail: product.DistributionProductDetailJSON,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user