CBSubs PostAfPro plugin except for staff

7 years 2 months ago #289953 by activha
Replied by activha on topic CBSubs PostAfPro plugin except for staff
Hello

I am coming back on this subject as we have difficulties automatizing things for moderators.
We use :
if ( \CBLib\Application\Application::MyUser()->isGlobalModerator() ) { 
			CBCookie::setcookie( 'PAPVisitorId', '11111111' );
 			}

This writes a session cookie for our domain activ-ha.com while PAP writes also its own domain cookie at domain .activ-ha.com

Is it possible to select the domain in CBCookie ?
We also tried CBCookie::setcookie( 'PAPVisitorId', null ); but it does not seem to overwrite the previous cookie.

Any hint on this ?
thanks
Jean

Please Log in to join the conversation.

7 years 2 months ago #289958 by krileon
Replied by krileon on topic CBSubs PostAfPro plugin except for staff
I highly recommend using an IDE like PhpStorm (commercial) or Netbeans (free) then selecting your entire Joomla install as its project (download it from ftp to local as needed). This will give you autocomplete and phpdoc. The phpdoc for that function is as follows.

	/**
	 * PHP setcookie but smarter and more secure:
	 * //TBD: add domain info in cookie-name
	 *
	 * @param  string       $name
	 * @param  string       $value
	 * @param  int          $expire
	 * @param  string       $path
	 * @param  string       $domain
	 * @param  boolean|null $secure    Default: Null: same as session cookie
	 * @param  boolean      $httpOnly  Default: true
	 * @return boolean
	 */
	public static function setcookie( $name, $value = '', $expire = 0, $path = null, $domain = null, $secure = null,  $httpOnly = true )

To delete a cookie you typically need to also expire it. So you'd set the value to null or '' (empty string) then set expire to -1.


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 3 weeks ago #291955 by activha
Replied by activha on topic CBSubs PostAfPro plugin except for staff
Hello Kyle

I am coming back on this subject because we have some difficulties avoiding cookies for our mods when they record a payment or when there is an automated payment from ogone

We have this modified code in cbsubs.postafpro.php
public function onCPayBeforeStorePaymentBasketUpdated( $paymentBasket, /** @noinspection PhpUnusedParameterInspection */ $paymentItems, /** @noinspection PhpUnusedParameterInspection */ $paymentTotalizers ) {
		$integrationParams	=&	$paymentBasket->getParams( 'integrations' );
		if ('[post_cb_codeparrainpartenaire]') {
		cbimport( 'cb.session' );
		CBCookie::setcookie( 'PAPVisitorId', '[post_cb_codeparrainpartenaire]' );
		}
		//to avoid commissions for our mods in office recording customer payments
		//careful return; stops recording commissions, replace by  setcookie
 		if ( \CBLib\Application\Application::MyUser()->isGlobalModerator() ) { 
                        //return;
			CBCookie::setcookie( 'PAPVisitorId', null, -1, null, 'activ-ha.com', null, true );
			CBCookie::setcookie( 'PAPVisitorId', null, -1, null, '.activ-ha.com', null, true );
 			}
		//fin modifs
		$user = CBuser::getMyUserDataInstance();		
		if ( $user->get( 'cb_codeparrainpartenaire' )  ) {
   			$affiliateID = $user->get( 'cb_codeparrainpartenaire' );
			CBCookie::setcookie( 'PAPVisitorId', '[cb_codeparrainpartenaire]' );
		} else {
    		$affiliateID = stripslashes( cbGetParam( $_COOKIE, 'PAPVisitorId', null ) );
		}
		// fins
		//$affiliateID		=	stripslashes( cbGetParam( $_COOKIE, 'PAPVisitorId', null ) );

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

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

However, when recording a payment for a customer from our offices, or when a manual payment is recorded in Ogone from our offices, the sale is always attributed to the affiliate with the latest cookie set on the offices computers if there is no value in [cb_codeparrainpartenaire] or in [post_cb_codeparrainpartenaire] for the customer.

As our people visit a lot of affiliates websites to check different things, they always get their cookies on their computers.

This leads to a lot of wrongly affected sales in PAP.

I am trying to find another solution for this and request your assistance if you have an idea ?
Can you tell me if MyUser()->isGlobalModerator() also counts special groups (admin, super admin or managers) ?

Thanks in advance
Jean

Please Log in to join the conversation.

7 years 3 weeks ago #291962 by krileon
Replied by krileon on topic CBSubs PostAfPro plugin except for staff

Can you tell me if MyUser()->isGlobalModerator() also counts special groups (admin, super admin or managers) ?

That just checks if the user has CB Moderator permissions. You need to ensure they actually have CB Moderator permissions as per your Moderator View Access Level within CB > Configuration > Moderation. It looks like you're just deleting the cookie though and not completely cancelling the process.

Another option maybe to just prevent that plugin from even loading for moderators. To do this create a view access level that includes only your customer userroups. Next edit CBSubs PostAfPro within CB > Plugin Management and change its access to your new view access level. As long as your moderators don't meet the criteria for that view access level it shouldn't even load on frontend for them and thus will not process affiliates tracking at all for them.


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 3 weeks ago #292015 by activha
Replied by activha on topic CBSubs PostAfPro plugin except for staff

Another option maybe to just prevent that plugin from even loading for moderators. To do this create a view access level that includes only your customer userroups. Next edit CBSubs PostAfPro within CB > Plugin Management and change its access to your new view access level. As long as your moderators don't meet the criteria for that view access level it shouldn't even load on frontend for them and thus will not process affiliates tracking at all for them.


Well this is not an option because our mods record sales and the sales need to be correctly attributed to the affiliate who triggered it. So we need the plugin to always work.
The thing is that we only need to remove cookies for our mods so that sales are not wrongly attributed to them.

Please Log in to join the conversation.

7 years 3 weeks ago #292031 by krileon
Replied by krileon on topic CBSubs PostAfPro plugin except for staff
Your shouldn't need to delete the cookie, but instead just skip the storing of the cookie value to the basket in onCPayBeforeStorePaymentBasketUpdated. Please note your below code usages do not work.

Substitutions do not just parse in every PHP file. They need to be passed through the substitutions parsing function. Code in CB Auto Actions is an except to this since it passes the code through the substitution parsing function before being executed.
		if ('[post_cb_codeparrainpartenaire]') {
		cbimport( 'cb.session' );
		CBCookie::setcookie( 'PAPVisitorId', '[post_cb_codeparrainpartenaire]' );
		}

The below your set cookie usage should be setting the cookie value to your $affiliateID value and not '[cb_codeparrainpartenaire]' as that's a substitution that won't be processed.
		if ( $user->get( 'cb_codeparrainpartenaire' )  ) {
   			$affiliateID = $user->get( 'cb_codeparrainpartenaire' );
			CBCookie::setcookie( 'PAPVisitorId', '[cb_codeparrainpartenaire]' );
		} else {
    		$affiliateID = stripslashes( cbGetParam( $_COOKIE, 'PAPVisitorId', null ) );
		}

The code in onCPayBeforeStorePaymentBasketUpdated is also just to ensure the cookie value doesn't get lost when the basket is paid by an IPN for example. If you don't set it there and it's a PDT payment then it'll still get used by the PostAfPro API. So you'd need to add a check to onCPayAfterPaymentStatusUpdateEvent as well to just stop the affiliate tracking process if there's no affiliate id and the user is a moderator.


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.

Moderators: beatnantkrileon
Time to create page: 0.368 seconds

Facebook Twitter LinkedIn