Skip to content

Commit

Permalink
improve dynamic-options id loader (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
guitavano authored Oct 23, 2024
1 parent f78e400 commit 4cde382
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
28 changes: 22 additions & 6 deletions vtex/loaders/options/productIdByTerm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { allowCorsFor } from "@deco/deco";
interface Props {
term?: string;
}

interface DynamicOptionsReturn {
value: string;
label: string;
image?: string;
}

const loader = async (props: Props, req: Request, ctx: AppContext) => {
Object.entries(allowCorsFor(req)).map(([name, value]) => {
ctx.response.headers.set(name, value);
Expand All @@ -19,11 +26,20 @@ const loader = async (props: Props, req: Request, ctx: AppContext) => {
}];
}

return suggestions?.products?.map((product) => ({
value: `${product.productID}`,
label:
`${product.productID} - ${product.isVariantOf?.name} ${product.name} - ${product.isVariantOf?.productGroupID}`,
image: product.image?.[0]?.url,
}));
let suggestionsArray: DynamicOptionsReturn[] = [];

suggestions?.products?.forEach((product) => {
const variants = product.isVariantOf?.hasVariant?.map((variant) => {
return {
value: `${variant.productID}`,
label:
`${variant.productID} - ${product.isVariantOf?.name} ${variant.name} - ${product.isVariantOf?.productGroupID}`,
image: variant.image?.[0]?.url,
};
}) || [];
suggestionsArray = suggestionsArray.concat(variants);
});

return suggestionsArray;
};
export default loader;
4 changes: 3 additions & 1 deletion website/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export const getOptimizedMediaUrl = (opts: OptimizationOptions) => {
}

if (
/(vteximg.com.br|vtexassets.com|myvtex.com)\/arquivos\/ids\/\d+/.test(originalSrc)
/(vteximg.com.br|vtexassets.com|myvtex.com)\/arquivos\/ids\/\d+/.test(
originalSrc,
)
) {
return optimizeVTEX(opts);
}
Expand Down
3 changes: 1 addition & 2 deletions website/handlers/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function Proxy({
const to = new URL(
`${proxyUrl}${avoidAppendPath ? "" : sanitize(path)}`,
);

to.search = qs;

const headers = new Headers(req.headers);
Expand All @@ -132,7 +132,6 @@ export default function Proxy({
headers.set("host", hostToUse ?? to.host);
headers.set("x-forwarded-host", url.host);


for (const { key, value } of customHeaders) {
if (key === "cookie") {
const existingCookie = headers.get("cookie");
Expand Down

0 comments on commit 4cde382

Please sign in to comment.