Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    Still looking into this, thanks for your patience. I have to go and recreate some of your config to be able to determine what’s causing this issue.

    Can you clarify whether you have the fields in Pods as allowing for read/write on the REST API tab of that field?

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Thanks for your time and interest @sc0ttkclark

    The field has read/write access, not in the REST API tab, only in that field (and works fine in a new product).

    You can download my Pods JSON configuration from https://u.pc.cd/mT0ctalK

    Kindly regards, Carlos Longarela.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Hi @sc0ttkclark, any result about this? or could I contact support by a quick via? I don’t see any option in my Friends of Pods account to contact, and the question was posted two weeks ago.

    If the option to modify a relationship field with API REST doesn’t work, I must search for another plugin alternative.

    Thanks in advance.

    Kindly regards, Carlos Longarela.

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    Looking at this again today, sorry I was going through a loss of a family pet and then subsequent holiday rush at work.

    Will post another update for you once I have reproduced the issue and have a recommendation.

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    Your config link isn’t working for me, there’s a DNS issue I think.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Hi @sc0ttkclark works fine for me, but anyway, upload to OneDrive here: https://1drv.ms/u/s!AjDUA-dYPHfu9rRD3ozNE-PrDtnwmw?e=Euh1jj

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Oh, sorry to hear about your loss of a family pet.

    Kindly regards and happy Christmas.

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    The first link works now, must have been a DNS issue on my side, not yours. Sorry about that. Will look into this config today.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Ok, thanks a lot @sc0ttkclark I wait for your response.

    Kindly regards, Carlos Longarela.

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    I was able to reproduce the issue. I have some more digging to do but for some reason the update to the metadata for this product isn’t getting hooked into by Pods at this point. Determining the cause of that next.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Ok, thanks, yes, there is a problem with that product update with API REST. Thanks a lot @sc0ttkclark

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    I see now that it’s using a different update hook. We only hook into add/update/delete for post meta data (and the same for user/term/comment meta too).

    The function that ultimately gets called is update_metadata_by_mid() which we aren’t hooking into right now for Pods.

    Here’s a workaround for you that should do the trick. It essentially takes over the update for that meta key and makes it Pods compatible.

    
    add_filter( 'update_post_metadata_by_mid', static function( $check, $meta_id, $meta_value, $meta_key ) {
    	$covered_keys = [
    		'cl_product_documents',
    	];
    
    	// Stop overriding the saving process if it's not a meta key we want to handle.
    	if ( ! in_array( $meta_key, $covered_keys, true ) ) {
    		return $check;
    	}
    
    	// Get the original meta record.
    	$meta = get_metadata_by_mid( 'post', $meta_id );
    
    	// Stop overriding the saving process if the original meta record was not found.
    	if ( ! $meta ) {
    		return $check;
    	}
    
    	// Get the post ID from the original meta record.
    	$post_id = $meta->post_id;
    
    	// If the meta key changed, delete the old value.
    	if ( $meta->meta_key !== $meta_key ) {
    		delete_post_meta( $post_id, $meta_key );
    	}
    
    	// Force the update in a Pods compatible way.
    	update_post_meta( $post_id, $meta_key, $meta_value );
    
    	// Stop the normal saving process.
    	return true;
    }, 10, 4 );
    
    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    I’ll work on a fix for this as part of an upcoming Pods release, but I don’t have timing for that right now unfortunately. I have some tweaks I’ve put into some of my upcoming Pods 2.8 work but that is only just about to go out as a beta release in the coming days.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Thanks a lot for the fix @sc0ttkclark. I’ll check it in a few hours, and I’ll come back here with the result.

    Thanks a lot for your work.

    Plugin Author Jory Hogeveen

    (@keraweb)

    I’ve created a bug report about this issue: https://github.com/pods-framework/pods/issues/5903

    Closing topic here in favor of GitHub.

    Cheers, Jory

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Edit WooCommerce Product with relationship field with API REST’ is closed to new replies.