CBSubs PostAfPro plugin except for staff

7 years 1 month ago #292044 by activha
Replied by activha on topic CBSubs PostAfPro plugin except for staff
Well these codes with substitutions are the code you gave me more than a year ago in order to get the correct affiliate ids ;-)

Can you tell me what to do at this stage ?
Is this possible to add an auto action to this integration to achieve what we want ?
Meaning overwriting a cookie when the affiliate code is manually inserted in the registration form or found in CB table when updating a subscription ? And avoiding this when a mod is manually subscribing a customer.

For now, the affiliate id is only one field in the CBSubs plan.
What we want to do is make it dynamic so that this field is either a CB field for an existing customer, or is taken from the cookie with an ability to be manually overwritten on the registration form.



Thanks for the help on this, we have been struggling with this for months
Attachments:

Please Log in to join the conversation.

7 years 1 month ago #292050 by krileon
Replied by krileon on topic CBSubs PostAfPro plugin except for staff

Well these codes with substitutions are the code you gave me more than a year ago in order to get the correct affiliate ids

Don't recall what I did a year ago, but have a hard time believing I gave you obviously non-working code. :unsure:

Can you tell me what to do at this stage ?
Is this possible to add an auto action to this integration to achieve what we want ?
Meaning overwriting a cookie when the affiliate code is manually inserted in the registration form or found in CB table when updating a subscription ? And avoiding this when a mod is manually subscribing a customer.

Depends on what you're trying to do. Still trying to understand what it is you're attempting. You want to use the fields value as the affiliate id if supplied otherwise use the cookie? However, if the user is a moderator you want it to ignore the cookie and only track if the field has a value in the case of moderator? In onCPayBeforeStorePaymentBasketUpdated is where you'd handle switching between the field value and the cookie as needed, but you need the field value of the basket user and not of the viewing user. So something like the below probably.

	public function onCPayBeforeStorePaymentBasketUpdated( $paymentBasket, /** @noinspection PhpUnusedParameterInspection */ $paymentItems, /** @noinspection PhpUnusedParameterInspection */ $paymentTotalizers ) {
		$basketUser			=	CBuser::getUserDataInstance( $paymentBasket->user_id );
		$integrationParams	=	$paymentBasket->getParams( 'integrations' );
		$affiliateID		=	null;

		if ( $basketUser->get( 'FIELD_NAME' ) ) {
			$affiliateID	=	$basketUser->get( 'FIELD_NAME' );
		} elseif ( ! \CBLib\Application\Application::MyUser()->isGlobalModerator() ) {
			$affiliateID	=	stripslashes( cbGetParam( $_COOKIE, 'PAPVisitorId', null ) );
		}

		if ( $affiliateID ) {
			$integrationParams->set( 'postafpro_affiliateid', $affiliateID );
		}

		$paymentBasket->storeParams( 'integrations' );
	}

