This repository has been archived by the owner on Dec 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Fulfillment Support and Added Product Variant Support (#24)
* Adding fulfillment support * Removing options references * Adding casting * Revert "Adding casting" This reverts commit d04956c. * Found serious errors in my previous PR * add product variants service and export * Adding proper variant support * Fixing update
- Loading branch information
1 parent
6a2ce3e
commit 0dce9a8
Showing
3 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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,59 @@ | ||
import * as Options from '../options'; | ||
import { ProductVariant } from '../models'; | ||
import { BaseService } from '../infrastructure'; | ||
|
||
/** | ||
* A service for manipulating a blog's product variants. | ||
*/ | ||
export class ProductVariants extends BaseService { | ||
constructor(shopDomain: string, accessToken: string) { | ||
super(shopDomain, accessToken, ""); | ||
} | ||
|
||
/** | ||
* Gets a variant with the given id. | ||
* @param id Id of the variant being retrieved. | ||
* @param options Options for filtering the result. | ||
*/ | ||
public get(id: number, options?: Options.FieldOptions) { | ||
return this.createRequest<ProductVariant>("GET", `variants/${id}.json`, "variant", options); | ||
} | ||
|
||
/** | ||
* Lists up to 250 variants for the given product. | ||
* @param productId Id of the product that the variants belong to. | ||
* @param options Options for filtering the results. | ||
*/ | ||
public list(productId: number, options?: Options.FieldOptions) { | ||
return this.createRequest<ProductVariant>("GET", `products/${productId}/variants.json`, "variants", options); | ||
} | ||
|
||
/** | ||
* Counts the variants on the given product. | ||
* @param productId Id of the product that the variants belong to. | ||
* @param options Options for filtering the results. | ||
*/ | ||
public count(productId: number, options?: Options.FulfillmentCountOptions) { | ||
return this.createRequest<number>("GET", `products/${productId}/variants/count.json`, "count", options); | ||
} | ||
|
||
/** | ||
* Updates an variant with the given id. | ||
* @param id Id of the variant. | ||
* @param productVariant The updated variant. | ||
*/ | ||
public update(id: number, variant: ProductVariant) { | ||
return this.createRequest<ProductVariant>("PUT", `variants/${id}.json`, "variant", { variant }); | ||
} | ||
|
||
/** | ||
* Deletes the variant with the given variantId. | ||
* @param productId Id of the product that the varaint belongs to. | ||
* @param variantId Id of the variant to delete. | ||
*/ | ||
public delete(productId: number, variantId: number) { | ||
return this.createRequest<void>("DELETE", `products/${productId}/variants/${variantId}.json`); | ||
} | ||
} | ||
|
||
export default ProductVariants; |