Skip to content

Commit

Permalink
fix(composables): proper currency and price context on SSR (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
patzick committed Apr 27, 2023
1 parent 4369d4a commit bb64070
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-squids-flow.md
@@ -0,0 +1,5 @@
---
"@shopware-pwa/composables-next": patch
---

Currency and price context are properly set during the hydration. `usePrice` is not a shared composable.
16 changes: 9 additions & 7 deletions packages/composables/src/usePrice.ts
@@ -1,10 +1,5 @@
import { ref } from "vue";

const currencyLocale = ref<string>("");
const currencyCode = ref<string>("");

// @ToDo make sure why there is no decimal precision in api response
const decimalPrecision = 2;
import { createSharedComposable } from "@vueuse/core";

export type UsePriceReturn = {
/**
Expand All @@ -22,7 +17,12 @@ export type UsePriceReturn = {
* @public
* @category Product
*/
export function usePrice(): UsePriceReturn {
function _usePrice(): UsePriceReturn {
const currencyLocale = ref<string>("");
const currencyCode = ref<string>("");

// TODO: make sure why there is no decimal precision in api response
const decimalPrecision = 2;
/**
* Set init data from backend response
*
Expand Down Expand Up @@ -72,3 +72,5 @@ export function usePrice(): UsePriceReturn {
getFormattedPrice,
};
}

export const usePrice = createSharedComposable(_usePrice);
7 changes: 7 additions & 0 deletions packages/composables/src/useSessionContext.ts
Expand Up @@ -102,6 +102,13 @@ export function useSessionContext(
const { apiInstance } = useShopwareContext();
const { init } = usePrice();

if (newContext) {
init({
currencyCode: newContext.currency?.isoCode,
localeCode: newContext.salesChannel?.language?.locale?.code,
});
}

const _sessionContext = _useContext("swSessionContext", {
replace: newContext,
});
Expand Down

2 comments on commit bb64070

@vercel
Copy link

@vercel vercel bot commented on bb64070 Apr 27, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on bb64070 Apr 27, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo-shopware-frontends.vercel.app
frontends-demo-git-main-shopware-frontends.vercel.app
frontends-demo.vercel.app

Please sign in to comment.