• Resolved slawos

    (@slawos)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Misha Rudrastyh

    (@rudrastyh)

    Hello,

    Thank you very much for the information. I will release the fix this week.

    Plugin Author Misha Rudrastyh

    (@rudrastyh)

    Hello again,

    It is fixed. Please update to 2.1.2 version of the plugin, when it will be ready.

    Related to plugin logs – sorry for inconvenience, logs are currently only available in the Pro version. But I would agree, probably it would be a good idea to include them in the Free version as well.

    Please let me know if it is fixed for you as well (on my test sites everything is working perfectly now).

    Thread Starter slawos

    (@slawos)

    Yes, everything is working properly now. Thank you and best regards.

    Plugin Author Misha Rudrastyh

    (@rudrastyh)

    I’m glad, thanks for the update!

    p.s. If you could leave a 5-star to this plugin, that would make me very happy 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.