Skip to content

Commit 62aa42b

Browse files
authored
fix(plugin-ecommerce): price not showing as 0 when explicitly set (#16289)
Minor change, now it explicitly checks for null or data not being a number as opposed to `!data` which would hit on `0` as well. The result was that if you explicitly set the price as `0` then it would correctly display as `$0` for example.
1 parent 835a0ad commit 62aa42b

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

packages/plugin-ecommerce/src/ui/PriceCell/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ export const PriceCell: React.FC<Props> = (args) => {
2727
}
2828

2929
if (
30-
(!cellData || typeof cellData !== 'number') &&
30+
(cellData == null || typeof cellData !== 'number') &&
3131
'enableVariants' in rowData &&
3232
rowData.enableVariants
3333
) {
3434
// @ts-expect-error - plugin translations are not typed yet
3535
return <span>{t('plugin-ecommerce:priceSetInVariants')}</span>
3636
}
3737

38-
if (!cellData) {
38+
if (cellData == null) {
3939
// @ts-expect-error - plugin translations are not typed yet
4040
return <span>{t('plugin-ecommerce:priceNotSet')}</span>
4141
}

test/plugin-ecommerce/e2e.spec.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import type { Page } from '@playwright/test'
2+
3+
import { expect, test } from '@playwright/test'
4+
import path from 'path'
5+
import { fileURLToPath } from 'url'
6+
7+
import type { PayloadTestSDK } from '../__helpers/shared/sdk/index.js'
8+
import type { Config } from './payload-types.js'
9+
10+
import { ensureCompilationIsDone, initPageConsoleErrorCatch } from '../__helpers/e2e/helpers.js'
11+
import { AdminUrlUtil } from '../__helpers/shared/adminUrlUtil.js'
12+
import { initPayloadE2ENoConfig } from '../__helpers/shared/initPayloadE2ENoConfig.js'
13+
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'
14+
15+
const filename = fileURLToPath(import.meta.url)
16+
const dirname = path.dirname(filename)
17+
18+
const { afterAll, beforeAll, beforeEach, describe } = test
19+
20+
let productsUrl: AdminUrlUtil
21+
let page: Page
22+
let payload: PayloadTestSDK<Config>
23+
let serverURL: string
24+
let zeroPriceProductId: string
25+
26+
describe('Ecommerce Plugin', () => {
27+
beforeAll(async ({ browser }, testInfo) => {
28+
testInfo.setTimeout(TEST_TIMEOUT_LONG)
29+
const { payload: payloadFromInit, serverURL: serverURLFromInit } =
30+
await initPayloadE2ENoConfig<Config>({
31+
dirname,
32+
})
33+
payload = payloadFromInit
34+
serverURL = serverURLFromInit
35+
productsUrl = new AdminUrlUtil(serverURL, 'products')
36+
37+
const context = await browser.newContext()
38+
page = await context.newPage()
39+
initPageConsoleErrorCatch(page)
40+
await ensureCompilationIsDone({ page, serverURL })
41+
42+
// Create a product with price set to 0 (base value)
43+
const zeroPriceProduct = await payload.create({
44+
collection: 'products',
45+
data: {
46+
priceInUSDEnabled: true,
47+
priceInUSD: 0,
48+
},
49+
})
50+
zeroPriceProductId = zeroPriceProduct.id
51+
})
52+
53+
afterAll(async () => {
54+
if (zeroPriceProductId) {
55+
await payload.delete({
56+
collection: 'products',
57+
where: { id: { equals: zeroPriceProductId } },
58+
})
59+
}
60+
})
61+
62+
beforeEach(async () => {
63+
await ensureCompilationIsDone({ page, serverURL })
64+
})
65+
66+
describe('PriceCell', () => {
67+
test('should display $0.00 for a zero price instead of priceNotSet', async () => {
68+
const columnsParam = encodeURIComponent(JSON.stringify(['priceInUSD']))
69+
70+
await page.goto(`${productsUrl.list}?columns=${columnsParam}`)
71+
72+
// The table should contain a cell showing $0.00 for our zero-price product
73+
const zeroPriceCell = page.locator('.cell-priceInUSD', { hasText: '$0.00' }).first()
74+
await expect(zeroPriceCell).toBeVisible()
75+
})
76+
})
77+
})

test/plugin-ecommerce/payload-types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ export interface Config {
118118
globals: {};
119119
globalsSelect: {};
120120
locale: null;
121+
widgets: {
122+
collections: CollectionsWidget;
123+
};
121124
user: User;
122125
jobs: {
123126
tasks: unknown;
@@ -820,6 +823,16 @@ export interface PayloadMigrationsSelect<T extends boolean = true> {
820823
updatedAt?: T;
821824
createdAt?: T;
822825
}
826+
/**
827+
* This interface was referenced by `Config`'s JSON-Schema
828+
* via the `definition` "collections_widget".
829+
*/
830+
export interface CollectionsWidget {
831+
data?: {
832+
[k: string]: unknown;
833+
};
834+
width: 'full';
835+
}
823836
/**
824837
* This interface was referenced by `Config`'s JSON-Schema
825838
* via the `definition` "auth".

0 commit comments

Comments
 (0)