I'm testing this on localhost:8045. It seems like I got a 200 ok status.
This is the response I'm getting:
I'm testing this on localhost:8045. It seems like I got a 200 ok status.
This is the response I'm getting:
I changed the post request to the url of my shop instead of locahost. It doesn't make sense why I can submit a post request through a REST client like POSTMAN on chrome, but not be able to do this. So there is no way I can add an item to cart from localhost?
You can take a look into using permalinks or the shopify-widget app perhaps. I believe it's not possible because we don't support JSONP or CORS on the storefront.
So there is no way to asynchronously add to shopify's cart from a remote website even if I have the variant ID/quantity?
Currently no. We don't have CORS (or JSONP) support for the storefront yet I believe.
It's weird that we can add to shopify's cart from a remote website, but we can't do this asynchronously.
Submitting the HTML form with a page refresh works, but submitting it through AJAX doesn't seem to do it. Oh well...
Thank you, Nate - that's exactly what I needed!
I'll chime in and agree with Carted, better documentation would be helpful in this aspect. An accompanying infographic could be a simple, but effective, addition as well.
Hey Chris,
I'm hoping we can find a solution for this as well, it's a small requirement but I think it's potential for Shopify users and App creators alike is enormous. I myself was hoping to use the feature to really take the mobile app for my store to the next level.
Ben
Hi,
I have a product with price 100
https://mydevshop-6.myshopify.com/admin/products/281868381.json?fields=id,variants
{"product":{"id":281868381,"variants":[{"id":665050373,"price":"100.00"
But the search api give me another price 10000
https://mydevshop-6.myshopify.com/search?q=*&type=product&view=json
{ "results_count":2, "results":[ { "id":281868381, "variants":[{"id":665050373,"price":10000,
Search API return wrong price
It's not wrong. You're also confusing the api with the storefront search. They are not the same.
The search results you are seeing will be based on the code within that json template. You can just use the money filters within that file to change the value to whatever you need.
I have a product page with an "Add To Cart" button. Example: http://shop.tapiture.com/collections/beach-days/products/old-glories-swim-trunks
Is it possible to either intercept the "Add To Cart" event and get the variant ID/ quantity number of the item OR pass a call back receiving the JSON data of the cart? Thanks!
I tried
Shopify.onItemAdded = function(line_item) { console.log('line item added'); }; Shopify.onCartUpdate = function(cart) { alert('There are now ' + cart.item_count + ' items in the cart.'); };
But neither of them seem to work. I'm not calling the Shopify.addItem(...) function so that might be the case, but I need to listen for that event in the product page.
So just editing the cart template won't do? You've got me curious in any case.
Ok let me break down what I'm experimenting with. I'm trying to modify Shopify's cart from a remote siteasynchronously. This can't be done. What can be done however, is saving the updated cart data from the remote site into a cookie. Basically the cookie will have information about items users have added from our remote site.
When users go back to their cart, I want to pull the updated cart data and push these items to the cart. I know this can be done inside Shopify with Shopify's AJAX API, but I want to make sure these new items get added to the cart before the cart page gets rendered.
This is a pretty hackish approach to go about things, but it's the only way. Hope that makes sense!
Possible on both counts.
You could also add the id and quantity into the page itself to save you looking it up, though if the customer has sat on the page for while the quantity values may be different.
How would I achieve this? I tried the two Shopify callback handlers (mentioned above), don't seem to work. Not sure exactly where the code is that calls "Shopify.addItem..." when the user clicks "Add To Cart".
I know I can get the quantity from the product page easily, but I guess my problem is figuring out what variant ID is being selected by the user after he has selected option 1-2-3.
Your using the option selector script so you could tap in that to pull the variant id whenever the options change. The variant object should have all sorts of things like stock, id, etc.
You want to look for the function that starts with this:
var selectCallback = function(variant, selector) {
There's other ways, but this might be the easiest since you've got those scripts in place already.
As a sidenote - your theme is using this to add to cart (from your radiance.js)
function addToCart(e){ if (typeof e !== 'undefined') e.preventDefault(); var cartAmountContainer = $('.cart-amount'); if (cartAmountContainer.length == 0) { $('.cart').append('<span class="cart-amount"/>'); cartAmountContainer = $('.cart-amount'); } var currentCount = (cartAmountContainer.text() * 1) || 0; cartAmountContainer.text(currentCount + 1); var form = $(this).parents('form'); $.ajax({ type: 'POST', url: '/cart/add.js', async: false, data: form.serialize(), dataType: 'json', error: addToCartFail, success: addToCartSuccess, cache: false }); }
I'm trying to figure out how to add a file in the snippet directory over the API. Is that possible? Can't find anything about it in the docs for Theme (http://docs.shopify.com/api/theme).
What I'm trying to accomplish is a way to give the shop owner an easy way to display a small box where he/she sees appropriate with content that my app delivers. My thought was to have a div tag and some javascript in a snippet, which would be easy to place and then build up the content of the box (div tag) with jquery. Much like Linkcious does on my product page.
What you are looking for is covered in the Asset reference
PUT https://shop/admin/themes.json { "asset": {"key": "snippets/yoursnippet.liquid","value": "liquid snake" } }
Attempting to post to orders to our dev Shopify store always yields 406 errors for an inexplicable reason. I am able get orders and post/put/get/delete items, but every time I post an order (working from the C# library) it returns a 406. In the response, the content type is application/xml, which matches the accept header, so there doesn't seem to be any straightforward reason for this to occur, especially given that so many other api calls work smoothly in the exact same environment.
You aren't creating a valid order. Line Items is an array of entries not a single item. Also you need to send the variant_id not the product_id
From what I see this is the XML you are submitting:
<order><line_item><product_id>1234</product_id><quantity>1</product_id></line_item></order>
Instead you should be sending something close to the following:
<order><line_items><line_item><variant_id>1234</variant_id><quantity>1</product_id></line_item></line_items></order>
Can you can configure your library to use JSON instead of XML? The XML API is basically unsupported at this point.