Jump to content

Input data loss on saveReady on Publish


Vayu Robins
 Share

Recommended Posts

Hi.

I am hooking into the saveReady hook in order to update data on other pages, when a page is published. In other words, when a transaction is published, the user is updated. Certain fields are reset on Publish for some reason. It's only on publish, so if I insert data into input fields again and press save, then it works.

So i have added this bit of code to the admin.php file in my template.

$page->addHook( 'Pages::saveReady', null, 'credit_published' );
function credit_published( $event ) {
	$page = $event->arguments[0];

	if( $page->template == "credit-log" && $page->id && !$page->isTrash() && $page->isChanged( 'status' ) && !$page->is( Page::statusUnpublished ) && $page->credit_action->id === 3 ) {
		// Add credit to user.
		$partner = $page->partner;
		$partner->of( false );
		$partner->credit = intval( $partner->credit + $page->credit );
		$partner->save();
	}
}

post-3258-0-62706700-1436880061_thumb.jp

Link to comment
Share on other sites

Soma, is that the $page->addHookAfter( 'Pages::saved', null, 'credit_published' ); you refer to?

LostKobraKai, is that the $page->addHookAfter( 'Page::published', null, 'credit_published' ); you refer to?

I will try.

It's Pages::published. I've corrected it already in my previous post, but it seems you didn't notice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...