promotions
This commit is contained in:
+37
-10
@@ -28,16 +28,16 @@ type ItemMeta struct {
|
||||
}
|
||||
|
||||
type CartItem struct {
|
||||
Id uint32 `json:"id"`
|
||||
ItemId uint32 `json:"itemId,omitempty"`
|
||||
ParentId *uint32 `json:"parentId,omitempty"`
|
||||
Sku string `json:"sku"`
|
||||
Price Price `json:"price"`
|
||||
TotalPrice Price `json:"totalPrice"`
|
||||
SellerId string `json:"sellerId,omitempty"`
|
||||
OrgPrice *Price `json:"orgPrice,omitempty"`
|
||||
Cgm string `json:"cgm,omitempty"`
|
||||
Tax int
|
||||
Id uint32 `json:"id"`
|
||||
ItemId uint32 `json:"itemId,omitempty"`
|
||||
ParentId *uint32 `json:"parentId,omitempty"`
|
||||
Sku string `json:"sku"`
|
||||
Price Price `json:"price"`
|
||||
TotalPrice Price `json:"totalPrice"`
|
||||
SellerId string `json:"sellerId,omitempty"`
|
||||
OrgPrice *Price `json:"orgPrice,omitempty"`
|
||||
Cgm string `json:"cgm,omitempty"`
|
||||
Tax int `json:"tax"`
|
||||
Stock uint16 `json:"stock"`
|
||||
Quantity uint16 `json:"qty"`
|
||||
Discount *Price `json:"discount,omitempty"`
|
||||
@@ -97,6 +97,31 @@ type Marking struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
// AppliedPromotion records a single promotion action's effect on the cart. It is
|
||||
// rebuilt every time promotions are (re-)applied so the API result exposes a
|
||||
// per-promotion breakdown rather than only the aggregate TotalDiscount.
|
||||
//
|
||||
// An entry is one of two kinds, both living in the same list:
|
||||
// - applied (Pending=false): the action took effect now. Discount holds the
|
||||
// amount taken off (nil for non-monetary effects such as free_shipping).
|
||||
// - pending (Pending=true): the action has NOT qualified yet but is within
|
||||
// reach. Progress carries effect-specific data describing what's left to
|
||||
// unlock it — e.g. {"remaining": 120000, "threshold": 500000} for a
|
||||
// cart-total nudge. Keeping it an open map lets new effect types surface
|
||||
// their own progress fields without changing this struct. This powers
|
||||
// "spend X more for ..." nudges generically.
|
||||
type AppliedPromotion struct {
|
||||
PromotionId string `json:"promotionId,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ActionId string `json:"actionId,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Discount *Price `json:"discount,omitempty"`
|
||||
|
||||
Pending bool `json:"pending,omitempty"`
|
||||
Progress map[string]interface{} `json:"progress,omitempty"`
|
||||
}
|
||||
|
||||
type CartGrain struct {
|
||||
mu sync.RWMutex
|
||||
lastItemId uint32
|
||||
@@ -117,6 +142,7 @@ type CartGrain struct {
|
||||
OrderReference string `json:"orderReference,omitempty"`
|
||||
|
||||
Vouchers []*Voucher `json:"vouchers,omitempty"`
|
||||
AppliedPromotions []AppliedPromotion `json:"appliedPromotions,omitempty"`
|
||||
Notifications []CartNotification `json:"cartNotification,omitempty"`
|
||||
SubscriptionDetails map[string]*SubscriptionDetails `json:"subscriptionDetails,omitempty"`
|
||||
|
||||
@@ -245,6 +271,7 @@ func (c *CartGrain) FindItemWithSku(sku string) (*CartItem, bool) {
|
||||
func (c *CartGrain) UpdateTotals() {
|
||||
c.TotalPrice = NewPrice()
|
||||
c.TotalDiscount = NewPrice()
|
||||
c.AppliedPromotions = nil
|
||||
|
||||
for _, item := range c.Items {
|
||||
rowTotal := MultiplyPrice(item.Price, int64(item.Quantity))
|
||||
|
||||
Reference in New Issue
Block a user