Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions blocks/product-list-page/product-list-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@
display: none;
}

/* Product Attribute Banner */
.block.product-list-page .dropin-product-item-card__image-container {
position: relative;
}

.block.product-list-page .product-attribute-banner,
.block.product-list-page .product-stock-banner {
position: absolute;
right: var(--spacing-xsmall);
padding: var(--spacing-xsmall) var(--spacing-small);
font: var(--type-body-2-strong-font);
letter-spacing: var(--type-body-2-strong-letter-spacing);
border-radius: var(--shape-border-radius-1);
z-index: 1;
pointer-events: none;
}

.block.product-list-page .product-attribute-banner {
top: var(--spacing-xsmall);
background-color: var(--color-brand-700);
color: var(--color-neutral-50);
}

.block.product-list-page .product-stock-banner {
top: calc(var(--spacing-xsmall) + var(--spacing-xlarge));
background-color: var(--color-informational-500);
color: var(--color-neutral-50);
}

/* Media Queries */
@media only screen and (min-width: 768px) {
.block.product-list-page .search__wrapper {
Expand Down
16 changes: 16 additions & 0 deletions blocks/product-list-page/product-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ export default async function decorate(block) {
height: defaultImageProps.height,
},
});

// Display the first product attribute as a banner
if (product.attributes?.length > 0 && product.attributes[0].label) {
const banner = document.createElement('div');
banner.className = 'product-attribute-banner';
banner.textContent = product.attributes[0].label;
ctx.prependSibling(banner);
}

// Display "Ready to Ship" badge when not low stock
if (!product.lowStock) {
const stockBadge = document.createElement('div');
stockBadge.className = 'product-stock-banner';
stockBadge.textContent = 'Ready to Ship';
ctx.prependSibling(stockBadge);
}
},
ProductActions: (ctx) => {
const actionsWrapper = document.createElement('div');
Expand Down
13 changes: 13 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ overrideGQLOperations([
// `,
// ],
// },
// Extend the ProductView fragment to include lowStock
{
npm: '@dropins/storefront-product-discovery',
operations: [
`
fragment ProductView on ProductSearchItem {
productView {
lowStock
}
}
`,
],
},
]);
Loading