That only handles the setting of the postafpro_affiliateid to the basket though. You need to next make sure the affiliate tracking is blocked entirely if postafpro_affiliateid has no value and the user is a moderator as PDTs will still cause PostAfPro to pick up the cookie (I guess you could expire it at this point, but it'd be more reliable to just handle these checks in PHP). That check would need to be added to onCPayAfterPaymentStatusUpdateEvent where it adds the $affiliateID. Something like the below probably.

FROM:
		if ( $affiliateID ) {
			$saleTracker->setCookieValue( $affiliateID );
		}
TO:
		if ( $affiliateID ) {
			$saleTracker->setCookieValue( $affiliateID );
		} elseif ( \CBLib\Application\Application::MyUser()->isGlobalModerator() ) {
			return;
		}

Please note this is just an example and was not tested. Please test thoroughly and adjust as needed.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

7 years 1 month ago #292106 by activha
Replied by activha on topic CBSubs PostAfPro plugin except for staff
Yes this is what I want to achieve.
Will test this and thanks a lot for the hints.

May I suggest that it would be perfect if this file could be overwritten by an auto action or an override ? so that it can be kept modified at each upgrade ?

Thanks anyway

Please Log in to join the conversation.

7 years 1 month ago #292109 by krileon
Replied by krileon on topic CBSubs PostAfPro plugin except for staff
You can rename the files, the PHP class name, and adjust the XML file accordingly so it becomes your own installable plugin.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

7 years 1 month ago - 7 years 1 month ago #292140 by activha
Replied by activha on topic CBSubs PostAfPro plugin except for staff
Coming back on the code you suggested, it seems to work fine for the cases when the field value is provided either on the registration page, or is already set in the client profile when this is an upgrade.

But when a moderator tries to register a new customer without the field value, the moderator's cookie is still used.

We add the PAP tracks code on our pages, could it interfere with the postafpro plugin ?
(function(d,t) {
    var script = d.createElement(t); script.id= 'pap_x2s6df8d'; script.async = true;
    script.src = '//activ-ha.com/affiliation/scripts/trackjs.js';
    script.onload = script.onreadystatechange = function() {
      var rs = this.readyState; if (rs && (rs != 'complete') && (rs != 'loaded')) return;
      PostAffTracker.setAccountId('default1');
      try { PostAffTracker.track(); } catch (e) {}
    }
    var placeholder = document.getElementById('papPlaceholder');
    placeholder.parentNode.insertBefore(script, placeholder);
    placeholder.parentNode.removeChild(placeholder);
  })(document, 'script');

I also tried to cancel the cookie with :
		$basketUser			=	CBuser::getUserDataInstance( $paymentBasket->user_id );
		$integrationParams	=	$paymentBasket->getParams( 'integrations' );
		$affiliateID		=	null;

		if ( $basketUser->get( 'cb_codeparrainpartenaire' ) ) {
			$affiliateID	=	$basketUser->get( 'cb_codeparrainpartenaire' );
		
		} elseif ( \CBLib\Application\Application::MyUser()->isGlobalModerator() ) {
			CBCookie::setcookie( 'PAPVisitorId', null, -1, null, 'activ-ha.com', null, true );
			CBCookie::setcookie( 'PAPVisitorId', null, -1, null, '.activ-ha.com', null, true );
          
        } elseif ( ! \CBLib\Application\Application::MyUser()->isGlobalModerator() ) {
			$affiliateID	=	stripslashes( cbGetParam( $_COOKIE, 'PAPVisitorId', null ) );
		}

		if ( $affiliateID ) {
			$integrationParams->set( 'postafpro_affiliateid', $affiliateID );
		}

		$paymentBasket->storeParams( 'integrations' );
		
	}

But no chance neither, the cookie is still there in the browser :-(

I don't understand where I miss the point...

Please Log in to join the conversation.

7 years 1 month ago #292144 by krileon
Replied by krileon on topic CBSubs PostAfPro plugin except for staff
With the above code I've supplied the postafpro_affiliateid basket value is never set for moderator usage if the field value isn't supplied then before it logs the commission it checks if postafpro_affiliateid has a value and if it doesn't and the user is a moderator it terminates the process there. The below is what terminates the commission process.

FROM:
		if ( $affiliateID ) {
			$saleTracker->setCookieValue( $affiliateID );
		}
TO:
		if ( $affiliateID ) {
			$saleTracker->setCookieValue( $affiliateID );
		} elseif ( \CBLib\Application\Application::MyUser()->isGlobalModerator() ) {
			return;
		}

Most likely what your issue is is the basket is being paid via IPN and not PDT. This means the IPN user is of course not a moderator so the process never terminates, but IPN case shouldn't have a cookie to begin with so that really shouldn't be logging anything either. At any rate you can try the below.

FROM:
		if ( $affiliateID ) {
			$saleTracker->setCookieValue( $affiliateID );
		}
TO:
		if ( $affiliateID ) {
			$saleTracker->setCookieValue( $affiliateID );
		} else {
			return;
		}


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.231 seconds

Facebook Twitter LinkedIn