Skip to content

Commit

Permalink
fix: promotion code handling (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored Jun 1, 2021
1 parent 7d3c317 commit acaefeb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

1 comment on commit acaefeb

@vercel
Copy link

@vercel vercel bot commented on acaefeb Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.