Skip to content

Commit d664729

Browse files
Added support for language when calling APIs (#57)
* Added support for language when calling APIs * Updated @moltin/sdk to 4.0.1
1 parent a2e118e commit d664729

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.1.0",
44
"private": true,
55
"dependencies": {
6-
"@moltin/sdk": "^4.0.0",
6+
"@moltin/sdk": "^4.0.1",
77
"@types/node": "^12.0.0",
88
"@types/react": "^16.9.0",
99
"@types/react-dom": "^16.9.0",

src/Address.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ export const Address: React.FC = () => {
2828
};
2929

3030
const onDeleteAddress = () => {
31-
const token = localStorage.getItem('mtoken') || '';
32-
const customer = localStorage.getItem('mcustomer') || '';
33-
setIsLoading(true);
31+
const token = localStorage.getItem('mtoken') || '';
32+
const customer = localStorage.getItem('mcustomer') || '';
33+
setIsLoading(true);
3434

35-
deleteAddress(customer, selectedDeleteAddress, token)
36-
.then(() => {
37-
updateAddresses();
38-
setIsLoading(false);
39-
setIsDeleteModalOpen(false);
40-
})
41-
.catch(error => {
42-
setIsLoading(false);
43-
setIsDeleteModalOpen(false);
44-
console.error(error);
45-
});
35+
deleteAddress(customer, selectedDeleteAddress, token)
36+
.then(() => {
37+
updateAddresses();
38+
setIsLoading(false);
39+
setIsDeleteModalOpen(false);
40+
})
41+
.catch(error => {
42+
setIsLoading(false);
43+
setIsDeleteModalOpen(false);
44+
console.error(error);
45+
});
4646
};
4747

4848
const handleEdit = (address: any) => {

src/app-state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ function useCategoriesState(selectedLanguage: string) {
295295
setCategoryPaths(undefined);
296296
setCategoriesTree(undefined);
297297

298-
loadCategoryTree().then(result => {
298+
loadCategoryTree(selectedLanguage).then(result => {
299299
setCategoriesTree(result);
300300
setCategoryPaths(mergeMaps(result));
301301
});

src/service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export async function loadEnabledCurrencies(): Promise<moltin.Currency[]> {
1010
return response.data.filter(c => c.enabled);
1111
}
1212

13-
export async function loadCategoryTree(): Promise<moltin.Category[]> {
14-
const moltin = MoltinGateway({ host: config.endpointURL, client_id: config.clientId });
13+
export async function loadCategoryTree(language: string): Promise<moltin.Category[]> {
14+
const moltin = MoltinGateway({ host: config.endpointURL, client_id: config.clientId, language });
1515
const result = await moltin.Categories.Tree();
1616

1717
return result.data;
@@ -28,7 +28,7 @@ function getProductCache(key: string, language: string, currency: string): molti
2828
}
2929

3030
export async function loadCategoryProducts(categoryId: string, pageNum: number, language: string, currency: string): Promise<moltin.ResourcePage<moltin.Product>> {
31-
const moltin = MoltinGateway({ host: config.endpointURL, client_id: config.clientId, currency: currency });
31+
const moltin = MoltinGateway({ host: config.endpointURL, client_id: config.clientId, language, currency });
3232

3333
const result = await moltin.Products
3434
.Offset((pageNum - 1) * config.categoryPageSize)
@@ -86,7 +86,7 @@ export async function loadProductBySlug(productSlug: string, language: string, c
8686
return cachedProduct;
8787
}
8888

89-
const moltin = MoltinGateway({ host: config.endpointURL, client_id: config.clientId, currency: currency });
89+
const moltin = MoltinGateway({ host: config.endpointURL, client_id: config.clientId, language, currency });
9090

9191
const resultSlug = await moltin.Products
9292
.Limit(1)

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,10 +2170,10 @@
21702170
"@types/istanbul-reports" "^1.1.1"
21712171
"@types/yargs" "^13.0.0"
21722172

2173-
"@moltin/sdk@^4.0.0":
2174-
version "4.0.0"
2175-
resolved "https://registry.yarnpkg.com/@moltin/sdk/-/sdk-4.0.0.tgz#f31898639134db72316176604ad44085ce51e2db"
2176-
integrity sha512-/PBpqK3IqEjOXaEVvJRJxqe/jOCmDsbckpW1mbLBBRHq33oqTYkk+R1soPJpJ4cXiSZ0ppmaZntapqJWx0q57Q==
2173+
"@moltin/sdk@^4.0.1":
2174+
version "4.0.1"
2175+
resolved "https://registry.yarnpkg.com/@moltin/sdk/-/sdk-4.0.1.tgz#a94c81d81d7bff565bae70aa70eabc0b09b5869d"
2176+
integrity sha512-yyfhg3X1u8WUYTKuG9VIV18zq5oeB5UC0Jg6DzExUcT40pzTPJcuBvlvG2LC9V52zc69CubMGebLMOtyCoxmPw==
21772177
dependencies:
21782178
es6-promise "^4.0.5"
21792179
fetch-everywhere "^1.0.5"

0 commit comments

Comments
 (0)