<p>As Brad said in his answer, what you get back is the lineItem details - enough to update e.g. your totals, shipping quote etc.</p>

<p>The URL of the product, and the product fields etc, are not available in the JSON.  But it's hard to see why they would need to be - you're sending this ajax call from somewhere you already have a reference to the product/variant in your twig templates - why would you need this info repeated in the return object?</p>

<p>If you really need that stuff at that point, you're probably better off ajax loading in a twig template to get at the full product stuff.  If you could clraify what you're actually trying to do I can probably help better/describe what we've done.</p>

CC BY-SA 4.0
2018-06-08T20:34:11.930Z
Jeremy, can you elaborate on how you would AJAX load a twig template? I'm kind of stuck myself trying to AJAX add to cart and get a product thumbnail in return.
John Johnson
CC BY-SA 4.0
2018-06-11T06:12:27.463Z
It's not hard really...just some JS to load a template, like this, where $cart is e.g. a reference to a div to hold the cart:
`
            $cart.load("/ajax-injects/cart", function() {
                $cart.fadeIn(400);
            });
        });
`
Then in that loaded template get the cart and loop through it like you normally would, getting the product (or variant) from the line item, and the image from the product (or variant)
`{% set cart = craft.commerce.cart %} etc

If that's not enough post another question and point me at it here or in Slack and I'll do a proper answer :)
Jeremy Daalder
CC BY-SA 4.0
2018-06-13T15:30:40.707Z
First, I should say I had trouble even loading a template with plain text in it simply because it was in a folder starting with an underscore (_partials/). That was my first mistake. Secondly, after adding the twig to the template, it no longer loads. Is twig able to render in a jquery loaded template?
John Johnson
CC BY-SA 4.0
2018-06-13T15:50:38.570Z
Ok, NVM. Had a typo in my twig code, which probably drew a template error that wasn't showing via jquery .load. I'll carry on in this direction and report back. Thank you, Jeremy!
John Johnson
CC BY-SA 4.0
2018-06-13T23:20:49.007Z
No worries.  Use the network thing in your broswer's dev tools and check the response - you'll see twig errors in there if you have them.  But you can do basically anything in an ajax loaded template you can in a normal one, it's jsut a bit fiddlier when you make a woopsie ;)
Jeremy Daalder
CC BY-SA 3.0
2017-03-17T00:22:28.937Z
2017-03-17T00:22:28.937Z
Jeremy Daalder
<p>A <a href="https://craftcommerce.com/docs/order-model" rel="nofollow noreferrer">Commerce_OrderModel</a> is returned in the response of a successful call to <code>Commerce_CartController-&gt;actionUpdateCart()</code>.</p>

<p>The product info you're looking for, you'd get through the <a href="https://craftcommerce.com/docs/order-model#lineitems" rel="nofollow noreferrer">lineItems</a> property, which would be an array of <a href="https://craftcommerce.com/docs/line-item-model" rel="nofollow noreferrer">Commerce_LineItemModel</a>s.</p>

CC BY-SA 3.0
2017-03-16T17:42:18.557Z
2017-03-16T17:42:18.557Z
Brad Bell
<p>I add items to my cart using ajax, following the code from this post</p>

<p><a href="https://craftcms.stackexchange.com/questions/17347/update-commerce-cart-using-ajax">Update Commerce Cart using Ajax</a></p>

<p>But there are some things missing in the cart object returned on success, they are :</p>

<ul>
<li>The URL of the page of the product added </li>
<li>The images, and all the fields from the product added</li>
<li>The name of the variant of the product added</li>
</ul>

<p>Are these somewhere in the object returned ? Otherwise, how could I retrieve them ?</p>

<plugin-craftcommerce><ajax>
Craft Commerce ajax add to cart, missing information
# Craft Commerce ajax add to cart, missing information

(Asked by: username_0 on 2017-03-16)

I add items to my cart using ajax, following the code from this post

[Update Commerce Cart using Ajax](https://craftcms.stackexchange.com/questions/17347/update-commerce-cart-using-ajax)

But there are some things missing in the cart object returned on success, they are :

* The URL of the page of the product added
* The images, and all the fields from the product added
* The name of the variant of the product added

Are these somewhere in the object returned ? Otherwise, how could I retrieve them ?

**Tags:** plugin-craftcommerce, ajax


---

## 2 answers

### Answer by username_1 on 2017-03-17. Score: 1

As Brad said in his answer, what you get back is the lineItem details - enough to update e.g. your totals, shipping quote etc.

The URL of the product, and the product fields etc, are not available in the JSON. But it's hard to see why they would need to be - you're sending this ajax call from somewhere you already have a reference to the product/variant in your twig templates - why would you need this info repeated in the return object?

If you really need that stuff at that point, you're probably better off ajax loading in a twig template to get at the full product stuff. If you could clraify what you're actually trying to do I can probably help better/describe what we've done.

> **Comments:**
> **username_2**: Jeremy, can you elaborate on how you would AJAX load a twig template? I'm kind of stuck myself trying to AJAX add to cart and get a product thumbnail in return.  
> **username_1**: It's not hard really...just some JS to load a template, like this, where $cart is e.g. a reference to a div to hold the cart: `             $cart.load("/ajax-injects/cart", function() {                 $cart.fadeIn(400);             });         }); ` Then in that loaded template get the cart and loop through it like you normally would, getting the product (or variant) from the line item, and the image from the product (or variant) `{% set cart = craft.commerce.cart %} etc  If that's not enough post another question and point me at it here or in Slack and I'll do a proper answer :)  
> **username_2**: First, I should say I had trouble even loading a template with plain text in it simply because it was in a folder starting with an underscore (_partials/). That was my first mistake. Secondly, after adding the twig to the template, it no longer loads. Is twig able to render in a jquery loaded template?  
> **username_2**: Ok, NVM. Had a typo in my twig code, which probably drew a template error that wasn't showing via jquery .load. I'll carry on in this direction and report back. Thank you, Jeremy!  
> **username_1**: No worries.  Use the network thing in your broswer's dev tools and check the response - you'll see twig errors in there if you have them.  But you can do basically anything in an ajax loaded template you can in a normal one, it's jsut a bit fiddlier when you make a woopsie ;)  

---

### Answer by username_3 on 2017-03-16. Score: 0

A [Commerce\_OrderModel](https://craftcommerce.com/docs/order-model) is returned in the response of a successful call to `Commerce_CartController->actionUpdateCart()`.

The product info you're looking for, you'd get through the [lineItems](https://craftcommerce.com/docs/order-model#lineitems) property, which would be an array of [Commerce\_LineItemModel](https://craftcommerce.com/docs/line-item-model)s.


---

