Skip to content

Commit 5e18875

Browse files
committed
fix: allow products with no price
1 parent e94c004 commit 5e18875

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/content/queries/cs-product.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { errorWithResponse, forceImagesHTTPS } from '../../utils/http.js';
13+
import { forceImagesHTTPS } from '../../utils/http.js';
1414
import { gql, parseRating, parseSpecialToDate } from '../../utils/product.js';
1515

1616
/**
@@ -91,10 +91,6 @@ export const adapter = (config, productData) => {
9191
} : null,
9292
};
9393

94-
if (!minPrice && !maxPrice) {
95-
throw errorWithResponse(400, 'no product price range found');
96-
}
97-
9894
if (config.attributeOverrides?.product) {
9995
Object.entries(config.attributeOverrides.product).forEach(([key, value]) => {
10096
product.attributeMap[key] = product.attributeMap[value] ?? product[key];

src/content/queries/cs-variants.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { errorWithResponse, forceImagesHTTPS } from '../../utils/http.js';
13+
import { forceImagesHTTPS } from '../../utils/http.js';
1414
import { gql, parseRating, parseSpecialToDate } from '../../utils/product.js';
1515

1616
/**
@@ -53,10 +53,6 @@ export const adapter = (config, variants) => variants.map(({ selections, product
5353
selections: (selections ?? []).sort(),
5454
};
5555

56-
if (!minPrice && !maxPrice) {
57-
throw errorWithResponse(400, 'no variant price range found');
58-
}
59-
6056
if (config.attributeOverrides?.variant) {
6157
Object.entries(config.attributeOverrides.variant).forEach(([key, value]) => {
6258
variant.attributeMap[key] = variant.attributeMap[value] ?? variant[key];

src/templates/html/HTMLTemplate.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ ${HTMLTemplate.metaName('twitter:title', product.name)}
111111
${HTMLTemplate.metaName('twitter:image', image?.url)}
112112
${HTMLTemplate.metaName('twitter:description', product.metaDescription)}
113113
${HTMLTemplate.metaName('twitter:label1', 'Price')}
114-
${HTMLTemplate.metaName('twitter:data1', product.prices.final.amount)}
114+
${HTMLTemplate.metaName('twitter:data1', product.prices?.final?.amount)}
115115
${HTMLTemplate.metaName('twitter:label2', 'Availability')}
116116
${HTMLTemplate.metaName('twitter:data2', product.inStock ? 'In stock' : 'Out of stock')}`;
117117
}
@@ -129,8 +129,8 @@ ${HTMLTemplate.metaName('externalId', product.externalId)}
129129
${HTMLTemplate.metaName('addToCartAllowed', product.addToCartAllowed)}
130130
${HTMLTemplate.metaName('inStock', product.inStock ? 'true' : 'false')}
131131
${HTMLTemplate.metaProperty('product:availability', product.inStock ? 'In stock' : 'Out of stock')}
132-
${HTMLTemplate.metaProperty('product:price.amount', product.prices.final.amount)}
133-
${HTMLTemplate.metaProperty('product:price.currency', product.prices.final.currency)}`;
132+
${HTMLTemplate.metaProperty('product:price.amount', product.prices?.final?.amount)}
133+
${HTMLTemplate.metaProperty('product:price.currency', product.prices?.final?.currency)}`;
134134
}
135135

136136
/**
@@ -271,8 +271,8 @@ ${HTMLTemplate.indent(this.renderProductItems(opt.items), 2)}`).join('\n')}
271271
*/
272272
renderVariantPrices(prices) {
273273
return /* html */ `\
274-
<div>Regular: ${prices.regular.amount} ${prices.regular.currency}${HTMLTemplate.priceRange(prices.regular.minimumAmount, prices.regular.maximumAmount)}</div>
275-
<div>Final: ${prices.final.amount} ${prices.final.currency}${HTMLTemplate.priceRange(prices.final.minimumAmount, prices.final.maximumAmount)}</div>`;
274+
<div>Regular: ${prices.regular?.amount} ${prices.regular?.currency}${HTMLTemplate.priceRange(prices.regular?.minimumAmount, prices.regular?.maximumAmount)}</div>
275+
<div>Final: ${prices.final?.amount} ${prices.final?.currency}${HTMLTemplate.priceRange(prices.final?.minimumAmount, prices.final?.maximumAmount)}</div>`;
276276
}
277277

278278
/**
@@ -292,7 +292,7 @@ ${this.variants.map((v) => /* html */`\
292292
<div>${v.name}</div>
293293
<div>${v.description}</div>
294294
<div>${v.inStock ? 'inStock' : ''}</div>
295-
${HTMLTemplate.indent(this.renderVariantPrices(v.prices), 4)}
295+
${v.prices ? HTMLTemplate.indent(this.renderVariantPrices(v.prices), 4) : ''}
296296
<div>
297297
${HTMLTemplate.indent(this.renderVariantImages(v.images), 6)}
298298
</div>

0 commit comments

Comments
 (0)