XiaoFaye / WooCommerce.NET

A .NET Wrapper for WooCommerce/WordPress REST API
MIT License
392 stars 218 forks source link

Implementation on a Windows Service. #109

Closed HugoRodriguesPT closed 7 years ago

HugoRodriguesPT commented 7 years ago

Objective: Create a Windows Service that syncs all process Using: Visual Studio 2015 WooCommerce 3.0 Note: Sorry my english 👍

Hello,

Im trying to create a service that syncs all the data from a ERP(Local DataBase) to the website. The easy part, getting data from the DB is easy, now im working on the connection whit the Rest API. Im starting using your framework and i love it! But whit the new version i am afraid that the error is in my calls..

Anyways im trying to insert some products and customers and im getting stuck... probably is a easy fix! my company wants the service to support the last version of WC and as i see all old methods still works.

In some issues i see ppl trying to call the "v3/" URL but now im using this configs: image image

and that works!! but when i try to add a customer nothing happens: image

Probably is something abou Legacy or as i said some wrong calls.

Greetings, Hugo Rodrigues

XiaoFaye commented 7 years ago

First of all, it's good to know that the wrapper is helpful for you. :)

By looking into your code, I can see 2 problems:

  1. When insert product, you are using the latest V1 api, but in InsertCustomer, you are using the legacy object.
  2. I don't see PostCustomer has been called in InsertCustomer.
HugoRodriguesPT commented 7 years ago

Thanks! i was using legacy because i follow the example... i told u it was easy fix! ahah I really dont know if using v3 i need too use legacy, i dont even know what is legacy very well. I find that is a type of shipping option.

anyways now i have my WService running a schedule process that will check if any of the products suffers updates. I made this method but i think that whit good amount of data that will slow the machine. Take a look: image to solve my case i can do Triggers but i find in some issue that u recomend using this: image what is your suggestion??

XiaoFaye commented 7 years ago

Record all product changes, use ProductBatch to do a batch update at the end of your loop.

HugoRodriguesPT commented 7 years ago

image

1- ProductBatch up = new ProductBatch(); 2 - i will storage my changes in the Lists 3 - in the end of the loop i need to batch the lists but i get this error... And now i need to use Legacy? is that related to this? image

XiaoFaye commented 7 years ago

Please remove the legacy here:

image

Never use legacy if you don't have to as it's not being maintained anymore.

HugoRodriguesPT commented 7 years ago

image this methods are from legacy: image Once again, thanks for helping!

XiaoFaye commented 7 years ago

On the top of your code file, if you see any "using xxxx.xxx.legacy", please remove it.

XiaoFaye commented 7 years ago

if you want to use legacy functions, please do it in another code file with a legacy WCObject, so it will not mix with the latest API.

HugoRodriguesPT commented 7 years ago

easy then, can i suggest that you add that in the main documentation? some kind for legacy use, so new users like me dont get lost ;) or adding this lines instead image

XiaoFaye commented 7 years ago

I have been thinking of a better way to keep the legacy and latest API working side by side, hopefully I can include that in the next release.

HugoRodriguesPT commented 7 years ago

Another think since the new version of WC was released yesterday i dont know for sure if i am using the right url since v1-v3 json response... u said in another post to use always /wp-json/wc/v1/ image Is like 2AM here in portugal and im exploring your framework ;)

XiaoFaye commented 7 years ago

Already working on the WC 3.0 API, expecting a pre-release in early May.

XiaoFaye commented 7 years ago

When you pass the URL as ***wc-api/v3/, that is the legacy one,

And /wp-json/wc/v1/ will be the latest API.

HugoRodriguesPT commented 7 years ago

Nice! I'm completing the computer engineering course and for 5 months im working as a trainee in a company and it's the first time I'm creating a windows service, you dont know how happy i am to have this framework eheh Thanks :) i will struggle whit all the changes! In the future i can send you my repository showing the final work (i wope)!

HugoRodriguesPT commented 7 years ago

Hey! My Service is running nicely but now my company added a UC. At the moment every time i start the service I create a new RestAPI instance. Now, because the local machine is always running, i need a scheduled task to validate the RestApi key and secret every hour for example... Can you give me a example of how to do it? Thanks!