I had a company approach me, looking for a way to be able to continue to use their WooCommerce store, but also continue to use their NetSuite ERP system to manage their product offering.
We talked about it a bit, and determined the easiest way to approach this was to create a one-way sync relationship between NetSuite and WooCommerce. Basically, we would create a worker that would periodically check to see if there are any updates for the products stored in NetSuite, and update the products in WooCommerce automatically when any changes are detected. To accomplish this, I had to make use of NetSuite's SOAP-based API, along with the help of their PHP SDK to fetch the products from NetSuite, compare them to the existing site, and update anything that changed.
The problem? This customer had thousands of products, so you couldn't exactly sync all of the products at one time - it would crash the server, or at minimum make the site very slow.
For this integration, I decided the best way to do this was with this flow:
- Fetch a list of 10 recently updated products from NetSuite, sorted by updated date.
- Fetch the last updated date of each product in the list
- If the updated date on the NetSuite product is newer, or the product doesn't exist, then update the product.
- If all ten products were out of date locally, then start another background job to fetch the next 10 products
- Repeat this process until everything is synchronized.
I used a WordPres cron job that ran every 10 minutes, and would check to see if the products are out of date, and would update on WooCommerce automatically.
The biggest challenge I faced with this was the occasional situation where a product would not synchronize fast-enough for our needs. In-order to get around this, I set the site up so that it was possible to force a product to sync with NetSuite immediately. I also wanted to make sure it would be possible to force the site to re-sync all of the products at one time, should something go wrong with the initial sync, so I made it possible to force all products to re-sync as well.
Another significant challenge was getting the images to remain in-sync. This is a frustrating limitation about WordPress - most of WordPress is very buttoned up, and has a simple function that just...solves your problem. Want to create a post? No problem,
wp_insert_post() has you covered. What happens, however, when you want to upload an image and associate it with the post? That...that's not so easy. There's no such thing as
wp_upload_media() or something like that, so I had to instead build out the script that actually handles that uploading process. I also had to compare the images to confirm that they weren't the same before uploading, which, was not as reliable as I hoped it would be.
Another big issue I had was getting authenticated with the SOAP API. I spent a lot of time bashing my head against my keyboard trying to make sense of why I was not getting authenticated. It turns out, because I was working on a local instance, it wasn't working because my SSL cert couldn't be validated. Once I worked around that, it was smooth sailing, but up until that point I was questioning my sanity. 🙃
Overall, this was a fun project to build, and I learned a lot about the nuance and intricacies of WooCommerce from this. There was a lot I wanted to do to make this plugin more robust, and more-reliable, but there just hasn't been enough resources to give to it in-order for me to do more than this. Ultimately, it works pretty well, and I'm happy with the result.