Straight to checkout

Shopify Partner
16 0 0
My demo app right now offers a single product - and I was curious if there's a method to have the person add the product to the shopping cart and go directly to checkout. I'd also settle for at least having a link to add the item to the customer's cart. I've tried: <%= link_to> However, this just takes the customer to the shopping cart. I'm beginning to think that I need to do a form post to get this to work: <form method="post" action="http://myshop.myshopify.com/cart/add" id="add-to-cart"> <label for="6945872" style="display:inline">Book</label> <input name="id[]" id="6945872" value="6945872" type="hidden" /> <input name="return_to" value="back" type="hidden" /> <input name="add" src="http://static1.shopify.com/s/files/1/0019/3982/assets/purchase.png?1235620900" id="purchase" value="Purchase" type="image" style="display:block;margin-top:10px;" /> </form> However it keeps mentioning that the variant does not exist - however that is the ID of the product. Is there a way to make sure that I'm searching for a product id and not a variant id? Also - I grabbed this from http://11heavens.com/testing-something-for-Tom so Caroline if you mind me using this let me know real quickly and I'll remove it. Otherwise, it's helping me understand what I need to do in order to get this working the way I want to.
0 Likes
Shopify Staff
Shopify Staff
2045 0 40

One important thing is that you actually need to add the variant.id and not the product id. Once done you can use the &move_to= parameter and tell it to move to /checkout. So try:

<%= link_to "Buy This", "http://#{current_shop.url}/cart/add/#{@products.variants.first.id}?move_to=/checkout" %>
Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Partner
16 0 0

Excellent, I’m still not getting this to work the way I want, but was able to use that to figure out the product variant ID.

However, now I’m getting desperate and am curious if this would work through a simple <form>. Since you do not require logins or even have them for that matter for customers wanting to check out – could something like:


<form action="http://myshop.myshopify.com/cart/add/" method="post" id="add-to-cart">
    <input type="hidden" name="id[]" id="19684512" />
    <input type="image" style="display:block;margin-top:10px;" src="http://static1.shopify.com/s/files/1/0019/3982/assets/purchase.png?1235620900" name="add" value="Purchase" id="purchase" />
</form>

Technically work? All I want is the person to click a button on our site and get taken to the checkout on our shop, would cURL be necessary for that?

0 Likes
Shopify Partner
16 0 0

Well, isn’t that embarrassing. All I had to do was read my code one more time over and i’d notice that:

<input type="hidden" name="id[]" id="19684512" />

Should read:

<input type="hidden" name="id[]" VALUE="19684512" />

Anyway, thanks so much tobi for the help. Shopify has gotten me engrossed in Ruby on Rails (although html/php will have to do for now).

EDIT: Just because I’m on that mild high that is a working chunk of code after a few unsuccessful whacks at it, I’m curious as to how I can go straight to checkout via the <form>.


<input type="hidden" name="move_to" value="/checkout" />

The above don’t quite work the way I thought it would. Is it possible to achieve what I’m attempting to do?

EDIT AGAIN:

Well, I tried the above and it don’t work, however I found that:


<form action="http://myshop.myshopify.com/cart/" method="post" id="add-to-cart" target="_blank">
<input type="hidden" name="id[]" id="id[]" value="19684512" />
<input type="image" id="checkout" name="checkout" value="Checkout" src="http://cdn.shopify.com/s/files/1/0031/8202/assets/checkout.png?1244218012" />
</form>

Works to take me straight to checkout – however, it is only if I have an item in my cart.

Anyway to do both at once (add item AND checkout)? I think something like that could be done with javascript, but I’d rather make sure it was necessary before jumping into that.

Thanks in advance!

0 Likes
Shopify Staff
Shopify Staff
55 0 0

Try using return_to instead of move_to:

<input type="hidden" name="return_to" value="/checkout" />

That should work.

Jesse Storimer | Shopify Developer | jesse@jadedpixel.com | http://www.jstorimer.com
0 Likes
Shopify Partner
16 0 0

Thanks jesse, works like a charm!

0 Likes
New Member
2 0 0

@tobi,

I can’t seem to get a link (GET) to add items to my cart. Can you revisit your link_to above and verify that it should work (and #2, that you can provide /checkout to move_to).

Neither seem to work for me.

Thanks,
Dave

0 Likes
Shopify Partner
1 0 0

I have a question about this. I set up a page on my side where I am posting to the cart from the main domain like something.com while the actual shop is on shop.something.com everything works great and I am able to add things to cart, and then I am redirecting back to the page with


 <input type="hidden" name="return_to" value="back"/>

then if I go to checkout I can see the products I added, but not remove them on the checkout page. If I click return to store at the bottom I am returned to shop.something.com, but the cart is empty.

It seems that the items on the cart are based on the domain or something. Is there a way around this.

0 Likes
Shopify Staff
Shopify Staff
5826 0 275

It works here: http://11heavens.com/testing-something-for-Tom

Sequence is:

1. Add to Cart.
2. Click on Checkout link.
3. On checkout page, click on ‘return to store’.
4. Product(s) is(are) in cart.

Caroline from http://11heavens.com ∴ mllegeorgesand AT gmail DOT com
0 Likes