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

Woocommerce routing #37

Open
asiz15 opened this issue Jan 21, 2021 · 3 comments
Open

Woocommerce routing #37

asiz15 opened this issue Jan 21, 2021 · 3 comments

Comments

@asiz15
Copy link

asiz15 commented Jan 21, 2021

Hi!

Can anyone point me in the right direction on how can routing properly for woocommerce ?
Actually, I follow the steps from [#15], but still not working.

Any solutions? Thanks in advance.

@jnz31
Copy link

jnz31 commented Jan 21, 2021

the wc api is very limited for frontend, you aware of that? i am currently working on a wc shop, i use cocart for the heavy lifiting. works pretty well so far, still working on the most complex part, the checkout, but it looks like it gets the job done..

@asiz15
Copy link
Author

asiz15 commented Jan 21, 2021

the wc api is very limited for frontend, you aware of that? i am currently working on a wc shop, i use cocart for the heavy lifiting. works pretty well so far, still working on the most complex part, the checkout, but it looks like it gets the job done..

Thanks for your answer, but Im still a bit confused.

Are you using cocart with this theme?

I think I can handle the woocommerce api on my own following the same logic as the theme, using the store.

Could you route the theme correctly for woocommece?, can you provide me an example?

What matters to me for the moment, is to define the appropriate routes to be able to use my vue template in single-product, just like in Single.vue for posts

actually, im ussing this route from permalinks config
https://my-store/products/product-name

thanks!

@jnz31
Copy link

jnz31 commented Jan 22, 2021

yes, i use cocart with this theme. like mentioned earlier, wc is not really opening up on products, attributes, prices etc. and with cocart these infos all get exposed to the api. same goes for taxes, shipping, fees, coupons etc. still working on it for the first time, but getting along quite well..

so basically you have issues with getting cpt to work properly, correct?

you need to expose your endpoints inside the rest api data localizer (in the theme this one is found inside functions.php):

new RADL('__VUE_WORDPRESS__', 'vue_wordpress.js', array(
    'routing' => RADL::callback('vue_wordpress_routing'),
    'state' => array(
        ...
        'products' => RADL::endpoint('products'),
    ),
));`

and in your template files you need to fetch the data from these endpoints.
i pasted this one inside my single.php and for archive it pretty much the same.
single:

$post_type = get_post_type();
$post_type === 'post' ? 'posts' : $post_type;
$single = RADL::get('state.' . $post_type, get_the_ID());

archive:

$post_type = get_post_type();
$post_type === 'post' ? 'posts' : $post_type;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$per_page = RADL::get('state.site')['posts_per_page'];
$posts = RADL::get('state.' . $post_type, ['page' => $paged, 'per_page' => $per_page]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants