Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WooCommerce post types in wordpress source plugin #5794

Closed
Amanej opened this issue Jun 8, 2018 · 15 comments
Closed

Support WooCommerce post types in wordpress source plugin #5794

Amanej opened this issue Jun 8, 2018 · 15 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@Amanej
Copy link

Amanej commented Jun 8, 2018

Currently the wordpress source plugin only fetches the woocommerce post titles, excerpts and other generic wordpress content.

It would be good if it supports the product data, such as prices, variations etc.

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Jun 8, 2018
@Amanej
Copy link
Author

Amanej commented Jun 13, 2018

I would like to do this myself, but the wordpress source plugin was difficult to understand.

@keithgnx
Copy link

keithgnx commented Jun 16, 2018

You should already be able to query WooCommerce data. WooCommerce has its own routes, /wc/v1 and /wc/v2. If you're receiving 401 Unauthorized, it's because you need to create keys in WooCommerce > Settings > Advanced > REST API. Add these to the auth field in the wordpress section of your gatsby-config.

I've also learned that if you want the plugin to optimize product images, you will need to make sure the /wp/v2/media route is fetched and either make sure every product has an image or change the placeholder image so that the default image is not null.

I should also add that I don't believe WooCommerce is "officially" supported and you may still run into issues. For example, node links are not created for product tags and categories as they are for regular Wordpress posts as WooCommerce tags and categories have different wordpress types and are not accounted for in the plugin.

#5796 discusses extending gatsby-source-wordpress.

@Amanej
Copy link
Author

Amanej commented Jun 18, 2018

I am receiving alot 401s, 403 etc actually.
They are all public, and if I wrote a request from scratch I would be able to fetch all the products with their prices etc.

How should I attach the wc auth field ?
Tried the following

auth: {
 user: 'username',
 pass: 'password'
}
auth: {
 user: 'username',
 pass: 'password',
 consumerKey: 'consumerKey',
 secret: 'secret'
}
auth: {
 user: 'username',
 pass: 'password'
}

Or is there a special naming convention for WC ?

The actual products are showing up as posts in graphql inspector but only the most basic post data such as title, excerpt etc.
But not all the other fields, such as variations, prices etc.
I am not sure, how you would query the other fields with the wordpress-source-plugins.

@mr-tcan
Copy link

mr-tcan commented Jun 28, 2018

Why not use WooCommerce REST API to create a gatsby-source-woocommerce?

@Amanej
Copy link
Author

Amanej commented Jul 4, 2018

image

This is not working, but this works in the browser:
http://mywoocommercesite.com/wp-json/wc/v1/products?consumer_key=key&consumer_secret=secret&category=17

@keithgonzalez

@Amanej
Copy link
Author

Amanej commented Jul 4, 2018

@keithgnx
Copy link

keithgnx commented Jul 4, 2018

@Amanej what do you mean by not working? Are you getting any errors?

@Amanej
Copy link
Author

Amanej commented Jul 5, 2018

Yes, 401 Unauthorized.

@keithgnx
Copy link

keithgnx commented Jul 6, 2018

Try setting up a fresh WordPress installation on a local development environment as well as a fresh Gatsby repo with the gatsby-source-wordpress plugin. It would be helpful to figure out if this is a Gatsby issue or a Wordpress server configuration issue. The latter seems more likely.

I can only help so much with the limited details provided. Try going over https://docs.woocommerce.com/document/woocommerce-rest-api/ and https://github.com/woocommerce/woocommerce/wiki/Getting-started-with-the-REST-API. There's a 401 Unauthorized troubleshooting section in there as well.

@Amanej
Copy link
Author

Amanej commented Jul 6, 2018

Well, the url works in the browser, as an ajax call, with curl and with nodejs rest api. So its definitely not a wp server config issue.

How exactly does the source plugin use the auth parameters ? That is what is really missing here. If you are able to just provide one example of how it could work, of how the auth parameters would look with WooCommerce keys, not WordPress login (which would not sufficient) that would be helpful.

If you're receiving 401 Unauthorized, it's because you need to create keys in WooCommerce > Settings > Advanced > REST API. Add these to the auth field in the wordpress section of your gatsby-config.

I have just started my own source plugin anyway: wc source plugin. But unfortunately for the current project, its way out-of-scope already.

@wilsonmar
Copy link

The link in the above comment does not resolve for me: https://github.com/gatsbyjs/gatsby/issues/wc-source-plugin
@Amanej we are exploring the same, so let's join forces. Please contact me.

@Amanej
Copy link
Author

Amanej commented Aug 14, 2018

@wilsonmar I updated the link now!

@marcaaron
Copy link

@Amanej @wilsonmar late to the party, but I created a source plugin for woocommerce today. rather than node-fetch it uses the woocommerce node package. Not sure if it will be useful to you all. But it allows you to pull in a few different data fields from the WooCommerce REST API. Still need to test it out some more.

https://github.com/marcaaron/gatsby-source-woocommerce

@gatsbot
Copy link

gatsbot bot commented Dec 28, 2018

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Dec 28, 2018
@gatsbot
Copy link

gatsbot bot commented Jan 8, 2019

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

@gatsbot gatsbot bot closed this as completed Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

6 participants