Methods

The Vinoshipper object exposes a number of methods to extend your integration.

📘

Window Scope

These methods are called directly on the Vinoshipper object on the top most Window object. While in some cases window.Vinoshiper may work, sometimes the focus is set to a different window object.

To consistently call the object, we highly suggest calling window.top.Vinoshipper. This insures you're calling the top most window object at all times.

Core

init

init(producerID: number, [options : VinoshipperConfig | undefined]) : Promise<void>

getId () : number | null

producerId: Number, Required
options: See above configuration options.

Initializes the Vinoshipper Injector for use. Returns a Promise<void> allowing for actions after initialization.

render

render() : Promise<void>

Detects all HTML elements and renders Vinoshipper objects that are not yet rendered, except for the Cart and Cart Button.

This function automatically runs with init() unless the setting autoRender is false.

isLoaded

isLoaded() : boolean

Returns true if Vinoshipper is loaded. This is different from rendering Vinoshipper components.

isRendered

isRendered() : boolean

Returns true if Vinoshipper Cart is rendered. This may also include other elements if autoRender was set to true.

isDebug

isDebug() : boolean

Returns true if Vinoshipper Injector is in debug mode.

getId

Returns the Producer ID.

getServer

getServer( includeProtocol : boolean = true ) : string | undefined

includeProtocol: Boolean, if false, returns the server string without the protocol (<https://>).

Returns the Vinoshipper server URL string.

getId

getId () : number | null

Returns the Producer ID.

Cart

getCart

getCart() : Cart | null

Returns the Vinoshipper Cart object, or null if not defined.

getCartCheckout

getCartCheckout() : URL

Returns an URL object of the Vinoshipper checkout URL for the customer.

getLinkParams

getLinkParams (url : URL) : Promise<URL>

Returns the given URL object with any activated Analytics properties for cross-domain tracking. Will return an unaltered URL object if analytics isn't active.

cartOpen

cartOpen() : void

Opens the Vinoshipper Cart.

cartClose

cartClose() : void

Closes the Vinoshipper Cart.

Themes

getTheme

getTheme( withPrefix = false ) : string | null

withPrefix: Boolean, if true returns the CSS class name for the theme.

Returns the class name of the set theme. Returns null if the theme was not defined.

Setting withPrefix will return the theme in the standard Vinoshipper CSS class name.

isThemeDark

isThemeDark () : boolean

Returns if the set theme is a dark contrast theme. Will return true when theme is set to 'dark', 'red_dark', etc.

Products

onProductAdd

onProductAdd (productId : number, qty : number = 1, options : VSCartOnProductAddOptions | undefined = undefined) : Promise<void>

Adds a product to the customer's cart.

productId is the product ID number.
qty the quantity of items to add to the cart (default is 1 item).

options is an optional VSCartOnProductAddOptions object. Setting update: true will overwrite the quantity of the project as set in qty .

export interface VSCartOnProductAddOptions {
  update?: boolean
}

onProductAddFormSubmit

onProductAddFormSubmit(event: SubmitEvent) : Promise<void | Error>

Club Registration

clubRegistrationClubSet

clubRegistrationClubSet (clubId : number, domId : string | undefined = undefined) : void

Sets the given club ID to either all rendered Club Registration instances, or to a specific ID.

If domID is not defined, ALL instances of club registration elements will be set to the given club ID.

/** This line sets all currently rendered Club Registration components to a club ID of 1. */
window.top.Vinoshipper.clubRegistrationClubSet(1)

/** This line sets the Club Registration component with the ID "club-registration-main" to a club ID of 1. */
window.top.Vinoshipper.clubRegistrationClubSet(1, 'club-registration-main')

If the club ID is not in the list of clubs, the club will not be set and no error will be returned. This can happen when:

  • The club ID doesn't exist in the producer account
  • The Club Registration element defines the data-vs-club-allow attribute and does not include the given club ID.