Compare commits
3 Commits
refactor/h
...
47adb12112
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47adb12112 | ||
|
|
4835041f14 | ||
| 104f9fbb4c |
@@ -260,6 +260,10 @@ func (c *CartGrain) UpdateTotals() {
|
|||||||
for _, voucher := range c.Vouchers {
|
for _, voucher := range c.Vouchers {
|
||||||
if _, ok := voucher.AppliesTo(c); ok {
|
if _, ok := voucher.AppliesTo(c); ok {
|
||||||
value := NewPriceFromIncVat(voucher.Value, 25)
|
value := NewPriceFromIncVat(voucher.Value, 25)
|
||||||
|
if c.TotalPrice.IncVat <= value.IncVat {
|
||||||
|
// don't apply discounts to more than the total price
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
c.TotalDiscount.Add(*value)
|
c.TotalDiscount.Add(*value)
|
||||||
c.TotalPrice.Subtract(*value)
|
c.TotalPrice.Subtract(*value)
|
||||||
|
|||||||
@@ -30,9 +30,13 @@ func AddItem(g *CartGrain, m *messages.AddItem) error {
|
|||||||
|
|
||||||
// Fast path: merge with existing item having same SKU
|
// Fast path: merge with existing item having same SKU
|
||||||
if existing, found := g.FindItemWithSku(m.Sku); found {
|
if existing, found := g.FindItemWithSku(m.Sku); found {
|
||||||
|
if existing.StoreId == m.StoreId {
|
||||||
existing.Quantity += int(m.Quantity)
|
existing.Quantity += int(m.Quantity)
|
||||||
|
existing.Stock = StockStatus(m.Stock)
|
||||||
|
existing.StoreId = m.StoreId
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g.mu.Lock()
|
g.mu.Lock()
|
||||||
defer g.mu.Unlock()
|
defer g.mu.Unlock()
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type Voucher struct {
|
|||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
// Add fields here
|
// Add fields here
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrInvalidCode = errors.New("invalid vouchercode")
|
var ErrInvalidCode = errors.New("invalid vouchercode")
|
||||||
|
|||||||
Reference in New Issue
Block a user