• the hook bellow causes fatal error for products saved on a different blog then the blog that the ajax hook runs

    Hooks::onAction( ‘shutdown’ )
    ->then( function() use ( $productId ) {
    // For direct updates, we adjust terms filters just before triggering the update.
    $hasTermsClausesFilter = $this->adjustTermsFilters();

    wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_changed( $productId );

    $this->restoreTermsFilters( $hasTermsClausesFilter );
    } );

    We use an ajax hook on blog id (1) where we process products on different blogs (2) and call product->save
    This will register the product hook from Woocommerce multilingual on the wrong blog and that causes a fatal error as the product doesn’t exist on blog (1)

    add_action(‘wp_ajax_blog_1’, function(){
    // we are on blog 1 here

    switch_to_blog(2); // switched to blog 2
    //create a product here
    //add attributes, and other data
    $product->save()
    restore_current_blog();

    echo “success”; //return a response to ajax

    wp_die(); //your hook from above runs here on blog(1) searching for product 190 from blog(2) saved above. This causes a fatal error and javascript breakes because the product doesnt exist on blog(1)
    });

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Andrés Cifuentes

    (@andrescifuentesr)

    Hello @wordpressheroes,

    Thank you very much for your report. I’ve passed this information to our devs and they will investigate it carefully.

    I’ll update you once I have more information.
    Regards

    Plugin Support Andrés Cifuentes

    (@andrescifuentesr)

    Hi again @wordpressheroes,

    Could you please try the following patch in your staging website and let us know if it helps?

    public function triggerUpdateForTranslations( $productId ) {
        if (
            'product' === get_post_type( $productId )
            && 'publish' === get_post_status( $productId )
            && ! $this->sitepress->is_original_content_filter( false, $productId, 'post_product' )
        ) {
            $savedOnBlogId = get_current_blog_id();
    
            Hooks::onAction( 'shutdown' )
                ->then( function() use ( $productId, $savedOnBlogId ) {
                    $savedOnAnotherBlog = get_current_blog_id() !== $savedOnBlogId;
    
                    if ( $savedOnAnotherBlog ) {
                                switch_to_blog( $savedOnBlogId );
                    }
    
                    // For direct updates, we adjust terms filters just before triggering the update.
                    $hasTermsClausesFilter = $this->adjustTermsFilters();
    
                    wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_changed( $productId );
    
                    $this->restoreTermsFilters( $hasTermsClausesFilter );
    
                    if ( $savedOnAnotherBlog ) {
                                restore_current_blog();
                    }
                } );
        }
    }

    I hope it helps!

    Thread Starter Alexandru Negoita

    (@wordpressheroes)

    Hi!

    Thank you for the help. It works.

    Could you please confirm if this will be included in your next release(s) ?

    Thank you!

    Plugin Support Andrés Cifuentes

    (@andrescifuentesr)

    Thank you very much for your confirmation @wordpressheroes.
    Sure, however I can’t confirm you at this point in which version it will be included.

    I’ll keep this ticket updated once I get a confirmation.
    Regards

    Plugin Support Andrés Cifuentes

    (@andrescifuentesr)

    Hello @wordpressheroes.

    Just to inform you that this issue should have been solved in WCML 5.3.0. Could you please give it a try?

    Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce multilingual bug on multisite install’ is closed to new replies.