Skip to content

Commit

Permalink
Add option values (#62)
Browse files Browse the repository at this point in the history
* Fix option value and expose type

* Fix post deploy test
  • Loading branch information
herzog31 authored Dec 11, 2024
1 parent d3cc60b commit 08566d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/content/queries/cs-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const adapter = (config, productData) => {
label: value.title,
inStock: value.inStock,
type: value.type,
value: value.value,
product: value.product
? {
sku: value.product.sku,
Expand Down
3 changes: 2 additions & 1 deletion src/templates/html/HTMLTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ${HTMLTemplate.metaProperty('product:price.currency', product.prices?.final?.cur
*/
renderJSONLD() {
return /* html */ `\
<script type="application/ld+json">
<script type="application/ld+json" data-name="product">
${this.jsonTemplate.render()}
</script>`;
}
Expand Down Expand Up @@ -228,6 +228,7 @@ ${attributes.map((attr) => /* html */`\
<div>${item.value ?? ''}</div>
<div>${item.selected ? 'selected' : ''}</div>
<div>${item.inStock ? 'inStock' : ''}</div>
<div>${item.type}</div>
</div>`).join('\n');
}

Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ declare global {
inStock: boolean;
value: string;
selected: boolean;
type: string;
product?: {
name: string;
sku: string;
Expand Down
26 changes: 17 additions & 9 deletions test/fixtures/post-deploy/bella-tank.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<script src="/scripts/aem.js" type="module"></script>
<script src="/scripts/scripts.js" type="module"></script>
<link rel="stylesheet" href="/styles/styles.css">
<script type="application/ld+json">
<script type="application/ld+json" data-name="product">
{
"@context": "http://schema.org",
"@type": "Product",
Expand Down Expand Up @@ -276,41 +276,46 @@ <h1>Bella Tank</h1>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzU1Ni81MjM=</div>
<div>XS</div>
<div></div>
<div>XS</div>
<div></div>
<div>inStock</div>
<div>TEXT</div>
</div>
<div>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzU1Ni81MjY=</div>
<div>S</div>
<div></div>
<div>S</div>
<div></div>
<div>inStock</div>
<div>TEXT</div>
</div>
<div>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzU1Ni81Mjk=</div>
<div>M</div>
<div></div>
<div>M</div>
<div></div>
<div>inStock</div>
<div>TEXT</div>
</div>
<div>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzU1Ni81MzI=</div>
<div>L</div>
<div></div>
<div>L</div>
<div></div>
<div>inStock</div>
<div>TEXT</div>
</div>
<div>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzU1Ni81MzU=</div>
<div>XL</div>
<div></div>
<div>XL</div>
<div></div>
<div>inStock</div>
<div>TEXT</div>
</div>
<div>
<div>color</div>
Expand All @@ -324,25 +329,28 @@ <h1>Bella Tank</h1>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzI3Ny8xNzI=</div>
<div>Black</div>
<div></div>
<div>#000000</div>
<div></div>
<div>inStock</div>
<div>COLOR_HEX</div>
</div>
<div>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzI3Ny8xNzU=</div>
<div>Blue</div>
<div></div>
<div>#1857f7</div>
<div></div>
<div>inStock</div>
<div>COLOR_HEX</div>
</div>
<div>
<div>option</div>
<div>Y29uZmlndXJhYmxlLzI3Ny8xOTM=</div>
<div>Orange</div>
<div></div>
<div>#eb6703</div>
<div></div>
<div>inStock</div>
<div>COLOR_HEX</div>
</div>
</div>
<div class="product-variants">
Expand Down

0 comments on commit 08566d0

Please sign in to comment.