Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/resources/swell_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface SwellProductOption {

export interface SwellVariant {
id: string;
sku?: string;
name: string;
option_value_ids: string[];
selected_option_values: string[];
Expand Down
16 changes: 13 additions & 3 deletions src/resources/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ export default class SwellVariant extends SwellStorefrontRecord<SwellVariantType
id: string,
query?: SwellData,
) {
// current search parameters
const params = swell.queryParams;

super(swell, 'products:variants', id, query, async function () {
const variant = await this._swell.get<SwellVariantType>(
'/products:variants/{id}',
{ id: this._id },
'/products:variants/:last',
{ $or: [{ id: this._id }, { sku: this._id }] },
);

return variant ?? null;
// add swell properties to the resolved object
return transformSwellVariant(
params,
product instanceof SwellStorefrontRecord
? ((await product.resolve()) as SwellProduct)
: product,
variant as SwellVariantType,
);
});

this.product = product;
Expand Down