> For the complete documentation index, see [llms.txt](https://docs.nosto.com/magento-2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nosto.com/magento-2/features/add-to-cart.md).

# Add to Cart

Nosto supports a quick-buy function straight from within its recommendations. This feature will be referred to as the add-to-cart feature henceforth. As of version 2.0.0, it's possible to add variations (configurable products) directly to cart from recommendations.

![2.0.0-RC1](https://img.shields.io/badge/nosto-2.0.0-green.svg)

**Note:** The function definition is a part of the extension and is automatically added to all pages. You do not need to define the function or include any additional scripts.

In order to do this, you must pass the product id of the actual variation `Nosto.addSkuToCart` method.

The first argument is the id of variation, and the second one being the element where the product was added to the cart. If configurable product's id is 123 and the id of the variation is 124 the method call in recommendations template would look like this

```javascript
Nosto.addProductToCart('124', this);
```

### Leveraging Quantities

![2.11.0](https://img.shields.io/badge/nosto-2.11.0-green.svg)

As of version `2.11.0` you can also pass the quantity as a parameter.

```javascript
Nosto.addProductToCart('124', this, 2);
```

### Adding Multiple Products

![2.12.0](https://img.shields.io/badge/nosto-2.12.0-red.svg)

It is also possible to add multiple products to the cart by using an array of objects containing the `productId` and the `skuId`.

The product id is the parent product that holds the variations, and the SKU is the variation itself.

The parent id is needed in order to recognize which product was added and improve the recommendations.

**Note** that if you use a configurable product as SKU ID, will simply not be added to the cart, since you need to select the options.

```javascript
Nosto.addMultipleProductsToCart([
        {'productId' : '123', 'skuId' : '123'},
        {'productId' : '124', 'skuId' : '124'},
        {'productId' : '111', 'skuId' : '222'}
    ], this);
```

## Use Cases

A common way to implement the functionality of adding variation directly to cart is to implement drop down of available variations for recommended products. The selected variation id is then picked up from the drop down and passed to the `Nosto.addSkuToCart` method. An example implementation can be found below.

```markup
#if($product.skus.size() > 0)
  <div class="nosto-sku-select-wrapper">
    <label class="nosto-sku-select">
      <select onChange="document.getElementById('selected_sku').value = this.value">
        <option value="">Choose</option>
          #foreach($sku in $product.skus)
            <option value="$!sku.id">
              #foreach($attr in $sku.customFields)
                $!attr.key: $!attr.value
              #end
            </option>
          #end
      </select>
    </label>
  </div>
  <button onclick="Nosto.addProductToCart(document.getElementById('selected_sku').value, this);return false;" class="nosto-btn">
    <img src="$!props.display.buyButtonIcon.url" width="15" height="15">
  </button>
#end
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.nosto.com/magento-2/features/add-to-cart.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
