add description all the way
This commit is contained in:
@@ -92,10 +92,12 @@ type CartGrain struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Voucher struct {
|
type Voucher struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Rules []string `json:"rules"`
|
Applied bool `json:"applied"`
|
||||||
Id uint32 `json:"id"`
|
Rules []string `json:"rules"`
|
||||||
Value int64 `json:"value"`
|
Description string `json:"description,omitempty"`
|
||||||
|
Id uint32 `json:"id"`
|
||||||
|
Value int64 `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Voucher) AppliesTo(cart *CartGrain) ([]*CartItem, bool) {
|
func (v *Voucher) AppliesTo(cart *CartGrain) ([]*CartItem, bool) {
|
||||||
@@ -270,13 +272,15 @@ func (c *CartGrain) UpdateTotals() {
|
|||||||
c.TotalPrice.Add(delivery.Price)
|
c.TotalPrice.Add(delivery.Price)
|
||||||
}
|
}
|
||||||
for _, voucher := range c.Vouchers {
|
for _, voucher := range c.Vouchers {
|
||||||
if _, ok := voucher.AppliesTo(c); ok {
|
_, ok := voucher.AppliesTo(c)
|
||||||
|
voucher.Applied = false
|
||||||
|
if ok {
|
||||||
value := NewPriceFromIncVat(voucher.Value, 25)
|
value := NewPriceFromIncVat(voucher.Value, 25)
|
||||||
if c.TotalPrice.IncVat <= value.IncVat {
|
if c.TotalPrice.IncVat <= value.IncVat {
|
||||||
// don't apply discounts to more than the total price
|
// don't apply discounts to more than the total price
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
voucher.Applied = true
|
||||||
c.TotalDiscount.Add(*value)
|
c.TotalDiscount.Add(*value)
|
||||||
c.TotalPrice.Subtract(*value)
|
c.TotalPrice.Subtract(*value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -931,6 +931,7 @@ type AddVoucher struct {
|
|||||||
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
|
Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
|
||||||
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
|
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
|
||||||
VoucherRules []string `protobuf:"bytes,3,rep,name=voucherRules,proto3" json:"voucherRules,omitempty"`
|
VoucherRules []string `protobuf:"bytes,3,rep,name=voucherRules,proto3" json:"voucherRules,omitempty"`
|
||||||
|
Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@@ -986,6 +987,13 @@ func (x *AddVoucher) GetVoucherRules() []string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *AddVoucher) GetDescription() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Description
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type RemoveVoucher struct {
|
type RemoveVoucher struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
@@ -1267,12 +1275,13 @@ const file_messages_proto_rawDesc = "" +
|
|||||||
"\x12InitializeCheckout\x12\x18\n" +
|
"\x12InitializeCheckout\x12\x18\n" +
|
||||||
"\aorderId\x18\x01 \x01(\tR\aorderId\x12\x16\n" +
|
"\aorderId\x18\x01 \x01(\tR\aorderId\x12\x16\n" +
|
||||||
"\x06status\x18\x02 \x01(\tR\x06status\x12,\n" +
|
"\x06status\x18\x02 \x01(\tR\x06status\x12,\n" +
|
||||||
"\x11paymentInProgress\x18\x03 \x01(\bR\x11paymentInProgress\"Z\n" +
|
"\x11paymentInProgress\x18\x03 \x01(\bR\x11paymentInProgress\"|\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"AddVoucher\x12\x12\n" +
|
"AddVoucher\x12\x12\n" +
|
||||||
"\x04code\x18\x01 \x01(\tR\x04code\x12\x14\n" +
|
"\x04code\x18\x01 \x01(\tR\x04code\x12\x14\n" +
|
||||||
"\x05value\x18\x02 \x01(\x03R\x05value\x12\"\n" +
|
"\x05value\x18\x02 \x01(\x03R\x05value\x12\"\n" +
|
||||||
"\fvoucherRules\x18\x03 \x03(\tR\fvoucherRules\"\x1f\n" +
|
"\fvoucherRules\x18\x03 \x03(\tR\fvoucherRules\x12 \n" +
|
||||||
|
"\vdescription\x18\x04 \x01(\tR\vdescription\"\x1f\n" +
|
||||||
"\rRemoveVoucher\x12\x0e\n" +
|
"\rRemoveVoucher\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\rR\x02id\"\xa7\x01\n" +
|
"\x02id\x18\x01 \x01(\rR\x02id\"\xa7\x01\n" +
|
||||||
"\x19UpsertSubscriptionDetails\x12\x13\n" +
|
"\x19UpsertSubscriptionDetails\x12\x13\n" +
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ type Rule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Voucher struct {
|
type Voucher struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Value int64 `json:"value"`
|
Value int64 `json:"value"`
|
||||||
Rules string `json:"rules"`
|
Rules string `json:"rules"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
@@ -40,8 +41,9 @@ func (s *Service) GetVoucher(code string) (*messages.AddVoucher, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &messages.AddVoucher{
|
return &messages.AddVoucher{
|
||||||
Code: code,
|
Code: code,
|
||||||
Value: v.Value,
|
Value: v.Value,
|
||||||
|
Description: v.Description,
|
||||||
VoucherRules: []string{
|
VoucherRules: []string{
|
||||||
v.Rules,
|
v.Rules,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ message AddVoucher {
|
|||||||
string code = 1;
|
string code = 1;
|
||||||
int64 value = 2;
|
int64 value = 2;
|
||||||
repeated string voucherRules = 3;
|
repeated string voucherRules = 3;
|
||||||
|
string description = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RemoveVoucher { uint32 id = 1; }
|
message RemoveVoucher { uint32 id = 1; }
|
||||||
|
|||||||
Reference in New Issue
Block a user