Skip to content

Commit

Permalink
Merge pull request #5699 from vuestorefront/20210324-fix-cart-getters
Browse files Browse the repository at this point in the history
Fix cart getters
  • Loading branch information
filrak committed Mar 24, 2021
2 parents 36304ce + 4859092 commit bf09a22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/commercetools/composables/src/getters/cartGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export const getCartItems = (cart: Cart): LineItem[] => {
return cart.lineItems;
};

export const getCartItemName = (product: LineItem): string => product.name;
export const getCartItemName = (product: LineItem): string => product?.name || '';

export const getCartItemImage = (product: LineItem): string => product.variant.images[0].url;
export const getCartItemImage = (product: LineItem): string => product?.variant?.images[0]?.url || '';

export const getCartItemPrice = (product: LineItem): AgnosticPrice => createPrice(product);

export const getCartItemQty = (product: LineItem): number => product.quantity;
export const getCartItemQty = (product: LineItem): number => product?.quantity || 0;

export const getCartItemAttributes = (product: LineItem, filterByAttributeName?: Array<string>) =>
getProductAttributes(product.variant, filterByAttributeName);

export const getCartItemSku = (product: LineItem): string => product.variant.sku;
export const getCartItemSku = (product: LineItem): string => product?.variant?.sku || '';

const getCartSubtotalPrice = (cart: Cart, selectSpecialPrices = false): number => {
return getCartItems(cart).reduce((total, cartItem) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/docs/changelog/5699.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
description: 'Fix getters in `cartGetters` to now throw errors when some properties don\'t exist',
link: 'https://github.com/vuestorefront/vue-storefront/pull/5699',
isBreaking: false,
breakingChanges: [],
author: 'Filip Sobol',
linkToGitHubAccount: 'https://github.com/filipsobol'
};

0 comments on commit bf09a22

Please sign in to comment.