Javascript (skio-plan-picker.js)
Parameters
Parameter | Type | Requirement |
---|---|---|
| Required | |
| Optional |
$planPicker
$planPicker
The DOM
element to be used as the plan picker
overrides
overrides
For overriding specific values (i.e. overrides.product would become the default product)
Events
skio:plan-picker:loaded
skio:plan-picker:loaded
(window) when skio script is loaded
skio:plan-picker:init
skio:plan-picker:init
($planPicker) when skio instance is initialized
skio:plan-picker:updated
skio:plan-picker:updated
($planPicker) when skio instance is updated
File loading & multiple instances
The script starts with a check to ensure that the script has not already been loaded on the page, returning an Error if the script has already loaded; this is in the case of multiple plan picker instances on the page, which may attempt to re-trigger the lazy loading of the JS file. Once we are sure the script hasn't yet loaded, we define a window
variable of window.SkioPlanPickerInstances
as an empty list, which we will populate with all instances of the plan picker element.
With the check complete and array initialized, it initializes the main instance, window.SkioPlanPicker
, which immediately initializes the skio
object.
Error Reporting
Our built-in error reporting contains 3 levels (info
, warn
, error
) that can provide varying levels of detail for use in debugging potential issues.
For example, the assert()
method is immediately used to confirm the following:
The required
$planPicker
parameter was passed in,The
$planPicker
's[skio-plan-picker]
property contains a uniquekey
value not used by any otherwindow.SkioPlanPicker
instances,The
$planPicker
's[skio-discount-format]
property contains a valid discount format ('percent'
or'absolute'
)
Selectors
The following selectors are utilized to access various elements in the DOM as needed for various pieces of functionality:
sellingPlanId
sellingPlanId
Default value: 'input[name="selling_plan"]'
Use: access element inside associated form[action="/cart/add"]
to get/update the element's value as variant / selling plan selections change
variantId
variantId
Default value: '[name="id"]'
Use: access element inside associated form[action="/cart/add"]
to get/update the element's value as variant / selling plan selections change
productJson
productJson
Default value: '[skio-product-json]'
Use: load in the product
data that was stored as a JSON
script in skio-plan-picker.liquid
onetime
onetime
Default value: '[skio-one-time]'
Use: access element for the plan picker's one-time radio button / selector
groupContainer
groupContainer
Default value: '[skio-group-container]'
Use: access elements used as the parent element / container for the plan picker's one-time radio buttons / selectors
sellingPlanGroup
method
sellingPlanGroup
method Parameter: id
of a selling plan group (optional)
Default value: `[skio-selling-plan-group${id ? `="${id}"` : ''}]`
Use: access elements used as selling plan radio buttons / selectors in order to get the group.id
of the selected selling plan / update the checked
value of the element
groupInput
groupInput
Default value: `input[name="skio-group-${skio.key}"]`
Use: access input elements used to identify which selling plan is currently selected; if a new groupInput
is checked, updateSellingPlan
will fire
sellingPlans
method
sellingPlans
method Parameter: id
of a selling plan group (optional)
Default value: `[skio-selling-plans${id ? `="${id}"` : ''}]`
Use: access the select
element that displays frequency options
onetimePrice
onetimePrice
Default value: '[skio-onetime-price]'
Use: access the element containing the value of the one-time price
subscriptionPrice
subscriptionPrice
Default value: '[skio-subscription-price]'
Use: access the element containing the value of the subscription price
discount
discount
Default value: '[skio-discount]'
Use: access the element containing the value of the discount (absolute or percent, depending on configuration)
discountProperty
discountProperty
Default value: '[name="properties[Discount]"]'
Use: access a hidden input element that stores the current value of the discount as an attribute
Form
The $planPicker
needs to be associated with a form[action="/cart/add"]
element. To associate a form, the $planPicker
can either be placed:
Inside a
form[action="/cart/add"]
,Outside a
form
if theskio-plan-picker.liquid
snippet had theform_id
Liquid parameter passed in to indicate theform[action="/cart/add"]
to be associated with the$planPicker
(i.e. LINK TO LIQUID DOCS HERE ),Outside a form if there is a
form[action="/cart/add"]
on the page, in which case the closestform[action="/cart/add"]
will be selected
The above selectors
are used to assert that there is only 1 selling plan input
element and that the associated form[action="/cart/add"]
exists.
Product
If a product
object was passed with the overrides parameter, that product
data is used for the plan picker functionality. Otherwise, the product
data from the productJson
selector is loaded in.
Last updated