Answers.Body: <p>Assuming your lineItem variable is called <code>item</code>, you're looking for</p>
  
  <p><code>item.purchasable.stock</code></p>
  
  <p>You might also need to pay attention to <code>maxQty</code> which is the maximum number of a purchasable item that a user is allowed to buy. I limit customers to a maximum of 10 and create a select box on the basket form with a Remove option at the bottom:</p>
  
  <pre><code>{% set maxQuantity = item.purchasable.stock &gt; 10 ? 10 : item.purchasable.stock %}
  {% if item.purchasable.maxQty %}
      {% set maxQuantity = maxQuantity &gt; item.purchasable.maxQty ? item.purchasable.maxQty : maxQuantity %}
  {% endif %}
  
  &lt;select name="qty"&gt;
      {% for i in 1..maxQuantity %}
          &lt;option value="{{ i }}" {{ i == item.qty ? 'selected' }}&gt;{{ i }}&lt;/option&gt;
      {% endfor %}
      &lt;option value="0"&gt;Remove&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-02T22:37:59.787Z
Answers.LastActivityDate: 2018-01-02T22:37:59.787Z
Answers.UserDisplayName: Ant Cooper
Body: <p>I'm trying to set a max amount on the quantity in the cart. My problem is I want a customer to be able to update their quantity while in the cart, but I can't seem to figure out how to set the max quantity according to the stock on hand. I've done this with variant.stock in the items page, but can't seem to find anything that allows me to pull that information according to the lineItem in the cart page.</p>
  
Tags: <plugin-craftcommerce>
Title: Pull in stock from Craft Commerce cart
ThreadText: # Pull in stock from Craft Commerce cart
  
  (Asked by: username_0 on 2017-12-27)
  
  I'm trying to set a max amount on the quantity in the cart. My problem is I want a customer to be able to update their quantity while in the cart, but I can't seem to figure out how to set the max quantity according to the stock on hand. I've done this with variant.stock in the items page, but can't seem to find anything that allows me to pull that information according to the lineItem in the cart page.
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-02. Score: 2 | Accepted answer
  
  Assuming your lineItem variable is called `item`, you're looking for
  
  `item.purchasable.stock`
  
  You might also need to pay attention to `maxQty` which is the maximum number of a purchasable item that a user is allowed to buy. I limit customers to a maximum of 10 and create a select box on the basket form with a Remove option at the bottom:
  
  ```
  {% set maxQuantity = item.purchasable.stock > 10 ? 10 : item.purchasable.stock %}
  {% if item.purchasable.maxQty %}
      {% set maxQuantity = maxQuantity > item.purchasable.maxQty ? item.purchasable.maxQty : maxQuantity %}
  {% endif %}
  
  <select name="qty">
      {% for i in 1..maxQuantity %}
          <option value="{{ i }}" {{ i == item.qty ? 'selected' }}>{{ i }}</option>
      {% endfor %}
      <option value="0">Remove</option>
  </select>
  
  ```
  
  
  ---
  
  