Documentation
Feedback
Guides
API Reference

Guides
UI Customization
vtex.js
vtex.js for Checkout

The Checkout module handles customer purchase information.

Checkout adds different details needed to create an order, such as customer profile, address, shipping, and item information.

The OrderForm is the structure that contains this clustered data. It has several sections, each with helpful information that can be accessed, manipulated, and changed. To learn more, read the OrderForm documentation.

Behavior of successive API requests

The checkout module encapsulates all requests that modify the orderForm and adds a cancellation behavior for subsequent requests.

Thus, subsequent requests to perform the same operation cause the abort of the previous request for the same operation. This means that if 3 successive requests are made for the same operation, the first 2 will be aborted, and only the third will be considered. For this reason, if more than one consumer uses the same Checkout instance, requests may be unintentionally aborted.

Consider the following scenario:

  • Application A creates variable API = new vtexjs.Checkout()

  • Plugin B uses API.sendAttachment() to send an address

  • Plugin C uses API.sendAttachment() to simultaneously send another address

  • Result: Call from B will be aborted and replaced with the call from C. This is expected. However, if Plugin B is waiting for the resolution of the call promise (e.g., using done()), it will never be successful because the request "failed" (was aborted).

There are two ways to solve this situation:

  • Each plugin uses its Checkout instance, e.g., var APIInternaDoPluginA = new vtexjs.Checkout().

  • The orderFormUpdated.vtex event handler is used to receive success notifications for Checkout modifications.

We recommend using extended-ajax.js (used by default in the bundle). With that, all requests are queued, so they do not happen in parallel.

Events

orderFormUpdated.vtex [orderForm]

When a call updates the orderForm, the orderFormUpdated.vtex event is fired. This is useful for different components that use vtex.js to stay updated without knowing the other present components.

Important: This event is only sent when the last pending request is finished. So, if multiple consecutive calls to the API are queued, the event will only be sent at the end of the last call.

checkoutRequestBegin.vtex [ajaxOptions]

When any request that changes the orderForm is started, this event is fired. It can be used, for example, to initiate a load on the screen and prevent the user from making further modifications. The ajaxOptions parameter is the option object originally used to initiate this request.

checkoutRequestEnd.vtex [orderForm|jqXHR]

When any request that changes the orderForm is finished, with or without success, this event is fired. Note that the argument can be an orderForm on success, or jqXHR in case of failure. It is not recommended to use this request to detect changes in the orderForm. Instead, use orderFormUpdated.vtex.

expectedOrderFormSections

You will notice that most methods require an expectedOrderFormSections argument.

The orderForm is made up of several sections (or attachments). You can request that only a few be sent in the response.

This primarily improves performance when you know your call will not affect the sections you did not ask for, or if you do not mind the changes.

In general, it is safe not to send this argument, in which case all sections will be required.

You can see a description of each section by taking a look at the _allOrderFormSections property.

Given this explanation, this argument will no longer be detailed in the method documentation.

Example


_10
$(window).on("orderFormUpdated.vtex", function(evt, orderForm) {
_10
alert("Someone changed the orderForm!")
_10
console.log(orderForm)
_10
})

