freescout-help-desk / freescout

FreeScout — Free self-hosted help desk & shared mailbox (Zendesk / Help Scout alternative)
https://freescout.net
GNU Affero General Public License v3.0
2.95k stars 488 forks source link

WooCommerce Integration is Spotty #4017

Closed aaversa closed 4 months ago

aaversa commented 4 months ago

I have the WooCommerce module installed and correctly configured with my store's API key. My store is hosted on the same domain (different server), on enterprise-grade hardware. We previously used Helpscout which integrated with the store without any issue.

However, with Freescout, when loading a given conversation with a customer that DEFINITELY has WooCommerce orders, the majority of the time the orders section simply 'spins' for 30-45 seconds before timing out and saying there are no orders.

This doesn't happen 100% of the time. Sometimes if I refresh the page a few times, the orders will eventually load. Some customers' orders load instantly, too. It's not clear what if any pattern there is.

We have many, many services integrated with our WooCommerce store and none of them exhibit this behavior so I don't think it's an issue with our WooCommerce database or server response time.

Our Freescout installation is on a Hetzner server with 3 vCPUs and 4GB of RAM. I have been monitoring our CPU utilization and it has never crossed 50%.

PHP version: 8.3 FreeScout version: Latest Database: Nginx Are you using CloudFlare: No

EDIT: I just checked the Laravel log and I am seeing a bunch of this:

[WooCommerce] HTTP Status Code: 0 (Store not found at the specified URL) | Requested resource: https://impactsoundworks.com/wp-json/wc/v2/orders

I can most definitely guarantee our store is at https://impactsoundworks.com/. Also, this integration was (at least sort of) working yesterday... What's going on?

freescout-helpdesk commented 4 months ago

The only way to figure it out is to debug on your server. Try https://github.com/freescout-helpdesk/freescout/wiki/Debugging

aaversa commented 4 months ago

This is the error in the logs, are you looking for more detail than this?

[WooCommerce] HTTP Status Code: 0 (Store not found at the specified URL) | Requested resource: https://impactsoundworks.com/wp-json/wc/v2/orders

I am 100% sure this is the correct endpoint. I have just used Postman and tested it for myself - it is correct and returning data as expected with a simple GET request.

freescout-helpdesk commented 4 months ago

https://github.com/freescout-helpdesk/freescout/issues/4017#issuecomment-2104600271

freescout-helpdesk commented 4 months ago

Unfortunately we can't tell what can be the reason of the problem from here. The only way to do it is for someone to investigate it on your server.

aaversa commented 4 months ago

By "your server" do you mean the server hosting Freescout? If so, as I showed in the logs, the only error is that HTTP Status Code 0. But that doesn't make sense as, like I said, every other application that uses my store's API (there are dozens) work perfectly, including Postman running on my computer. Is the WooCommerce module open source? Can I open it up and see if I can debug this myself?

EDIT: I've done this and spent awhile testing. The problem seems to be a cURL timeout... Our WooCommerce store db is quite large as we have many hundreds of thousands of orders. Requesting the orders on-demand like this takes about 40 seconds when going through the WP/Woo application layer. (A direct MySQL query is much much faster.)

I was looking into how Helpscout handles this, and it seems like rather than on-demand grabbing orders when you first open an email, it uses a store server-side plugin possibly in combination with caching data on the Freescout side.

I'm curious if this module is being used by any other stores in the 400k+ order range and how it performs for them.

In the short term perhaps I can adjust the cURL timeout manually.

aaversa commented 4 months ago

@freescout-helpdesk I have just rewritten some aspects of the WooCommerce integration.

The retrieval time has gone from 40s to less than 1 second.

I did this by working with Automattic to create a new endpoint via WC plugin that is orders of magnitude faster. I then added an integration via a separate plugin on the Orders page for customers allowing them to submit a ticket easily. See screenshots.

The plugins are not really polished but they do work and makes the functionality equivalent to Helpscout.

Are you interested in taking a look at our work?

need help form Orders screen

freescout-helpdesk commented 4 months ago

You can send the code to support@freescout.net We'll take a look.

OneTwo3D commented 1 month ago

Hi, has there been any update? I have also the Woocommerce module installed and it isn't loading any previous orders.

aaversa commented 1 month ago

Hi, has there been any update? I have also the Woocommerce module installed and it isn't loading any previous orders.

Not from the Freescout team, but you can look at the new endpoint we created here.

https://pastebin.com/9MFKXESy

Then you would just point Freescout to this endpoint instead of the regular WooCommerce one. Works literally orders of magnitude faster.

OneTwo3D commented 1 month ago

Thanks, I'll have a look at it :) But would be good if FreeScout would update their plugin.

OneTwo3D commented 1 month ago

Ok, I managed to connect to the new endpoint via Postman and can download order info, I managed to connect to it from Freescout (via the plugin settings), but Freescout is still not showing any order info within a ticket...

OneTwo3D commented 1 month ago

@aaversa do you have an example how you added the alternative API to the WooCommerceServiceProvider.php in Freescout? Unfortunately the Freescout original plugin using the standard Woo API isn't working for me (the ?search string can search for anything but an email address in my installation it seems).