@@ -30,7 +30,7 @@ func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*pro
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
amount, err := calcItemAmount(
|
||||
amount, amountOld, err := calcItemAmount(
|
||||
&ProductAndCount{
|
||||
product: product,
|
||||
count: item.Count,
|
||||
@@ -51,13 +51,17 @@ func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*pro
|
||||
Inventory: product.Inventory,
|
||||
Count: item.Count,
|
||||
Amount: amount,
|
||||
AmountOld: amountOld,
|
||||
Variants: product.Variants,
|
||||
Labels: product.Labels,
|
||||
},
|
||||
)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func calcItemAmount(item *ProductAndCount) (int64, error) {
|
||||
func calcItemAmount(item *ProductAndCount) (int64, int64, error) {
|
||||
variantOld := item.product.Variants[0]
|
||||
var variant *proto.Variant
|
||||
for _, v := range item.product.Variants {
|
||||
check := true
|
||||
@@ -65,7 +69,7 @@ func calcItemAmount(item *ProductAndCount) (int64, error) {
|
||||
if property.Name == "min" {
|
||||
minBorder, err := strconv.ParseInt(property.Value, 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, 0, err
|
||||
}
|
||||
if item.count < minBorder {
|
||||
check = false
|
||||
@@ -74,7 +78,7 @@ func calcItemAmount(item *ProductAndCount) (int64, error) {
|
||||
if property.Name == "max" {
|
||||
maxBorder, err := strconv.ParseInt(property.Value, 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, 0, err
|
||||
}
|
||||
if item.count > maxBorder {
|
||||
check = false
|
||||
@@ -86,8 +90,9 @@ func calcItemAmount(item *ProductAndCount) (int64, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
variant.Active = true
|
||||
if variant == nil {
|
||||
return 0, errors.New("variant not found")
|
||||
return 0, 0, errors.New("variant not found")
|
||||
}
|
||||
return variant.Price * item.count, nil
|
||||
return variant.Price * item.count, variantOld.Price * item.count, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user