Skip to content

Commit

Permalink
feat: related media improvement google feed
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikZed committed Jan 14, 2025
1 parent 4647920 commit ecdf6d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-news-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"products-feed": minor
---

Product feed: prioritize media assigned to a specific product variant. with a fallback mechanism to use product media when no variant-specific media is available. The changes aim to enhance the precision of media selection
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ export const getRelatedMedia = ({
variantMediaMap,
productMedia,
}: getRelatedMediaArgs) => {
// Saleor always uses the first photo as thumbnail - even if it's assigned to the variant
const productThumbnailUrl = productMedia[0]?.url;

const mediaAssignedToAnyVariant = Object.values(variantMediaMap).flat() || [];

const mediaAssignedToNoVariant =
productMedia?.filter((m) => !mediaAssignedToAnyVariant.find((vm) => vm.id === m.id)) || [];

const mediaAssignedToVariant = variantMediaMap[productVariantId] || [];
// Saleor always uses the first photo as thumbnail - even if it's assigned to the variant
const productThumbnailUrl = mediaAssignedToVariant[0]?.url || productMedia[0]?.url;

const additionalImages =
[...mediaAssignedToVariant, ...mediaAssignedToNoVariant]
Expand Down

0 comments on commit ecdf6d3

Please sign in to comment.