Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: promotion code error handling #1522

Merged
merged 2 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/composables/src/hooks/useCart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const useCart = (rootContext: ApplicationVueContext): IUseCart => {
async function submitPromotionCode(promotionCode: string) {
if (promotionCode) {
const result = await addPromotionCode(promotionCode, apiInstance);
``;
broadcastUpcomingErrors(result);
_storeCart.value = result;
broadcast(INTERCEPTOR_KEYS.ADD_PROMOTION_CODE, {
result,
Expand Down
8 changes: 5 additions & 3 deletions packages/default-theme/src/logic/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export const addToCartNotification = (payload, rootContext) => {

export const addPromotionCodeNotification = (payload, rootContext) => {
const { pushSuccess, pushError } = useNotifications(rootContext)
const { result } = payload
const { result, promotionCode } = payload

if (!result.errors || !result.errors.length) {
if (!result.errors || !Object.keys(result.errors).length) {
return pushSuccess(rootContext.$t("Promotion code added successfully"))
}

const err = Object.values(result.errors)[0]
const err = Object.values(result.errors).find(
(error) => promotionCode === error.promotionCode
)
if (err) {
switch (err.messageKey) {
case "promotion-not-found":
Expand Down