WooCommerce connector for Tryton

With kind help of @edbo, I could manage to install it in a PIP installation:

cd <your_environment>
. bin/activate
## the module depends on another module called web_shop. Install that one first.

git clone https://gitlab.com/kopen/web_shop
cd web_shop
python3 setup.py install
cd ..
git clone https://gitlab.com/kopen/web_shop_woocommerce
cd web_shop_woocommerce
python3 setup.py install
cd ..
trytond-admin -c [your-trytond.conf] -d [your database] -m -vv
trytond-admin -c trytond.conf -d [your database] --update=web_shop_woocommerce --activate-dependencies -vv

(Hope I copied everything correctly).

I only succeeded to install it with tryton 5.6, not 5.4.
Now I can see the web shop items at “sales” menu entry, created a woocommerce web shop and pasted the woocommerce keys (credentials).

Now nothing happens, and I couldn’t find any “action” buttons or so. @pokoli mentioned cron jobs above - in my install none such are running. Is my guess true that I need a certain cron job - and how would I install that in PIP?

Thank you for your work !

Cheers,
Wolf

It seems the module adds two jobs.

  • Update WooCommerce Products
  • Download WooCommerce Orders

Login as admin into Tryton and go to “Administration” -> “Scheduler” -> “Schedules Actions”

Create a new action and select one of the above jobs as “Method”. You can also set when it should run at what time. Use the “Run Once” button to run the job manually (the job is executed directly).

trytond-cron is a standalone process which continuously check all the actions and when the time of that actions is passed the Method will be executed in the background. So when you are testing, it doesn’t make sense a lot to automatically get the data out of woocommerce.

Also trytond-cron comes with the standard Trytond package so you have it already available. To execute it:

  • open a new terminal (commandline)
  • go to your virtual environment
  • activate it
  • trytond-cron -c trytond.conf -d <your database>

You don’t see any output until something will be executed (the time of an action has passed)
In you other terminal you can run the “normal” trytond, connect to it with the client and do everything you want.

Yes, there are two cron jobs to perform the sincronitzation.

The first syncs the webshop products and it’s stock quantity to the woocommerce shop.
The latter downloads customer orders into the sales model. It also creates the customer data into the party model if the customer does not exist already in Tryton.

Thank you very much. I found the “scheduled actions” things already in place. So first attempt was to download orders once manually.

Bildschirmfoto von 2020-09-26 20-16-57

There are open (untouched) orders available in woocommerce, credentials are in place - I guess I should have a look into a logfile… True? Where would I find it?

You should try to understand the error message which is in German and I do not understand.

It depends on how are your running the server and which logging configuration you set.

The message says: “I’m sorry, ressources cannot be listed”

I tried to set up standard logging following the info given here:
https://discuss.tryton.org/t/2311/2, with the standard log-conf.

When I click the “execute once” button from “scheduled actions”, I get this on terminal (and as well in the log file):

Thu Oct 01 17:57:21 2020] INFO:trytond.protocols.dispatcher:<class 'trytond.pool.company.company'>.read(*([1], ['party', 'party.rec_name', 'rec_name', '_timestamp'], {'client': 'f2cd8973-81bb-44b1-b441-b65c2a348310', 'warehouse': None, 'employee': None, 'company': 1, 'company.rec_name': '[here-was-my-company-name]', 'language': 'de', 'language_direction': 'ltr', 'groups': [5, 6, 1, 4, 8, 22, 2, 23, 3, 12, 13, 7, 20, 21, 15, 14, 18, 16, 17, 10, 9, 11, 19], 'locale': {'date': '%d.%m.%Y', 'grouping': [3, 3, 0], 'decimal_point': ',', 'thousands_sep': '.'}, 'company_work_time': {'h': 3600, 'm': 60, 's': 1, 'Y': 6912000.0, 'M': 576000.0, 'w': 144000.0, 'd': 28800.0}}), **{}) from admin@127.0.0.1//tryton-56/
Thu Oct 01 17:57:21 2020] INFO:werkzeug:127.0.0.1 - - [01/Oct/2020 17:57:21] "POST /tryton-56/ HTTP/1.1" 200 -
Thu Oct 01 17:57:31 2020] INFO:trytond.protocols.dispatcher:<class 'trytond.pool.ir.cron'>.run_once(*([4], {'client': 'f2cd8973-81bb-44b1-b441-b65c2a348310', 'warehouse': None, 'employee': None, 'company': 1, 'company.rec_name': '[here-was-my-company-name]', 'language': 'de', 'language_direction': 'ltr', 'groups': [5, 6, 1, 4, 8, 22, 2, 23, 3, 12, 13, 7, 20, 21, 15, 14, 18, 16, 17, 10, 9, 11, 19], 'locale': {'date': '%d.%m.%Y', 'grouping': [3, 3, 0], 'decimal_point': ',', 'thousands_sep': '.'}, 'company_work_time': {'h': 3600, 'm': 60, 's': 1, 'Y': 6912000.0, 'M': 576000.0, 'w': 144000.0, 'd': 28800.0}, '_timestamp': {'ir.cron,4': '1601050672.168693'}}), **{}) from admin@127.0.0.1//tryton-56/
Thu Oct 01 17:57:35 2020] INFO:werkzeug:127.0.0.1 - - [01/Oct/2020 17:57:35] "POST /tryton-56/ HTTP/1.1" 200 -

