Skip to content

Commit

Permalink
Merge pull request #38 from adobe-rnd/image-roles
Browse files Browse the repository at this point in the history
fix: image roles config option
  • Loading branch information
maxakuru authored Nov 5, 2024
2 parents 3384046 + 62585b9 commit e8eadc4
Show file tree
Hide file tree
Showing 12 changed files with 1,323 additions and 16 deletions.
253 changes: 253 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"eslint-plugin-header": "3.1.1",
"eslint-plugin-import": "2.29.1",
"esmock": "^2.6.9",
"html-differ": "1.4.0",
"husky": "9.1.4",
"jsdom": "25.0.1",
"lint-staged": "15.2.9",
Expand Down
4 changes: 2 additions & 2 deletions src/content/adobe-commerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import htmlTemplateFromContext from '../templates/html/index.js';
*/
async function fetchProduct(sku, config) {
const { catalogEndpoint = 'https://catalog-service.adobe.io/graphql' } = config;
const query = getProductQuery({ sku });
const query = getProductQuery({ sku, imageRoles: config.imageRoles });
console.debug(query);

const resp = await ffetch(`${catalogEndpoint}?query=${encodeURIComponent(query)}&view=${config.storeViewCode}`, {
Expand Down Expand Up @@ -68,7 +68,7 @@ async function fetchProduct(sku, config) {
*/
async function fetchVariants(sku, config) {
const { catalogEndpoint = 'https://catalog-service.adobe.io/graphql' } = config;
const query = getVariantsQuery(sku);
const query = getVariantsQuery({ sku, imageRoles: config.imageRoles });
console.debug(query);

const resp = await ffetch(`${catalogEndpoint}?query=${encodeURIComponent(query)}&view=${config.storeViewCode}`, {
Expand Down
10 changes: 8 additions & 2 deletions src/content/queries/cs-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ export const adapter = (productData) => {
};

// @ts-ignore
export default ({ sku }) => gql`{
/**
* @param {{
* sku: string;
* imageRoles?: string[];
* }} opts
*/
export default ({ sku, imageRoles = [] }) => gql`{
products(
skus: ["${sku}"]
) {
Expand All @@ -117,7 +123,7 @@ export default ({ sku }) => gql`{
addToCartAllowed
inStock
externalId
images(roles: []) {
images(roles: [${imageRoles.map((s) => `"${s}"`).join(',')}]) {
url
label
}
Expand Down
12 changes: 7 additions & 5 deletions src/content/queries/cs-variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const adapter = (config, variants) => variants.map(({ selections, product
minimumAmount: minPrice.final.amount.value,
},
},
selections: selections ?? [],
selections: (selections ?? []).sort(),
};

const specialToDate = parseSpecialToDate(product);
Expand All @@ -65,10 +65,12 @@ export const adapter = (config, variants) => variants.map(({ selections, product
});

/**
* @param {string} sku
* @param {{
* sku: string;
* imageRoles?: string[];
* }} opts
*/
// @ts-ignore
export default (sku) => gql`
export default ({ sku, imageRoles = [] }) => gql`
{
variants(sku: "${sku}") {
variants {
Expand All @@ -78,7 +80,7 @@ export default (sku) => gql`
sku
inStock
externalId
images {
images(roles: [${imageRoles.map((s) => `"${s}"`).join(',')}]) {
url
label
}
Expand Down
Loading

0 comments on commit e8eadc4

Please sign in to comment.