spz-coupon-code

When to use

spz-coupon-code provides a full coupon code workflow — input, apply, display active / expired codes, recommend available codes, and copy to clipboard.

Supported layout

  • container

Example

<spz-coupon-code id="coupon" layout="container" cart-id="cart">
  <input role="input" placeholder="Enter coupon code" />
  <button role="apply">Apply</button>
  <button role="clear">Clear invalid</button>
  <spz-render role="recommend" layout="container" src="...">
    <template><!-- recommend list --></template>
  </spz-render>
  <div role="applied"><!-- applied codes --></div>
  <div role="unavailable"><!-- expired codes --></div>
  <div role="result"><!-- result message --></div>
</spz-coupon-code>

Attributes

AttributeDescriptionTypeRequired
cart-idID of the cart element to refresh after a coupon is appliedstringNo

DOM role convention

The component locates child elements by their role attribute:

RoleElementDescription
input<input>Coupon code input field
apply<button>Apply button
clear<button>Button to clear expired / unavailable codes
recommendspz-renderRecommended coupon code list
appliedcontainerApplied and active coupon code list
unavailablecontainerExpired / unavailable coupon code list
resultcontainerApplication result message area

Status attributes

These boolean attributes are automatically set on the component element to reflect state:

AttributeDescription
emptyInput field is empty
limitUser has reached the coupon usage limit
loadingA request is in progress
dom-mountedDOM structure is initialized
failedThe last application failed
disabledInput is disabled

Actions

cancel

Cancel (remove) an applied coupon code.

Parameters:

  • code (string): The code to cancel

Example:

<button @tap="coupon.cancel(code='SAVE10')">Remove SAVE10</button>

clear

Clear all expired or unavailable codes from the list.

copy

Copy a coupon code to the clipboard. If auto-apply is enabled, also applies the code automatically.

Parameters:

  • code (string): The code to copy

setDiscountId

Cache the current discount ID for later reference.

Events

EventDescription
applySuccessCoupon code applied successfully
applyErrorCoupon code application failed
applyNotMetThresholdApplied but the spending threshold was not met
applyMessageApplication result message / status updated
copiedCoupon code copied to clipboard
dj.applyDiscountCodeDiscount code changed (also dispatched on document)

Public API

MethodDescriptionReturns
getModalData()Get discount campaign informationobject
getProductList(data)Get entitled products listarray
getObtainList(data)Get obtain products listarray
getMessage()Get the current message / status textstring

Notes

  • The component fetches its configuration from the backend on build; if the coupon feature is disabled, the component will not render.
  • Auto-apply behavior (copy → apply) depends on the backend auto_apply_switch configuration.
  • The component listens to cart change events and automatically re-validates applied codes.