Skip to content

Commit 52d5da8

Browse files
committed
fix(theme): remove cart load from layout
1 parent af3fa6d commit 52d5da8

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

packages/composables/src/composables/useCart/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ const factoryParams: UseCartFactoryParams<Cart, CartItem, Product> = {
383383
currentCart,
384384
product,
385385
},
386-
) => !!currentCart?.items.find((cartItem) => cartItem.product.uid === product.uid),
386+
) => !!currentCart?.items.find((cartItem) => cartItem?.product?.uid === product.uid),
387387
};
388388

389389
export default useCartFactory<Cart, CartItem, Product>(factoryParams);

packages/composables/src/getters/cartGetters.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,7 @@ export const getItemAttributes = (
8989
return attributes;
9090
};
9191

92-
export const getItemSku = (product: CartItem): string => {
93-
if (!product.product) {
94-
return '';
95-
}
96-
97-
return product.product.sku;
98-
};
92+
export const getItemSku = (product: CartItem): string => product?.product?.sku || '';
9993

10094
const calculateDiscounts = (discounts: Discount[]): number => discounts.reduce((a, b) => Number.parseFloat(`${a}`) + Number.parseFloat(`${b.amount.value}`), 0);
10195

packages/theme/components/CartSidebar.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,14 @@ import {
248248
defineComponent,
249249
ref,
250250
useRouter,
251-
useContext,
251+
useContext, onMounted,
252252
} from '@nuxtjs/composition-api';
253253
import {
254254
useCart,
255255
useUser,
256256
cartGetters,
257257
useExternalCheckout,
258258
} from '@vue-storefront/magento';
259-
import { onSSR } from '@vue-storefront/core';
260259
import { useUiState, useUiNotification } from '~/composables';
261260
import CouponCode from './CouponCode.vue';
262261
import stockStatusEnum from '~/enums/stockStatusEnum';
@@ -301,8 +300,9 @@ export default defineComponent({
301300
const isLoaderVisible = ref(false);
302301
const tempProduct = ref();
303302
304-
onSSR(async () => {
305-
await loadCart();
303+
onMounted(() => {
304+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
305+
loadCart();
306306
});
307307
308308
const goToCheckout = async () => {

packages/theme/layouts/default.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import LazyHydrate from 'vue-lazy-hydration';
2626
import { onSSR } from '@vue-storefront/core';
2727
import { useRoute, defineComponent } from '@nuxtjs/composition-api';
2828
import {
29-
useCart,
3029
useUser,
3130
} from '@vue-storefront/magento';
3231
import AppHeader from '~/components/AppHeader.vue';
@@ -57,16 +56,12 @@ export default defineComponent({
5756
setup() {
5857
const route = useRoute();
5958
const { load: loadUser } = useUser();
60-
const { load: loadCart } = useCart();
6159
6260
const { loadConfiguration } = useMagentoConfiguration();
6361
6462
onSSR(async () => {
6563
await loadConfiguration();
66-
await Promise.all([
67-
loadUser(),
68-
loadCart(),
69-
]);
64+
await loadUser();
7065
});
7166
7267
return {

0 commit comments

Comments
 (0)