@@ -843,7 +843,7 @@ func (l *Listing) UpdateCouponsFromDatastore(cdb couponGetter) error {
843
843
if err != nil {
844
844
return fmt .Errorf ("loading datastore coupon: %s" , err .Error ())
845
845
}
846
- for _ , c := range coupons {
846
+ for i , c := range coupons {
847
847
for _ , dbc := range dbCoupons {
848
848
if c .redemptionHash == dbc .Hash {
849
849
// make sure applying code does not shift already-matched hash
@@ -854,12 +854,13 @@ func (l *Listing) UpdateCouponsFromDatastore(cdb couponGetter) error {
854
854
if c .redemptionHash != expectedHash .B58String () {
855
855
return fmt .Errorf ("update coupon code (%s) results in mismatched published hash" , dbc .Code )
856
856
}
857
- if err := c .SetRedemptionCode (dbc .Code ); err != nil {
857
+ if err := coupons [ i ] .SetRedemptionCode (dbc .Code ); err != nil {
858
858
return fmt .Errorf ("setting redemption code: %s" , err .Error ())
859
859
}
860
860
}
861
861
}
862
862
}
863
+ l .listingProto .Coupons = coupons .GetProtobuf ()
863
864
return nil
864
865
}
865
866
@@ -920,11 +921,14 @@ func (cs ListingCoupons) GetProtobuf() []*pb.Listing_Coupon {
920
921
cspb [i ] = & pb.Listing_Coupon {
921
922
Title : c .GetTitle (),
922
923
PercentDiscount : c .GetPercentOff (),
923
- BigPriceDiscount : c .GetAmountOff ().Amount .String (),
924
+ }
925
+ if c .GetAmountOff () != nil {
926
+ cspb [i ].BigPriceDiscount = c .GetAmountOff ().Amount .String ()
924
927
}
925
928
if hash , err := c .GetRedemptionHash (); err == nil {
926
929
cspb [i ].Code = & pb.Listing_Coupon_Hash {Hash : hash }
927
- } else if code , err := c .GetRedemptionCode (); err == nil {
930
+ }
931
+ if code , err := c .GetRedemptionCode (); err == nil {
928
932
cspb [i ].Code = & pb.Listing_Coupon_DiscountCode {DiscountCode : code }
929
933
}
930
934
}
0 commit comments