I have successfully installed the Shopify API and eCommerce modules. Products and Collections are synchronized and webhooks are registered. Everything looks right and I get a success message after clicking the "Add to Cart" button on the /products view or product node page. However, clicking the cart link that is presented in the success message shows an empty shopping bag.
I have plenty of experience building and integrating Drupal modules and 3rd party APIs, but I'm new to Shopify so I'm not exactly sure how to troubleshoot.
Any insights would be appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | drupal_shopify_add.jpg | 326.01 KB | dchampine |
| #3 | Screenshot 2015-08-26 10.29.31.png | 621.58 KB | donutdan4114 |
Comments
Comment #2
marcopbazz commented+1 I have the same Issue
Comment #3
donutdan4114 commentedI'm not sure what the issue would be, but here is some additional information / helpful tips.
The "add to cart" form POSTs data directly to the Shopify store.
You can check in Chrome to make sure it's working properly.
Open the Network developer tab. Check the "Preserve Log" checkbox. Then try to add something to your cart.
You should see a POST form request to
https://myshopify.domain/cart/add.Example of what I see:

So I wonder if:
1. Does the POST request go through for you? Is there an error?
2. Some issue with the Shopify domain? Maybe it's not correct for some reason?
3. Did you change your store domain URL since creating your Shopify Store?..... I wonder if that needs to get updated...
Comment #4
donutdan4114 commentedWell the form action comes from shopify.module:1082.
$form['#action'] = 'https://' . variable_get('shopify_api_domain') . '/cart/add';Ensure the store domain is still correct at admin/config/services/shopify?....
Comment #5
donutdan4114 commentedAlso, inspect the actual "add to cart" form to ensure the form action is set to the right domain, and that it's set to POST.
Comment #6
donutdan4114 commentedComment #7
dchampine commentedThe api config shows the right domain (no-depression.myshopify.com)
I did initially set it to my alias domain of store.nodepression.com, but was unable to connect until I used the primary store domain.
What is interesting is that I tried using the "embedded buy button" and "html form" methods from Shopify docs with the same negative result.
The only method that seems to work is using a permalink "https://.myshopify.com/cart/:1"
I have included a screenshot of my network trace which is using POST. I notice that I'm not seeing the ?q=shopify/added-to-cart entry - only the add.
I hope this helps clarify things. FWIW, I'm not having any luck with Shopify support in explaining why the html form and embed link methods don't work.
Comment #8
dchampine commentedAlso, feel free to investigate at http://test.nodepression.com/products if that provides any additional info.
Comment #9
dchampine commentedsorry for the multiple posts:
I just printed the cart block to see if that gave any clues. If you visit http://test.nodepression.com/magazine you will see the 3 different attempts at remotely adding to cart and the output of the cart block (which shows 10 items in the cart!!!). However, when you click on the "Cart (10)" link, it takes you to my shopify store that says "No items in my shopping bag."
How is it that these two can be out of sync?
Comment #10
John Carbone commentedCo-maintainer here. I poked around your test site. I don't see the add to cart and quantity options that ship with the module being printed on the page. Looks like you're using 3 "add to cart" options that are copy/pasted from Shopify, but not the one that ships with the module and is automatically generated on product nodes. Perhaps that has something to do with it? Have you tried using the module's version? Looks like you're adding products to one cart id but when you visit the cart you're seeing the other card id's contents...
Comment #11
John Carbone commentedYep. The cart id is set using a cookie and you're seeing 1 cart id in one place and 1 in another. Basically the same behavior as if you'd added items to a cart in Chrome then visited the checkout page in Firefox and wondered why the items weren't showing.
Using the HTML embed options directly from shopify creates an alternate cart. If you visit the source of the cart block's count you see the items in the cart that you added. https://no-depression.myshopify.com/cart.json but when you click the link you see the alternate cart id.
Removing the other add to cart options (then clearing cookies) and just using the module's version should fix the problem. Also, you'll want to use the module's Shopify theme which redirects users back to Drupal rather than letting them get lost in a different store.
Comment #12
dchampine commentedApologies for distracting the thread with my other attempts on /magazine.
I have removed all those attempts and am only focused on http://test.nodepression.com/products (the default view that ships with this module).
I cleared my cookies and I'm only using the module's version and still having the same experience.
Not the domain and seems like not the cookies.
Changing the return_to destination in the module didn't have any impact - I'm kind of grasping at straws there.
Any other ideas?
Thanks for the tip on theme, I'm getting all the plumbing done first and then will apply.
Comment #13
John Carbone commentedCan you make /products public or provide login details so I can take a look?
Comment #14
dchampine commentedit is open to you now. sorry about that...
Comment #15
John Carbone commentedTook another look after you made your changes. I've been able to prove the two different cookie theory, just not sure why it's happening. Unfortunately using the module's version of the add to cart button did not affect anything. We'll keep looking into it, especially considering #2 above.
Are you sure you followed the module's installation instructions exactly? Did you deviate anywhere or change anything later? Are you running the current Alpha (8)? Just to rule something else out, would you mind switching to the module's version of the Shopify theme?
Comment #16
donutdan4114 commentedYea, so the issue is that the form is POSTing to https://no-depression.myshopify.com/cart/add but the domain is setup as http://store.nodepression.com/cart.
So this is obviously an issue with the domain alias for Shopify.
Comment #18
donutdan4114 commentedPushed up a potential fix.
You can either update to the next dev release or make one code change in shopify.module:1082 file.
Replace this line of code inside of
shopify_add_to_cart_form...with this line of code:
Comment #19
donutdan4114 commentedComment #20
donutdan4114 commentedComment #21
marcopbazz commentedI confirm alias is the problem: my domain is venipedia.myshopify.com but I set http://mercante.venipedia.it as alias.
The patch doesn't work, but if I declare the alias in function (like $form['#action'] = 'http://http://mercante.venipedia.it/cart/add';) it works.....
Comment #22
dchampine commentedI can also confirm that the alias was causing the problem.
When I tried to upgrade to latest dev with drush, I got:
File shopify-7.x-1.x-dev.tar.gz?date=1440598739 is corrupt (wrong md5 checksum). [error]
Updating project shopify failed. Attempting to roll back to previously installed version.
Changing the line of code manually per #18 didn't seem to work, but hardcoding the domain to store.nodepression.com in line 1080 does the trick.
Thanks for the quick and helpful support on this. The module seems very solid. I am happy to give back to this project as I intend to use it heavily in our new site.
Comment #24
donutdan4114 commentedIf you want to try this solution, I'm hoping this fixes the issue now:
Remove this line:
$form['#action'] = 'https://' . shopify_store_info()->myshopify_domain . '/cart/add';And put in this line:
$form['#action'] = '//' . shopify_store_info()->domain . '/cart/add';There was an issue with adding to a cart on HTTPS vs. HTTP page. Hoping this takes care of that issue.
Comment #25
marcopbazz commentedIt works, you're great! :)
Just one thing I noticed: the cart block shows right in firefox (latest version) but in chrome print only "cart()" (i'm on OS X Yosemite)
Comment #26
donutdan4114 commentedComment #27
dchampine commented#24 did the trick. Confirmed fixed.
Thanks again, donutdan!
Comment #29
marcopbazz commentedSorry if I reopen :(
shopify.module:1640 :
$domain = shopify_store_info()->myshopify_domain;Maybe it should be converted too:
$domain = shopify_store_info()->domain;Comment #30
donutdan4114 commentedComment #31
donutdan4114 commentedI have updated all usages of
myshopify_domainto be justdomain.Comment #32
marcopbazz commentedGreat :)
Comment #35
phreik commentedHello guys my problem is the cart will update any quantity of items and will show and cart but when a customer for example add 5 items and go back to check other products and add lets say... 2 more that will make 7 items and when you go to the cart gain you still have just 5 so cart is not updating quantities
Shopify eCommerce 8.x-1.0-alpha4 --->>> 8.x-1.0-alpha6
Drupal core 8.6.2