getOrderForm(expectedOrderFormSections

Gets the current orderForm.

This is one of the most important methods. It is essential to make sure that an orderForm is available before making calls to change it.

Returns

Promise for the orderForm.

Example


_10
vtexjs.checkout.getOrderForm().done(function(orderForm) {
_10
console.log(orderForm)
_10
})

sendAttachment(attachmentId, attachment, expectedOrderFormSections

Sends an attachment to the current orderForm. (An attachment is a section.)

This makes it possible to update this section by sending new information, making changes, or removing something.

You must send the complete attachment. See examples.

Read the OrderForm documentation to learn more about sections.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
attachmentIdString containing the name of the attachment being sent.
attachmentObject containing the attachment.

Examples

Change clientProfileData

If you want to change the customer's first name, change the property firstName in clientProfileData.


_15
vtexjs.checkout
_15
.getOrderForm()
_15
.then(function(orderForm) {
_15
var clientProfileData = orderForm.clientProfileData
_15
clientProfileData.firstName = William
_15
return vtexjs.checkout.sendAttachment(
_15
"clientProfileData",
_15
clientProfileData
_15
)
_15
})
_15
.done(function(orderForm) {
_15
alert("Name changed!")
_15
console.log(orderForm)
_15
console.log(orderForm.clientProfileData)
_15
})

Change openTextField

The openTextField is a field for comments. Read the OrderForm documentation for more information.


_10
vtexjs.checkout
_10
.getOrderForm()
_10
.then(function(orderForm) {
_10
var obs = "No onion!"
_10
return vtexjs.checkout.sendAttachment("openTextField", { value: obs })
_10
})
_10
.done(function(orderForm) {
_10
console.log("openTextField filled with: ", orderForm.openTextField)
_10
})

addToCart(items, expectedOrderFormSections, salesChannel)

Add items to the orderForm.

This method does not automatically apply to promotions through UTM. To add promotions using UTM, do a sendAttachment of marketingData with the required information.

An item to be added is necessarily composed of: id, quantity, and seller. The id property can be obtained from the Catalog by looking at the ItemId of the item in the product item array.

Items that are already in the orderForm will remain unchanged.

Returns

Promise for the orderForm.

Arguments

NameType
itemsArray containing the set of items that will be added. Even if there is only one item, it must be wrapped in an array.
salesChannelNumber or String(Optional parameter, default = 1).

Example

Add an item with itemId 2000017893 from sales channel 3.


_10
var item = {
_10
id: 2000017893,
_10
quantity: 1,
_10
seller: "1",
_10
}
_10
vtexjs.checkout.addToCart([item], null, 3).done(function(orderForm) {
_10
alert("Item added!")
_10
console.log(orderForm)
_10
})

updateItems(items, expectedOrderFormSections)

Updates items in the orderForm.

An item is identified by its index property. In the orderForm, this property can be obtained by looking at the item index in the item array.

Read the OrderForm documentation to learn more about the item object.

Properties and orderForm items that are not sent, will remain unchanged.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
itemsArray containing the set of items that will be updated. Even if there is only one item, it must be wrapped in an array.
splitItemBoolean default: true. Indicates if a separate item should be created when the items to be updated have attachments/services.

Example

Change the quantity and the seller of the first item.


_15
vtexjs.checkout
_15
.getOrderForm()
_15
.then(function(orderForm) {
_15
var itemIndex = 0
_15
var item = orderForm.items[itemIndex]
_15
var updateItem = {
_15
index: itemIndex,
_15
quantity: 5,
_15
}
_15
return vtexjs.checkout.updateItems([updateItem], null, false)
_15
})
_15
.done(function(orderForm) {
_15
alert("Items updated!")
_15
console.log(orderForm)
_15
})

removeItems(items, expectedOrderFormSections)

Removes items from the orderForm.

An item is identified by its index property. In the orderForm, this property can be obtained by looking at the item index in the item array.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
itemsArray containing the set of items that will be removed. Even if there is only one item, it must be wrapped in an array.

Example

Remove the first item.


_17
vtexjs.checkout
_17
.getOrderForm()
_17
.then(function(orderForm) {
_17
var itemIndex = 0
_17
var item = orderForm.items[itemIndex]
_17
var itemsToRemove = [
_17
{
_17
index: 0,
_17
quantity: 0,
_17
},
_17
]
_17
return vtexjs.checkout.removeItems(itemsToRemove)
_17
})
_17
.done(function(orderForm) {
_17
alert("Item removed!")
_17
console.log(orderForm)
_17
})

removeAllItems(expectedOrderFormSections)

Removes all items from the orderForm.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Example


_10
vtexjs.checkout.removeAllItems()
_10
.done(function(orderForm) {
_10
alert('Empty cart.');
_10
console.log(orderForm);
_10
});

cloneItem(itemIndex, newItemsOptions, expectedOrderFormSections)

Creates one or more items in the cart based on another item. The item to be cloned must have an attachment.

An item is identified by its index property. In the orderForm, this property can be obtained by looking at the item index in the item array.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
itemIndexIndex number of the item to which the offer is applied.
newItemsOptionsArray (optional) with the properties that should be assigned to the new items.

Example

Create a new item based on the item with index 0.


_10
var itemIndex = 0;
_10
_10
vtexjs.checkout.cloneItem(itemIndex)
_10
.done(function(orderForm) {
_10
console.log(orderForm);
_10
});

Create a new item based on an item with index 0, quantity 2, and an attachment already configured.


_18
var itemIndex = 0
_18
var newItemsOptions = [
_18
{
_18
itemAttachments: [
_18
{
_18
name: "Customization",
_18
content: {
_18
Name: "Robert",
_18
},
_18
},
_18
],
_18
quantity: 2,
_18
},
_18
]
_18
_18
vtexjs.checkout.cloneItem(itemIndex, newItemsOptions).done(function(orderForm) {
_18
console.log(orderForm)
_18
})

calculateShipping(address)

Receives an address and records it in the user's shippingData.

The effect is that the shipping will be calculated and available in one of the orderForm totalizers.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
addressObject containing the address that must have at least postalCode and country. From these two properties, the others will be inferred.

Example


_15
vtexjs.checkout.getOrderForm()
_15
.then(function(orderForm) {
_15
var postalCode = '22250-040'; // no hyphen is also OK
_15
var country = 'BRA';
_15
var address = {
_15
"postalCode": postalCode,
_15
"country": country
_15
};
_15
return vtexjs.checkout.calculateShipping(address)
_15
})
_15
.done(function(orderForm) {
_15
alert(Shipping calculated.');
_15
console.log(orderForm.shippingData);
_15
console.log(orderForm.totalizers);
_15
});

simulateShipping(items, postalCode, country, salesChannel) [DEPRECATED]

Receives an item list, postalCode, and country and simulates the shipping of these items for this address.

The difference from calculateShipping is that this call is isolated. It can be used for an arbitrary set of items and does not bind the address to the user.

The result of this simulation includes the different carriers that can be used for each item, including name, delivery date, and price.

It is ideal for simulating shipping on the product page.

Returns

Promise with the result. The result has the property logisticsInfo.

Arguments

NameType
itemsArray of objects that have at least ID, quantity, and seller.
postalCodeString with the postal code. (CEP for Brazil.)
countryString with the three-letter country code. For example, "BRA" for Brazil.
salesChannelNumber or string. (Optional parameter, default = 1.)

Example


_26
// `Items` must be an array of objects containing at least the information below
_26
var items = [
_26
{
_26
id: 5987, // item sku
_26
quantity: 1,
_26
seller: "1",
_26
},
_26
]
_26
_26
// For Brazil, `postalCode` must be the customer's CEP
_26
var postalCode = "22250-040"
_26
// This also works
_26
// var postalCode = '22250040';
_26
_26
// `country` must be the 3-letter country code
_26
var country = "BRA"
_26
_26
vtexjs.checkout
_26
.simulateShipping(items, postalCode, country)
_26
.done(function(result) {
_26
/* `result.logisticsInfo` is an array of objects.
_26
Each object corresponds to the logistics information (shipping) for each item in the order in which the items were sent.
_26
For example, `result.logisticsInfo[0].slas` will contain different carrier options (with deadline and price) for the first item.
_26
For more details, check the orderForm documentation.
_26
*/
_26
})

simulateShipping(shippingData, orderFormId, country, salesChannel)

Receives an object containing shipping information (shippingData), the orderFormId, and country, and simulates the shipping of these items for this address.

The difference from calculateShipping is that this call receives different parameters to get the same result.

This is an overloaded function.

The result of this simulation is the same as the last one; it returns different carriers that can be used for each item, including name, delivery date, and price.

Returns

Promise for the result. The result has the property logisticsInfo.

Arguments**

NameType
shippingDataObject containing shipping and item information through logisticsInfo and selectedAddresses.
orderFormIdString representing the ID of the current session's orderForm.
countryString with the three-letter country code. For example, "BRA" for Brazil.
salesChannelNumber or string. (Optional parameter, default = 1.)

Example


_23
// `logisticsInfo` must be an array of logisticsInfo objects and contain at least one selectedAddresses
_23
var shippingData = [
_23
{
_23
logisticsInfo: logisticsInfoList,
_23
selectedAddresses: selectedAddressesList,
_23
},
_23
]
_23
_23
// `orderFormId` must be an ID of the session's orderForm
_23
var orderFormId = "9f879d435f8b402cb133167d6058c14f"
_23
_23
// `country` must be the 3-letter country code
_23
var country = "BRA"
_23
_23
vtexjs.checkout
_23
.simulateShipping(items, postalCode, country)
_23
.done(function(result) {
_23
/* `result.logisticsInfo` is an array of objects.
_23
Each object corresponds to the logistics information (shipping) for each item in the order in which the items were sent.
_23
For example, `result.logisticsInfo[0].slas` contains the different carrier options (with deadline and price) for the first item.
_23
For more details, check the orderForm documentation.
_23
*/
_23
})

getAddressInformation(address)

Given an incomplete address with postalCode and country, returns a complete address with city, state, street, and any other available information.

Returns

Promise for the complete address.

Arguments

NameType
addressObject with the address that must have at least postalCode and country. With these two properties, the others will be inferred.

Example


_16
// For Brazil, `postalCode` must be the customer's CEP
_16
var postalCode = "22250-040"
_16
// No hyphen also works
_16
// var postalCode = '22250040';
_16
_16
// `country` must be the 3-letter country abbreviation
_16
var country = "BRA"
_16
_16
var address = {
_16
postalCode: postalCode,
_16
country: country,
_16
}
_16
_16
vtexjs.checkout.getAddressInformation(address).done(function(result) {
_16
console.log(result)
_16
})

getProfileByEmail(email, salesChannel)

Performs partial user login using email.

The information will likely come masked, and you will not be able to edit it if the user already exists. For this, you need to authenticate with VTEX ID. You can check through the canEditData property of the orderForm. For more information, read the OrderForm documentation.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
emailString
salesChannelNumber or string (default = 1).

Example


_10
vtexjs.checkout
_10
.getOrderForm()
_10
.then(function(orderForm) {
_10
var email = "example@vtex.com"
_10
return vtexjs.checkout.getProfileByEmail(email)
_10
})
_10
.done(function(orderForm) {
_10
console.log(orderForm)
_10
})

removeAccountId(accountId, expectedOrderFormSections)

In orderForm.paymentData.availableAccounts, you find the user's payment accounts. Each account has several details, one of which is the accountId. This ID can be used in this method for removing the payment account.

Do not forget to use getOrderForm first.

Returns

Promise of success.

Arguments

NameType
accountIdString

Example


_10
vtexjs.checkout
_10
.getOrderForm()
_10
.then(function(orderForm) {
_10
var accountId = orderForm.paymentData.availableAccounts[0].accountId
_10
return vtexjs.checkout.removeAccountId(accountId)
_10
})
_10
.then(function() {
_10
alert("Removed.")
_10
})

addDiscountCoupon(couponCode, expectedOrderFormSections)

Adds a discount coupon to the orderForm.

Only one discount coupon can be applied per purchase.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
couponCodeString

Example


_12
vtexjs.checkout
_12
.getOrderForm()
_12
.then(function(orderForm) {
_12
var code = "ABC123"
_12
return vtexjs.checkout.addDiscountCoupon(code)
_12
})
_12
.then(function(orderForm) {
_12
alert("Coupon added.")
_12
console.log(orderForm)
_12
console.log(orderForm.paymentData)
_12
console.log(orderForm.totalizers)
_12
})

removeDiscountCoupon(expectedOrderFormSections)

Removes the orderForm discount coupon.

Only one discount coupon can be applied per purchase. Therefore, there is no need to specify anything here.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Example


_11
vtexjs.checkout
_11
.getOrderForm()
_11
.then(function(orderForm) {
_11
return vtexjs.checkout.removeDiscountCoupon()
_11
})
_11
.then(function(orderForm) {
_11
alert("Coupon removed.")
_11
console.log(orderForm)
_11
console.log(orderForm.paymentData)
_11
console.log(orderForm.totalizers)
_11
})

removeGiftRegistry(expectedOrderFormSections)

Removes the gift registry from the orderForm.

This unlinks the gift list to which the orderForm is associated, if any. If it is not linked, it does not do anything.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Example


_10
vtexjs.checkout
_10
.getOrderForm()
_10
.then(function(orderForm) {
_10
return vtexjs.checkout.removeGiftRegistry()
_10
})
_10
.then(function(orderForm) {
_10
alert("Gift list removed.")
_10
console.log(orderForm)
_10
})

addOffering(offeringId, itemIndex, expectedOrderFormSections)

Adds an offer to the orderForm.

Each orderForm item may have a list of offerings. These offers are linked to the item, like extended warranty or installation service.

When an offer is added, it will appear in the item's bundleItems field.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
offeringIdString or number. This may be found in the id property of the offer.
itemIndexNumber. The index of the item to which the offer is applied.

Example


_34
// Considering the following (summarized) structure of items:
_34
var items = [
_34
{
_34
id: "2004075",
_34
productId: "4741",
_34
name: "Dog food",
_34
skuName: "3 kg Dog Food",
_34
quantity: 3,
_34
seller: "1",
_34
bundleItems: [],
_34
offerings: [
_34
{
_34
id: "1033",
_34
name: "The Magnificent Offer",
_34
price: 100,
_34
type: "idk",
_34
},
_34
],
_34
availability: "available",
_34
},
_34
]
_34
_34
var offeringId = items[0].offerings[0].id
_34
var itemIndex = 0
_34
_34
vtexjs.checkout
_34
.getOrderForm()
_34
.then(function() {
_34
return vtexjs.checkout.addOffering(offeringId, itemIndex)
_34
})
_34
.done(function(orderForm) {
_34
// Offer added!
_34
console.log(orderForm)
_34
})

removeOffering(offeringId, itemIndex, expectedOrderFormSections)

Removes an offer.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
offeringIdString or number. This may be found in the offer's id property.
itemIndexNumber. The index of the item to which the offer is applied.

Example


_41
// Considering the following (summarized) structure of items:
_41
var items = [
_41
{
_41
id: "2004075",
_41
productId: "4741",
_41
name: "Dog Food",
_41
skuName: "3 kg Dog Food",
_41
quantity: 3,
_41
seller: "1",
_41
bundleItems: [
_41
{
_41
id: "1033",
_41
name: "The Magnificent Offer",
_41
price: 100,
_41
type: "idk",
_41
},
_41
],
_41
offerings: [
_41
{
_41
id: "1033",
_41
name: "The Magnificent Offer",
_41
price: 100,
_41
type: "idk",
_41
},
_41
],
_41
availability: "available",
_41
},
_41
]
_41
_41
var offeringId = items[0].bundleItems[0].id
_41
var itemIndex = 0
_41
_41
vtexjs.checkout
_41
.getOrderForm()
_41
.then(function() {
_41
return vtexjs.checkout.removeOffering(offeringId, itemIndex)
_41
})
_41
.done(function(orderForm) {
_41
// Offer removed!
_41
console.log(orderForm)
_41
})

addItemAttachment(itemIndex, attachmentName, content, expectedOrderFormSections, splitItem)

This method adds an attachment to an item in the cart. This allows you to add extra information to the item.

You can link an attachment to the SKU through the admin interface. To see which attachments can be inserted, check the item's attachmentOfferings property.

For example, when adding a sports team shirt to the cart, you can add the 'customization' attachment to allow the customer to choose the number that will be printed on the shirt.

If the attachment has more than one property in its object, you must send the complete object even if you only changed one field.

Example

The item has an attachmentOffering as follows:


_14
"attachmentOfferings": [{
_14
"name": "Customization",
_14
"required": true,
_14
"schema": {
_14
"Name": {
_14
"maximumNumberOfCharacters": 20,
_14
"domain": []
_14
},
_14
"Number": {
_14
"maximumNumberOfCharacters": 20,
_14
"domain": []
_14
}
_14
}
_14
}],

The content object must always send all its properties:


_13
var itemIndex = 0
_13
var attachmentName = Customization
_13
_13
// User entered the value for the Name field. The object must also pass the Number field.
_13
var content = { Name: Robert, Number: "" }
_13
_13
vtexjs.checkout.addItemAttachment(
_13
itemIndex,
_13
attachmentName,
_13
content,
_13
null,
_13
false
_13
)

Do not forget to call getOrderForm at least once before.

Returns

Promise for the orderForm.

Arguments

NameType
itemIndexNumber. The index of the item that will be included in the attachment.
attachmentNameString that can be found in the name property of attachmentOfferings in the item object.
contentObject. An object that follows the schema described in the schema property of attachmentOfferings.
splitItemBoolean default: true. Indicates that a separate item should be created if the items to be updated have attachments.

Example


_16
// Called sometime before
_16
// vtexjs.checkout.getOrderForm()
_16
_16
var itemIndex = 0
_16
var attachmentName = "Customization"
_16
var content = {
_16
Name: Robert,
_16
Numero: "10",
_16
}
_16
_16
vtexjs.checkout
_16
.addItemAttachment(itemIndex, attachmentName, content)
_16
.done(function(orderForm) {
_16
// Attachment added to the item!
_16
console.log(orderForm)
_16
})

Possible errors

404: The item does not have this linked attachment or the content object has an invalid property. 400: The content object was not passed correctly.

If the call fails, check the error object returned: (error.message). This will give you clues about what is wrong in the call.

removeItemAttachment(itemIndex, attachmentName, content, expectedOrderFormSections)

Removes an item attachment from the cart.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
itemIndexNumber. The index of the item that will be included in the attachment.
attachmentNameString that can be found in the name property of attachmentOfferings in the item object.
contentObject. An object that follows the schema described in the schema property of attachmentOfferings.

addBundleItemAttachment(itemIndex, bundleItemId, attachmentName, content, expectedOrderFormSections)

This method adds an attachment to the service (bundleItem) of an item in the cart.

You can link an attachment to the service through the admin interface. To see which attachments can be inserted, check the attachmentOfferings property of the service.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
itemIndexNumber. The index of the item to which the service is applied.
bundleIdString or number. This may be found in the id property of the bundleItem.
attachmentNameString that can be found in the name property of attachmentOfferings in the service object.
contentObject. An object that follows the schema described in the schema property of attachmentOfferings.

Example


_21
var itemIndex = 0
_21
var bundleItemId = 5
_21
var attachmentName = "message"
_21
var content = {
_21
text: "Congratulations!",
_21
}
_21
_21
vtexjs.checkout
_21
.getOrderForm()
_21
.then(function() {
_21
return vtexjs.checkout.addBundleItemAttachment(
_21
itemIndex,
_21
bundleItemId,
_21
attachmentName,
_21
content
_21
)
_21
})
_21
.done(function(orderForm) {
_21
// Attachment added to the item!
_21
console.log(orderForm)
_21
})

removeBundleItemAttachment(itemIndex, bundleItemId, attachmentName, content, expectedOrderFormSections)

Removes an attachment from a service.

Do not forget to use getOrderForm first.

Returns

Promise for the orderForm.

Arguments

NameType
itemIndexNumber. The index of the item to which the service is applied.
bundleIdString ou Number May be found in the id property of the bundleItem
attachmentNameString that can be found in the name property of attachmentOfferings in the service object.
contentAn object that follows the schema described in the schema property of attachmentOfferings.

sendLocale(locale)

Changes the user locale.

This causes a change in the orderForm, in clientPreferencesData.

Do not forget to use getOrderForm first.

Returns

Promise of success (no orderForm section is requested).

Arguments

NameType
localeString examples: "pt-BR", "en-US".

Example


_10
vtexjs.checkout
_10
.getOrderForm()
_10
.then(function(orderForm) {
_10
return vtexjs.checkout.sendLocale("en-US")
_10
})
_10
.then(function() {
_10
alert("Now you're an American ;)")
_10
})

clearMessages(expectedOrderFormSections)

Occasionally, the orderForm has its messages section populated with informational or error messages.

To clear the messages, use this method.

Do not forget to use getOrderForm first.

Returns

Promise of success (no orderForm section is requested).

Example


_10
vtexjs.checkout
_10
.getOrderForm()
_10
.then(function(orderForm) {
_10
return vtexjs.checkout.clearMessages()
_10
})
_10
.then(function() {
_10
alert("Messages cleaned.")
_10
})

getLogoutURL()

This method returns a URL that logs the user out, but keeps their cart.

You are responsible for making this redirection.

Do not forget to use getOrderForm first.

Returns

String

Example


_10
$(".logout").on("click", function() {
_10
vtexjs.checkout.getOrderForm().then(function(orderForm) {
_10
var logoutURL = vtexjs.checkout.getLogoutURL()
_10
window.location = logoutURL
_10
})
_10
})

getOrders(orderGroupId)

Gets the orders (order) contained in an order group (orderGroup).

If an order has been finalized and fulfilled by multiple sellers, it will be split into several orders — one for each seller.

The orderGroupId looks like v50123456abc, while group orders have identifiers such as v50123456abc-01, v50123456abc-02.

In most cases, an orderGroup will only contain one order.

In terms of data, an orderGroup is an array of order objects. An order has several properties related to the completion of the purchase. Full documentation of this object will be available soon.

Returns

Promise for the orders.

Arguments

NameType
orderGroupIdString

Example


_10
var orderGroupId = "v50123456abc"
_10
vtexjs.checkout.getOrders(orderGroupId).then(function(orders) {
_10
console.log("Number of orders in this group: ", orders.length)
_10
console.log(orders)
_10
})

changeItemsOrdination(criteria, ascending, expectedOrderFormSections)

Changes the sort order of the items based on the criteria (criteria) and an ascending parameter (ascending).

This causes a change in the itemsOrdination object of the OrderForm and also in the sort order of the objects in the items array.

Returns

Promise for the orderForm.

Arguments

NameType
criteriaString name or add_time
ascendingBoolean. True for increasing and false for decreasing.

Example


_10
var criteria = "add_time"
_10
var asceding = "false"
_10
vtexjs.checkout
_10
.changeItemsOrdination(criteria, ascending)
_10
.then(function(orderForm) {
_10
console.log("Sorting criteria: ", orderForm.itemsOrdination)
_10
console.log("Array of items sorted by criteria: ", orderForm.items)
_10
})

replaceSKU(items, expectedOrderFormSections, splitItem)

Removes a SKU from a current item and replaces it with a new one.

Returns

Promise for the orderForm.

Arguments

NameType
itemsArray object with the SKU to be removed in quantity 0 and the new SKU to be added. Must be wrapped in an array.
splitItemBoolean default: true. Indicates a separate item should be created if the items to be updated have attachments/services.

Example


_16
var items = [
_16
{
_16
seller: "1",
_16
quantity: 0,
_16
index: 0,
_16
},
_16
{
_16
seller: "1",
_16
quantity: 1,
_16
id: "2",
_16
},
_16
]
_16
_16
vtexjs.checkout.replaceSKU(items).then(function(orderForm) {
_16
console.log("New items: ", orderForm.items)
_16
})

finishTransaction(orderGroupId, expectedOrderFormSections)

Tells the Checkout API to finish a transaction and go to the final URL (e.g. order-placed, checkout).

Returns

Promise for the orderForm.

Arguments

NameType
orderGroupIdNumber. ID of the order to be created after finishing the checkout process.****

Example


_10
var orderGroupId = "959290226406"
_10
_10
vtexjs.checkout.finishTransaction(orderGroupId).then(function(response) {
_10
console.log("Success", response.status)
_10
})

Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
On this page