I replaced my company name manually.
Hope that speaks… (-;

Cheers,
Wolf

This seems like an error message from woocommerce as the connector will print the API error in case of any.

So it seems that you have something that is not porperly setup on woocomerce side.

Did you enable url rewriting? IIRC the api won’t work when disabled.

Sorry but there is no error message on the logs you posted. This is because it’s a expected error so it is shown to the user.

Not entirely sure about this, but in the .htaccess of the page the rewrite engine is set to “on”. Is that what you mean - or how would I know? -

I’m using packlink.com API without any trouble.

I tried to dig a little deeper into that. It looks as if I could test my web shop’s API with these URLs simply at the web browser:

https://[my-web-shop's-URL]/wp-json/wc/v2/orders?consumer_key=ck_[my-consumer-key]&consumer_secret=cs_[my-consumer-secret]
 
https://[my-web-shop's-URL]/wp-json/wc/v2/products?consumer_key=ck_[my-consumer-key]&consumer_secret=cs_[my-consumer-secret]

When I do so with my credentials, I actually get readable lists, containing my products and orders. So the web shop seems to deliver data.

What could be the problem that my tryton cannot read it? - I’m using a PIP setup in a virtual environment, everything is running locally. Do I need to grant web access manually - or such?

Cheers,
Wolf

I think your prolbem is that you are using an old version of the API (v2) while the module has been developed on verison v3.

I tried to call

https://[my-web-shop's-URL]/wp-json/wc/v3/[orders|products?credentials-etc]

and I get the same answer, so I guess the v3 API is active as well.

Will somebody be so kind and give me a hint how I can proceed?

Well, the connector is using the woocommerce Python library https://pypi.org/project/WooCommerce/ When you read the documentation there you can try those things in your virtual environment. When you get data back, you have ruled out a problem between your woocommerce and the python library. Then it’s time to move into the code of the module.

:rofl: :rofl: :rofl:

Nice to hear what grade of confidence you have about my abilities…
Next life. Maybe…

But I’ll be happy to try and report back anything I’m advised.
(Exepct sudo rm -rf *).

Create a file called test_woo.py and put the following data into it:

from woocommerce import API

wcapi = API(
    url="https://[my-web-shop's-URL]",
    consumer_key="<your key>",
    consumer_secret="<your secret>",
    version="wc/v3"
)

r = wcapi.get("products")
print(r.status_code)
print(r.headers)
print(r.text)
print(r.json)

execute this file with python test_woo.py within your activated virtual environment. You should see some data with the print statements.

1 Like

This is what I get. “401” seems to be an authentification error. So I re-checked credentials with a browser as stated in message #16, but they are still working.

(tryton-5.6) wd@Simux-380:~/tryton-56-exp$ python test_woo.py
401
{'Server': 'nginx', 'Date': 'Tue, 13 Oct 2020 13:37:59 GMT', 'Content-Type': 'application/json; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'X-Robots-Tag': 'noindex', 'Link': '<https://shop.komponentenkontor-berlin.de/wp-json/>; rel="https://api.w.org/"', 'X-Content-Type-Options': 'nosniff', 'Access-Control-Expose-Headers': 'X-WP-Total, X-WP-TotalPages, Link', 'Access-Control-Allow-Headers': 'Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type', 'Vary': 'Origin'}
{"code":"woocommerce_rest_cannot_view","message":"Entschuldigung, es k\u00f6nnen keine Ressourcen aufgelistet werden.","data":{"status":401}}

The messsage “sorry, no ressources can be listed” are the same as in tryton GUI.

So, no problem with the module, but with connection. You can search the internet for the woocommerce_rest_cannot_view and find https://stackoverflow.com/questions/42186757/woocommerce-woocommerce-rest-cannot-view-status-401.

You can try to change:

wcapi = API(
    url="https://[my-web-shop's-URL]",
    consumer_key="<your key>",
    consumer_secret="<your secret>",
    version="wc/v3"
)

to

wcapi = API(
    url="https://[my-web-shop's-URL]",
    consumer_key="<your key>",
    consumer_secret="<your secret>",
    version="wc/v3",
    query_string_auth=True
)

It seems for many people that solved their case. It’s because of using httpS.

But maybe the keys you have created are not sufficient enough and have the wrong rights, e.g. they are not allowed to show the products. Maybe @pokoli can also shed some light here with explaining his setup.

1 Like
wcapi = API(
    url="https://[my-web-shop's-URL]",
    consumer_key="[your key]",
    consumer_secret="[your secret]",
    version="wc/v3",
    query_string_auth="true"
)

Eddy the great! It works. Magician!

Yes. My homework now is to find out where I have to insert the line.
Already tried. Already failed… Sorry.

1 Like

Unfortunately you can’t, see web.py · master · kopen / web_shop_woocommerce · GitLab. @pokoli have to make some changes to the code so support this.

There is an API parameters property that can be overriden to match custom requirements.

Why not? The property can be overriden in custom module so you can pass any arguments to the API constructor and make it work for any use case.