stock synchronization
-
Hello,
I am using Inventory Sync for WooCommerce Free 2.1.1 to synchronize stock between two independent WooCommerce stores.
I have found a problem with stock synchronization for variable products.The problem
Manual changes to a variation’s stock are synchronized correctly between the two stores.
However, when a customer purchases a variation, WooCommerce correctly reduces the stock on the source store, but the stock is not updated on the other store.
For example:
- Store A variation SKU:
LOR-GRN-42 - Store B has the same variation SKU:
LOR-GRN-42 - Stock on Store A: 10
- Customer purchases 1 item
- Store A correctly changes to 9
- Store B remains at 10
The same variation synchronizes correctly when I manually change its stock in the WooCommerce admin.What I found in the code
After investigating version 2.1.1, it appears that the order synchronization code handles variations differently.
In
format_order_items(), the parent product ID from the source store is used when building the synchronization data:if ( $parent_id = $product->get_parent_id() ) { $return['variations'][$parent_id][] = $this->product_data( $product, $woocommerce ); }Later, this parent ID is used when updating the variation:
$woocommerce->put( "products/{$parent_id}/variations/{$variation_id}", $variations[0] );The problem is that the parent product ID belongs to the source WooCommerce installation.
On two independently created WooCommerce stores, the same product normally has different database IDs.
Therefore, using the source store’s parent ID when making the REST API request to the destination store can cause the variation update to fail.
Interestingly, the exception is also caught without logging:
catch ( Exception $e ) { // TODO logger }This makes the problem difficult to diagnose because there is no useful error in the WooCommerce logs.Workaround
I tested a workaround that searches for both the parent product and the variation in the destination store by SKU and then uses the destination store’s IDs for the REST API request.
With this approach, stock synchronization after a purchase works correctly in both directions.
So the issue appears to be specifically related to variation order synchronization when the two stores have different product/parent IDs.
Could you please check this part of the 2.1.1 code and confirm whether this is a bug?
If so, it would be great if it could be fixed in a future version.
Thank you.
- Store A variation SKU:
You must be logged in to reply to this topic.