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.

Comments

dchampine created an issue. See original summary.

marcopbazz’s picture

+1 I have the same Issue

donutdan4114’s picture

StatusFileSize
new621.58 KB

I'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...

donutdan4114’s picture

Well 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?....

donutdan4114’s picture

Also, 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.

donutdan4114’s picture

Status: Active » Postponed (maintainer needs more info)
dchampine’s picture

StatusFileSize
new326.01 KB

The 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.

dchampine’s picture

Also, feel free to investigate at http://test.nodepression.com/products if that provides any additional info.

dchampine’s picture

sorry 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?

John Carbone’s picture

Co-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...

John Carbone’s picture

Yep. 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.

dchampine’s picture

Apologies 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.

John Carbone’s picture

Can you make /products public or provide login details so I can take a look?

dchampine’s picture

it is open to you now. sorry about that...

John Carbone’s picture

Took 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?

donutdan4114’s picture

Yea, 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.

  • donutdan4114 committed 19e4989 on 7.x-1.x
    Fixes #2557405: Add to cart form should post to the proper URL.
    
donutdan4114’s picture

Pushed 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...

$form['#action'] = 'https://' . variable_get('shopify_api_domain') . '/cart/add';

with this line of code:

$form['#action'] = 'https://' . shopify_store_info()->myshopify_domain . '/cart/add';
donutdan4114’s picture

Status: Postponed (maintainer needs more info) » Fixed
donutdan4114’s picture

Status: Fixed » Needs review
marcopbazz’s picture

I 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.....

dchampine’s picture

I 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.

  • donutdan4114 committed d6955c9 on 7.x-1.x
    Fixed #2557405: Add to cart form posts to URL without protocol and use...
donutdan4114’s picture

If 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.

marcopbazz’s picture

It 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)

donutdan4114’s picture

Status: Needs review » Fixed
dchampine’s picture

#24 did the trick. Confirmed fixed.
Thanks again, donutdan!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

marcopbazz’s picture

Sorry if I reopen :(

shopify.module:1640 :
$domain = shopify_store_info()->myshopify_domain;

Maybe it should be converted too:

$domain = shopify_store_info()->domain;

donutdan4114’s picture

Status: Closed (fixed) » Needs work
donutdan4114’s picture

Status: Needs work » Fixed

I have updated all usages of myshopify_domain to be just domain.

marcopbazz’s picture

Great :)

  • donutdan4114 committed 19e4989 on 8.x-1.x
    Fixes #2557405: Add to cart form should post to the proper URL.
    
  • donutdan4114 committed d6955c9 on 8.x-1.x
    Fixed #2557405: Add to cart form posts to URL without protocol and use...
  • donutdan4114 committed 50722fa on 8.x-1.x
    Issue #2557405: Replaced references to myshopify_domain with just '...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

phreik’s picture

Hello 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