Added virtually all of the data returned by the REST API to the SimpleProduct model
There's still a few things missing but I think this is a much better start than where we were before.
This commit is contained in:
parent
72d09026a6
commit
f438ddc80a
|
@ -1,4 +1,14 @@
|
|||
import { Model } from '../model';
|
||||
import { DateTime, PostStatus } from '../shared-types';
|
||||
import {
|
||||
BackorderStatus,
|
||||
CatalogVisibility,
|
||||
ProductAttribute,
|
||||
ProductDownload,
|
||||
ProductImage,
|
||||
ProductTerm, StockStatus,
|
||||
Taxability,
|
||||
} from './shared-types';
|
||||
|
||||
/**
|
||||
* The base class for all product types.
|
||||
|
@ -11,10 +21,318 @@ export abstract class AbstractProduct extends Model {
|
|||
*/
|
||||
public readonly name: string = '';
|
||||
|
||||
/**
|
||||
* The slug of the product.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly slug: string = '';
|
||||
|
||||
/**
|
||||
* The permalink of the product.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly permalink: string = '';
|
||||
|
||||
/**
|
||||
* The datetime when the product was created.
|
||||
*
|
||||
* @type {DateTime}
|
||||
*/
|
||||
public readonly created: DateTime = new DateTime();
|
||||
|
||||
/**
|
||||
* The datetime when the product was last modified.
|
||||
*
|
||||
* @type {DateTime}
|
||||
*/
|
||||
public readonly modified: DateTime = new DateTime();
|
||||
|
||||
/**
|
||||
* The product's current post status.
|
||||
*
|
||||
* @type {PostStatus}
|
||||
*/
|
||||
public readonly postStatus: PostStatus = '';
|
||||
|
||||
/**
|
||||
* The product's short description.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly shortDescription: string = '';
|
||||
|
||||
/**
|
||||
* The product's full description.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly description: string = '';
|
||||
|
||||
/**
|
||||
* The product's SKU.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly sku: string = '';
|
||||
|
||||
/**
|
||||
* An array of the categories this product is in.
|
||||
*
|
||||
* @type {ReadonlyArray.<ProductTerm>}
|
||||
*/
|
||||
public readonly categories: readonly ProductTerm[] = [];
|
||||
|
||||
/**
|
||||
* An array of the tags this product has.
|
||||
*
|
||||
* @type {ReadonlyArray.<ProductTerm>}
|
||||
*/
|
||||
public readonly tags: readonly ProductTerm[] = [];
|
||||
|
||||
/**
|
||||
* Indicates whether or not the product is currently able to be purchased.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isPurchasable: boolean = true;
|
||||
|
||||
/**
|
||||
* Indicates whether or not the product should be featured.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isFeatured: boolean = false;
|
||||
|
||||
/**
|
||||
* Indicates that the product is delivered virtually.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isVirtual: boolean = false;
|
||||
|
||||
/**
|
||||
* The attributes for the product.
|
||||
*
|
||||
* @type {ReadonlyArray.<ProductAttribute>}
|
||||
*/
|
||||
public readonly attributes: readonly ProductAttribute[] = [];
|
||||
|
||||
/**
|
||||
* The images for the product.
|
||||
*
|
||||
* @type {ReadonlyArray.<ProductImage>}
|
||||
*/
|
||||
public readonly images: readonly ProductImage[] = [];
|
||||
|
||||
/**
|
||||
* Indicates whether or not the product should be visible in the catalog.
|
||||
*
|
||||
* @type {CatalogVisibility}
|
||||
*/
|
||||
public readonly catalogVisibility: CatalogVisibility = CatalogVisibility.Everywhere;
|
||||
|
||||
/**
|
||||
* The current price of the product.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly price: string = '';
|
||||
|
||||
/**
|
||||
* The regular price of the product when not discounted.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly regularPrice: string = '';
|
||||
|
||||
/**
|
||||
* Indicates that only one of a product may be held in the order at a time.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly onePerOrder: boolean = false;
|
||||
|
||||
/**
|
||||
* The taxability of the product.
|
||||
*
|
||||
* @type {Taxability}
|
||||
*/
|
||||
public readonly taxStatus: Taxability = Taxability.ProductAndShipping;
|
||||
|
||||
/**
|
||||
* The tax class of the product
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly taxClass: string = '';
|
||||
|
||||
/**
|
||||
* Indicates whether or not the product is currently on sale.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly onSale: boolean = false;
|
||||
|
||||
/**
|
||||
* The price of the product when on sale.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly salePrice: string = '';
|
||||
|
||||
/**
|
||||
* The timeframe during which the product should be one sale.
|
||||
*
|
||||
* @type {{start: DateTime, end: DateTime}}
|
||||
*/
|
||||
public readonly saleWindow?: { start: DateTime, end: DateTime };
|
||||
|
||||
/**
|
||||
* Indicates whether or not the product is downloadable.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isDownloadable: boolean = false;
|
||||
|
||||
/**
|
||||
* The downloads available for the product.
|
||||
*
|
||||
* @type {ReadonlyArray.<ProductDownload>}
|
||||
*/
|
||||
public readonly downloads: readonly ProductDownload[] = [];
|
||||
|
||||
/**
|
||||
* The maximum number of times a customer may download the product's contents.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly downloadLimit: number = -1;
|
||||
|
||||
/**
|
||||
* The number of days after purchase that a customer may still download the product's contents.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly daysToDownload: number = -1;
|
||||
|
||||
/**
|
||||
* The weight of the product in the store's current units.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly weight: string = '';
|
||||
|
||||
/**
|
||||
* The length of the product in the store's current units.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly length: string = '';
|
||||
|
||||
/**
|
||||
* The width of the product in the store's current units.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly width: string = '';
|
||||
|
||||
/**
|
||||
* The height of the product in the store's current units.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly height: string = '';
|
||||
|
||||
/**
|
||||
* Indicates that the product must be shipped.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly requiresShipping: boolean = false;
|
||||
|
||||
/**
|
||||
* Indicates that the product's shipping is taxable.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isShippingTaxable: boolean = false;
|
||||
|
||||
/**
|
||||
* The shipping class for the product.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly shippingClass: string = '';
|
||||
|
||||
/**
|
||||
* Indicates that a product should use the inventory system.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly trackInventory: boolean = false;
|
||||
|
||||
/**
|
||||
* The number of inventory units remaining for this product.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly remainingStock: number = -1;
|
||||
|
||||
/**
|
||||
* Indicates whether or not a product is in stock.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isInStock: boolean = false;
|
||||
|
||||
/**
|
||||
* The product's stock status.
|
||||
*
|
||||
* @type {StockStatus}
|
||||
*/
|
||||
public readonly stockStatus: StockStatus = ''
|
||||
|
||||
/**
|
||||
* The status of backordering for a product.
|
||||
*
|
||||
* @type {BackorderStatus}
|
||||
*/
|
||||
public readonly backorderStatus: BackorderStatus = BackorderStatus.Allowed;
|
||||
|
||||
/**
|
||||
* Indicates whether or not a product can be backordered.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly canBackorder: boolean = false;
|
||||
|
||||
/**
|
||||
* Indicates whether or not a product is on backorder.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isOnBackorder: boolean = false;
|
||||
|
||||
/**
|
||||
* Indicates whether or not a product allows reviews.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly allowReviews: boolean = false;
|
||||
|
||||
/**
|
||||
* The average rating for the product.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly averageRating: number = -1;
|
||||
|
||||
/**
|
||||
* The number of ratings for the product.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly numRatings: number = -1;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,262 @@
|
|||
import { DateTime } from '../shared-types';
|
||||
|
||||
/**
|
||||
* An enum describing the catalog visibility options for products.
|
||||
*
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum CatalogVisibility {
|
||||
/**
|
||||
* The product should be visible everywhere.
|
||||
*/
|
||||
Everywhere = 'visible',
|
||||
|
||||
/**
|
||||
* The product should only be visible in the shop catalog.
|
||||
*/
|
||||
ShopOnly = 'catalog',
|
||||
|
||||
/**
|
||||
* The product should only be visible in search results.
|
||||
*/
|
||||
SearchOnly = 'search',
|
||||
|
||||
/**
|
||||
* The product should be hidden everywhere.
|
||||
*/
|
||||
Hidden = 'hidden'
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the taxability of a product.
|
||||
*
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum Taxability {
|
||||
/**
|
||||
* The product and shipping are both taxable.
|
||||
*/
|
||||
ProductAndShipping = 'taxable',
|
||||
|
||||
/**
|
||||
* Only the product's shipping is taxable.
|
||||
*/
|
||||
ShippingOnly = 'shipping',
|
||||
|
||||
/**
|
||||
* The product and shipping are not taxable.
|
||||
*/
|
||||
None = 'none'
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates the status for backorders for a product.
|
||||
*
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum BackorderStatus {
|
||||
/**
|
||||
* The product is allowed to be backordered.
|
||||
*/
|
||||
Allowed = 'yes',
|
||||
|
||||
/**
|
||||
* The product is allowed to be backordered but it will notify the customer of that fact.
|
||||
*/
|
||||
AllowedWithNotification = 'notify',
|
||||
|
||||
/**
|
||||
* The product is not allowed to be backordered.
|
||||
*/
|
||||
NotAllowed = 'no'
|
||||
}
|
||||
|
||||
/**
|
||||
* A product's stock status.
|
||||
*
|
||||
* @typedef StockStatus
|
||||
* @alias 'instock'|'outofstock'|'onbackorder'|string
|
||||
*/
|
||||
export type StockStatus = 'instock' | 'outofstock' | 'onbackorder' | string
|
||||
|
||||
/**
|
||||
* A products taxonomy term such as categories or tags.
|
||||
*/
|
||||
export class ProductTerm {
|
||||
/**
|
||||
* The ID of the term.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly id: number = -1;
|
||||
|
||||
/**
|
||||
* The name of the term.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly name: string = '';
|
||||
|
||||
/**
|
||||
* The slug of the term.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly slug: string = '';
|
||||
|
||||
/**
|
||||
* Creates a new product term.
|
||||
*
|
||||
* @param {Partial.<ProductTerm>} properties The properties to set.
|
||||
*/
|
||||
public constructor( properties?: Partial< ProductTerm > ) {
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A product's download.
|
||||
*/
|
||||
export class ProductDownload {
|
||||
/**
|
||||
* The ID of the downloadable file.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly id: string = '';
|
||||
|
||||
/**
|
||||
* The name of the downloadable file.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly name: string = '';
|
||||
|
||||
/**
|
||||
* The URL of the downloadable file.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly url: string = '';
|
||||
|
||||
/**
|
||||
* Creates a new product download.
|
||||
*
|
||||
* @param {Partial.<ProductDownload>} properties The properties to set.
|
||||
*/
|
||||
public constructor( properties?: Partial< ProductDownload > ) {
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A product's attributes.
|
||||
*/
|
||||
export class ProductAttribute {
|
||||
/**
|
||||
* The ID of the attribute.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly id: number = -1;
|
||||
|
||||
/**
|
||||
* The name of the attribute.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly name: string = '';
|
||||
|
||||
/**
|
||||
* The sort order of the attribute.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly sortOrder: number = -1;
|
||||
|
||||
/**
|
||||
* Indicates whether or not the attribute is visible on the product page.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readonly isVisibleOnProductPage: boolean = false;
|
||||
|
||||
/**
|
||||
* The options which are available for the attribute.
|
||||
*
|
||||
* @type {ReadonlyArray.<string>}
|
||||
*/
|
||||
public readonly options: readonly string[] = [];
|
||||
|
||||
/**
|
||||
* Creates a new product attribute.
|
||||
*
|
||||
* @param {Partial.<ProductAttribute>} properties The properties to set.
|
||||
*/
|
||||
public constructor( properties?: Partial< ProductAttribute > ) {
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A product's image.
|
||||
*/
|
||||
export class ProductImage {
|
||||
/**
|
||||
* The ID of the image.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly id: number = -1;
|
||||
|
||||
/**
|
||||
* The date and time when the image was created.
|
||||
*
|
||||
* @type {DateTime}
|
||||
*/
|
||||
public readonly created: DateTime = new DateTime();
|
||||
|
||||
/**
|
||||
* The date and time when the image was modified.
|
||||
*
|
||||
* @type {DateTime}
|
||||
*/
|
||||
public readonly modified: DateTime = new DateTime();
|
||||
|
||||
/**
|
||||
* The URL for the image file.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly url: string = '';
|
||||
|
||||
/**
|
||||
* The name of the image file.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly name: string = '';
|
||||
|
||||
/**
|
||||
* The alt text to use on the image.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly altText: string = '';
|
||||
|
||||
/**
|
||||
* The sort order for the image.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
public readonly sortOrder: number = -1;
|
||||
|
||||
/**
|
||||
* Creates a new product image.
|
||||
*
|
||||
* @param {Partial.<ProductImage>} properties The properties to set.
|
||||
*/
|
||||
public constructor( properties?: Partial< ProductImage > ) {
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ export class SimpleProduct extends AbstractProduct {
|
|||
*
|
||||
* @param {Object} properties The properties to set in the object.
|
||||
*/
|
||||
public constructor( properties: Partial< SimpleProduct > = {} ) {
|
||||
public constructor( properties?: Partial< SimpleProduct > ) {
|
||||
super();
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ export class SettingGroup extends Model {
|
|||
*
|
||||
* @param {Object} properties The properties to set in the object.
|
||||
*/
|
||||
public constructor( properties: Partial< SettingGroup > = {} ) {
|
||||
public constructor( properties?: Partial< SettingGroup > ) {
|
||||
super();
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ export class Setting extends Model {
|
|||
*
|
||||
* @param {Object} properties The properties to set in the object.
|
||||
*/
|
||||
public constructor( properties: Partial< Setting > = {} ) {
|
||||
public constructor( properties?: Partial< Setting > ) {
|
||||
super();
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* A post's status.
|
||||
*
|
||||
* @typedef PostStatus
|
||||
* @alias 'draft'|'pending'|'private'|'publish'|string
|
||||
*/
|
||||
export type PostStatus = 'draft' | 'pending' | 'private' | 'publish' | string;
|
||||
|
||||
/**
|
||||
* A metadata object.
|
||||
*/
|
||||
export class MetaData {
|
||||
/**
|
||||
* The key of the metadata.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly key: string = '';
|
||||
|
||||
/**
|
||||
* The value of the metadata.
|
||||
*
|
||||
* @type {*}
|
||||
*/
|
||||
public readonly value: any = '';
|
||||
|
||||
/**
|
||||
* Creates a new metadata.
|
||||
*
|
||||
* @param {Partial.<MetaData>} properties The properties to set.
|
||||
*/
|
||||
public constructor( properties?: Partial< MetaData > ) {
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An object for more easily representing the dual local/gmt times returned by the API.
|
||||
*/
|
||||
export class DateTime {
|
||||
/**
|
||||
* The local time representation.
|
||||
*
|
||||
* @type {Date}
|
||||
*/
|
||||
public readonly local: Date = new Date();
|
||||
|
||||
/**
|
||||
* The GMT representation.
|
||||
*
|
||||
* @type {Date}
|
||||
*/
|
||||
public readonly gmt: Date = new Date();
|
||||
|
||||
/**
|
||||
* Creates a new datetime.
|
||||
*
|
||||
* @param {Partial.<DateTime>} properties The properties to set.
|
||||
*/
|
||||
public constructor( properties?: Partial< DateTime > ) {
|
||||
Object.assign( this, properties );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue