forked from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LYNX-718: Sidekick Personalisation plugin - Catalog Rules, Cart Rules…
… and Customer Groups (#287)
- Loading branch information
Showing
14 changed files
with
267 additions
and
390 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
tools/segments/dist/index.e22faa19.js.map → tools/segments/dist/index.76406fbe.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!DOCTYPE html><html lang="en"><head><link rel="stylesheet" href="index.6bf80747.css"><meta charset="utf-8"><title>Customer Segments Picker</title><link rel="stylesheet" href="index.107f8a5c.css"></head><body> <div id="app"></div> <script type="module" src="index.e22faa19.js"></script> </body></html> | ||
<!DOCTYPE html><html lang="en"><head><link rel="stylesheet" href="index.6bf80747.css"><meta charset="utf-8"><title>Customer Segments Picker</title><link rel="stylesheet" href="index.107f8a5c.css"></head><body> <div id="app"></div> <script type="module" src="index.76406fbe.js"></script> </body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
import executeGraphQlQuery from './query.graphql'; | ||
import queryCache from './query.cache'; | ||
|
||
const query = ` | ||
query { | ||
allCartRules { | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const getCartRules = async (environment) => { | ||
if (!queryCache.cartRules.length > 0) { | ||
try { | ||
const rules = await executeGraphQlQuery(query, environment); | ||
rules?.allCartRules?.forEach(rule => { | ||
queryCache.cartRules.push({ | ||
'name': rule.name, | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error('Could not retrieve cart rules', err); | ||
} | ||
} | ||
return queryCache.cartRules; | ||
} | ||
|
||
export default getCartRules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
import executeGraphQlQuery from './query.graphql'; | ||
import queryCache from './query.cache'; | ||
|
||
const query = ` | ||
query { | ||
allCatalogRules { | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const getCatalogRules = async (environment) => { | ||
if (!queryCache.catalogRules.length > 0) { | ||
try { | ||
const rules = await executeGraphQlQuery(query, environment); | ||
rules?.allCatalogRules?.forEach(rule => { | ||
queryCache.catalogRules.push({ | ||
'name': rule.name, | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error('Could not retrieve catalog rules', err); | ||
} | ||
} | ||
return queryCache.catalogRules; | ||
} | ||
|
||
export default getCatalogRules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
import executeGraphQlQuery from './query.graphql'; | ||
import queryCache from './query.cache'; | ||
|
||
const query = ` | ||
query { | ||
allCustomerGroups { | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const getCustomerGroups = async (environment) => { | ||
if (!queryCache.customerGroups.length > 0) { | ||
try { | ||
const groups = await executeGraphQlQuery(query, environment); | ||
groups?.allCustomerGroups?.forEach(group => { | ||
queryCache.customerGroups.push({ | ||
'name': group.name, | ||
}); | ||
}); | ||
} catch (err) { | ||
console.error('Could not retrieve customer groups', err); | ||
} | ||
} | ||
return queryCache.customerGroups; | ||
} | ||
|
||
export default getCustomerGroups; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
|
||
/** | ||
* To avoid executing requests every time the Personalisation category is selected, | ||
* the result is cached. | ||
* | ||
* In order to clear the cache (eg. when new rule or segment was added to the backend), there is | ||
* 'Refresh' button added to the plugin. | ||
* Also, cache is cleared every time when the environment | ||
* is changed as data comes from different endpoint. | ||
*/ | ||
const queryCache = { | ||
catalogRules: [], | ||
cartRules: [], | ||
customerSegments: [], | ||
customerGroups: [], | ||
} | ||
|
||
export default queryCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
import { getConfigValue } from '../../../../scripts/configs'; | ||
import { fetchGraphQl, setEndpoint } from '@dropins/tools/fetch-graphql.js'; | ||
|
||
async function executeGraphQlQuery(query, environment) { | ||
try { | ||
setEndpoint(new URL(await getConfigValue('commerce-core-endpoint', environment)).href); | ||
const response = await fetchGraphQl(query, { | ||
method: 'GET' | ||
}); | ||
|
||
return response.data ? response.data : []; | ||
} catch (err) { | ||
console.error('Could not execute GraphQl query to ', environment); | ||
} | ||
} | ||
|
||
export default executeGraphQlQuery; |
Oops, something went wrong.