-
Plugins
See also in Portuguese.
Call the plugin in an empty div:
$('.sku-selector-container').skuSelector(data, options);
-
datamust be a JSON with API standard SKUs. -
options(optional) is an object that may have the following properties:-
selectOnOpeningdefault:false. Iftrue, at initialization the plugin selects the first available SKU (the first one that comes in the array). -
modalLayoutdefault:false. Iftrue, it uses the modal template. -
warnUnavailabledefault:false. Iftrue, it shows "notify me" form when an unavailable SKU is selected. -
showPriceRangedefault:false. Iftrue, it shows the minimum and maximum price among the selectable SKUs with the dimensions already selected. -
forceInputTypedefault:null. If not falsy, it forces the inputType of all dimensions to be that.
-
Triggers the following events:
skuReady.vtex []when the SKU Selector is rendered.skuDimensionChanged.vtex [productId, name, value]when a dimension is selected.skuSelected.vtex [productId, sku]when an SKU is defined.skuUnselected.vtex [productId, selectableSkus]when the SKU becomes undefined.
Call the plugin in an empty div:
$('.quantity-selector-container').quantitySelector(productId, options);
-
productIdthe product ID. -
options(optional) is an object that may have the following properties:-
unitBaseddefault:false. Defines whether to use bulk selector (quantity calculator). -
unitVariationsdefault:[]. IfunitBased == true, specifies the unit options for each SKU. It is a collection of{skuId: Number, measurementUnit: String, unitMultiplier: Number}. -
maxdefault:10. Defines the maximum amount that can be selected. -
initialQuantitydefault:1. Sets the quantity initially selected. -
decimalPlacesdefault:2. Sets the number of decimal places for the units input. It should not exceed 12.
-
Triggers the following events:
quantityReady.vtex [productId, quantity]when the Quantity Selector is rendered.quantityChanged.vtex [productId, quantity]when quantity is changed.
It listens for the following events:
quantityChanged.vtex [productId, quantity]The quantity can be changed through external scripts and the plugin will be updated.
Call the plugin in an empty div:
$('.acc-selector-container').accessoriesSelector(productId, data, options);
-
productIdthe product ID which is the accessories’ parent. -
datamust be a JSON with API standard accessories. -
options(none currently.)
Triggers the following events:
accessoriesUpdated.vtex [productId, accessories]when an accessory is changed. Theaccessoriesarray contains the accessories of a particular product, with properties likeskuandquantity.
Listens for changes in the selected SKU and updates the price labels.
Uses standard price information when there is no SKU selected.
Call the plugin in an empty div. If it contains some HTML, it will be used when a Sku is not defined.
$('.productPrice').price(productId, options);
-
productIdthe product ID. -
options(optional) is an object that can have the following properties-
originalSkudefault:null. Must be set if the above option istrue. -
modalLayoutdefault:false. Iftrue, it uses the modal template.
-
Listens for the following events:
skuSelected.vtex [productId, sku]skuUnselected.vtex [productId, selectableSkus]
Offers a form for calculating shipping, plus a button to show it.
Call the plugin in an empty div.
$('.shipping-calc-ref').shippingCalculator(productId, options);
-
productIdthe product ID. -
options(optional) is an object that can have the following properties:-
stringsSets the messages to be displayed.Default:
{ "calculateShipping": 'Calcule o valor do frete e prazo de entrega para a sua região:', "enterPostalCode": 'Calcular o valor do frete e verificar disponibilidade:', "requiredPostalCode": 'O CEP deve ser informado.', "invalidPostalCode": 'CEP inválido.', "requiredQuantity": 'É necessário informar a quantidade do mesmo Produto.', "siteName": 'Vtex.Commerce.Web.CommerceContext.Current.WebSite.Name', "close": 'Fechar' }Suggested english version:
{ "calculateShipping": 'Calculate the shipping value and delivery deadline for your region:', "enterPostalCode": 'Calculate the shipping value and check availability:', 'requiredPostalCode': 'The ZIP code must be informed.', 'invalidPostalCode': 'Invalid ZIP code.', 'requiredQuantity': 'You must enter the quantity of the same Product.', "siteName": 'Vtex.Commerce.Web.CommerceContext.Current.WebSite.Name', "close": 'Close' }
-
Listens for the following events:
skuSelected.vtex [productId, sku]skuUnselected.vtex [productId, selectableSkus]quantityReady.vtex [productId, quantity]quantityChanged.vtex [productId, quantity]
Call the plugin on the a that acts as a buy button:
$('.buy-button').buyButton(productId, data, options);
-
productIdthe product ID. It may be an array of product IDs - in such case, it will be a button that enables buying all products at the same time. -
data(optional) is an object that can have thesku,quantity,sellerandsalesChannelproperties. -
options(optional) is an object that may have the following properties.-
errorMessageError message to be triggered if the user clicks the button without having chosen an SKU. This message will appear in the parameters of thevtex.buyButton.failedAttemptevent. Default: "Please select the desired template." -
alertOnErrordefault:true. Determines whether to display an alert with theerrorMessage. -
redirectdefault:true. Sets theRedirectproperty in the querystring. Must betruefor product page, andfalsefor modal. -
instaBuydefault:false. Iftrue, when an available SKU is selected, the button is clicked. -
hideUnselecteddefault:false. Iftrue, it is hidden when there is no SKU selected. -
hideUnavailabledefault:false. Iftrue, it is hidden when the selected SKU is unavailable. -
targetdefault:null. Sets thetargetquery parameter. A valid value is"orderform". -
requireAllSkusdefault:false. IfproductIdis an array, this option determines whether all product IDs must have an SKU selected, or whether partial purchases are accepted (only for those selected).
-
Triggers the following events:
modalHide.vtex []whenredirect=falseand the button is clicked.cartProductAdded.vtex []whenredirect=false, the button is clicked and the AJAX response is returned.buyButtonFailedAttempt.vtex [errorMessage]when the button is clicked but there’s no valid SKU.buyButtonThrough.vtex [url]when the button is clicked and there is a valid SKU.
Listens for the following events:
skuSelected.vtex [productId, sku]skuUnselected.vtex [productId, selectableSkus]quantityChanged.vtex [productId, quantity]accessorySelected.vtex [productId, accessory]
Call the plugin in an empty div:
$('.portal-notify-me-ref').notifyMe(productId, options);
-
productIdthe product ID. -
options(opcional) is an object that may have the following properties.-
ajaxdefault:true. Defines whether the form submit should be done with AJAX. -
skudefault:null. Sets the SKU to be used. If it exists, it ignores SKU selection events. -
stringsSets the messages to be displayed.Default:
{ "title": "", "explanation": "Para ser avisado da disponibilidade deste Produto, basta preencher os campos abaixo.", "namePlaceholder": "Digite seu nome...", "emailPlaceholder": "Digite seu e-mail...", "loading": "Carregando...", "success": "Cadastrado com sucesso. Assim que o produto for disponibilizado você receberá um email avisando.", "error": "Não foi possível cadastrar. Tente mais tarde." }Suggested english version:
{ "title": "", "explanation": "To be notified of the availability of this Product, just fill in the fields below.", "namePlaceholder": "Enter your name...", "emailPlaceholder": "Enter your email...", "loading": "Loading...", "success": "Successfully registered. As soon as the product is made available you will receive an email notifying you.", "error": "Registration failed, please try again later." }
-
Triggers the following events:
notifyMeSubmitted.vtex [productId, sku, promise]: when the form is sent.
Listens for the following events:
skuSelected.vtex [productId, sku]skuUnselected.vtex [productId, selectableSkus]
Call the plugin in an empty div:
$('.portal-minicart-ref').minicart(options);
-
options(optional) is an object that may have the following properties-
valuePrefixdefault:"R$ ". Sets the text to be displayed before the value. -
valueSufixdefault:"". Sets the text to be displayed after the value. -
availabilityMessagesSets the messages displayed for each API availability code.Default:
{ "available": "", "unavailableItemFulfillment": "Este item não está disponível no momento.", "withoutStock": "Este item não está disponível no momento.", "cannotBeDelivered": "Este item não está disponível no momento.", "withoutPrice": "Este item não está disponível no momento.", "withoutPriceRnB": "Este item não está disponível no momento.", "nullPrice": "Este item não está disponível no momento." }Suggested english version:
{ "available": "", "unavailableItemFulfillment": "This item is currently unavailable.", "withoutStock": "This item is currently unavailable.", "cannotBeDelivered": "This item is currently unavailable.", "withoutPrice": "This item is currently unavailable.", "withoutPriceRnB": "This item is currently unavailable.", "nullPrice": "This item is currently unavailable." } -
showMinicartdefault:true. Defines whether the minicart should be displayed. -
showTotalizersdefault:true. Defines whether the totalizers should be displayed.
-
Triggers the following events:
cartProductRemoved.vtex []when an item is removed by the minicart.minicartMouseOver.vtex []minicartMouseOut.vtex []minicartUpdated.vtex []
Listens for the following events:
cartProductAdded.vtex []the Minicart is updated.cartProductRemoved.vtex []the Minicart is updated.
Utilitary expiration timer, reset by events. When time expires, the user session is cleaned up (cookies are cleared) and the user is redirected to a URL.
Start expiration timer.
Parameters and defaults:
- url = '/'
- millis = 10 * 60 * 1000 (10 minutes)
- events = ["mousemove", "keyup", "click", "scroll"]
Stops current expiration timer.
The options can be passed in three ways. They are, in order of priority:
- Through JavaScript, in the plugin request.
- With
data-attributes in the elements.. - Changing the default options (object
$.fn.nomeDoPlugin.default).
After a plugin is initialized, the target element will contain, in its data object (access via $().data()), a reference to its plugin instance.
| Plugin | jQuery | front.utils | Dust (core) | Catalog SDK |
|---|---|---|---|---|
| Sku Selector | ✔ | ✔ | ✔ | ✗ |
| Quantity Selector | ✔ | ✗ | ✔ | ✗ |
| Accessories Selector | ✔ | ✔ | ✔ | ✗ |
| Price | ✔ | ✔ | ✔ | ✗ |
| Shipping Calculator | ✔ | ✗ | ✔ | ✔ |
| Buy Button | ✔ | ✗ | ✗ | ✔ |
| Notify Me | ✔ | ✗ | ✔ | ✔ |
| Minicart | ✔ | ✔ | ✔ | ✗ |
| Expiration | ✔ | ✗ | ✗ | ✗ |