-
Notifications
You must be signed in to change notification settings - Fork 319
Add stock level message to product page based on inventory settings #2619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": major | ||
--- | ||
|
||
Add current stock message to product details page based on the store/product inventory settings. | ||
|
||
## Migration | ||
For existing Catalyst stores, to get the newly added feature, simply rebase the existing code with the new release code. The files to be rebased for this change to be applied are: | ||
- core/messages/en.json | ||
- core/app/[locale]/(default)/product/[slug]/page-data.ts | ||
- core/app/[locale]/(default)/product/[slug]/page.tsx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Fixture } from '~/tests/fixtures/fixture'; | ||
import { InventorySettings } from '~/tests/fixtures/utils/api/settings'; | ||
|
||
export class SettingsFixture extends Fixture { | ||
private initialInventorySettings: InventorySettings | null = null; | ||
|
||
async getInventorySettings(): Promise<InventorySettings> { | ||
const settings = await this.api.settings.getInventorySettings(); | ||
|
||
return settings; | ||
} | ||
|
||
async setInventorySettings(settings: InventorySettings): Promise<void> { | ||
if (!this.initialInventorySettings) { | ||
this.initialInventorySettings = await this.getInventorySettings(); | ||
} | ||
|
||
await this.api.settings.setInventorySettings(settings); | ||
} | ||
|
||
async cleanup() { | ||
if (this.initialInventorySettings) { | ||
await this.api.settings.setInventorySettings(this.initialInventorySettings); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { z } from 'zod'; | ||
|
||
import { httpClient } from '../client'; | ||
import { apiResponseSchema } from '../schema'; | ||
|
||
import { InventorySettings, SettingsApi } from '.'; | ||
|
||
const InventorySettingsSchema = z | ||
.object({ | ||
default_out_of_stock_message: z.string(), | ||
show_out_of_stock_message: z.boolean(), | ||
stock_level_display: z.enum(['dont_show', 'show', 'show_when_low']).nullable(), | ||
}) | ||
.transform( | ||
(data): InventorySettings => ({ | ||
defaultOutOfStockMessage: data.default_out_of_stock_message, | ||
showOutOfStockMessage: data.show_out_of_stock_message, | ||
stockLevelDisplay: data.stock_level_display, | ||
}), | ||
); | ||
|
||
const transformInventorySettingsData = (data: InventorySettings) => ({ | ||
default_out_of_stock_message: data.defaultOutOfStockMessage, | ||
show_out_of_stock_message: data.showOutOfStockMessage, | ||
stock_level_display: data.stockLevelDisplay, | ||
}); | ||
|
||
export const settingsHttpClient: SettingsApi = { | ||
getInventorySettings: async (): Promise<InventorySettings> => { | ||
const resp = await httpClient | ||
.get(`/v3/settings/inventory`) | ||
.parse(apiResponseSchema(InventorySettingsSchema)); | ||
|
||
return resp.data; | ||
}, | ||
setInventorySettings: async (settings: InventorySettings): Promise<void> => { | ||
await httpClient.put(`/v3/settings/inventory`, transformInventorySettingsData(settings)); | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface InventorySettings { | ||
readonly defaultOutOfStockMessage?: string; | ||
readonly showOutOfStockMessage?: boolean; | ||
readonly stockLevelDisplay?: 'dont_show' | 'show' | 'show_when_low' | null; | ||
} | ||
|
||
export interface SettingsApi { | ||
getInventorySettings: () => Promise<InventorySettings>; | ||
setInventorySettings: (settings: InventorySettings) => Promise<void>; | ||
} | ||
|
||
export { settingsHttpClient } from './http'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
t
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's defined on this line where translations related to "Product" page are fetched.