Re: Affiliate program for some products only

  • Posts: 80
  • Thank you received: 1
13 years 1 month ago #30807

Hello,

I have the Business edition of Hikashop and would really need to enable Affiliate feature working for only products I want to promote and not for any sale within the website. I assume there is something to do with Hika's Affiliate plugin and A cart module. This could possibly be done using the logic:

if ( prodict_id = '1' || prodict_id = '2' ) {

use affiliate plugin

}

else {

do not use affiliate plugin
}

or may be a string like prod=1 or prod=2 could be included in the affeliate link.

I will be happy to amend the core files to get it done, but not that good at Hika coding. I am sure a lot of people would like to see this implemented.

Any help will be highly appreciated.

SeoWeb

Last edit: 13 years 1 month ago by seoweb.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 1 month ago #30833

You would need to add your check in the file plugins/system/hikashopaffiliate.php in the onBeforeOrderCreate function.
In the $order variable, you should find the products in either $order->cart->products or $order->products.
so you could do something like that:
foreach($order->cart->products as $product){
if($product->product_id!=YY){
return true; //don't add the affiliate to the order
}
}

Please Log in or Create an account to join the conversation.

  • Posts: 80
  • Thank you received: 1
13 years 1 month ago #30857

Thank you for your prompt reply!
I only want the commission to be calculated for products with IDs 1, 2, and 3.

How could the ready file look like?

Please advice.

Just noticed. The calculations of affiliate comission are not correct. If I sell the product for 5.00 and comission for this is 2.00 system gives 7.00 to the Affiliate. Strange....

Last edit: 13 years 1 month ago by seoweb.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 1 month ago #30907

It would be:
$orderClass = hikashop_get('class.order');
if(empty($order->cart->products)) $order->cart = $orderClass->loadFullOrder($order->order_id);
foreach($order->cart->products as $product){
if(!in_array($product->product_id,array(1,2,3))){
return true;
}
}


For the comission problem, that's already fixed on our end and will be in next version of HikaShop.
It comes from the line:
$order_price = $order->order_full_price;

which should be:
$order_price = 0;

in that same file.

Please Log in or Create an account to join the conversation.

  • Posts: 80
  • Thank you received: 1
13 years 1 month ago #30909

The comission problem is solved with your fix. Thanx for this!

Last edit: 13 years 1 month ago by seoweb.

Please Log in or Create an account to join the conversation.

  • Posts: 80
  • Thank you received: 1
13 years 1 month ago #30920

After a quick test the plugin still adds an Affiliate comission to the product with id=4. May be i put the code in the wrong place?

Now it looks like this:

function onBeforeOrderCreate(&$order,&$do){	
		$app =& JFactory::getApplication();
		if ($app->isAdmin()) return true;
		
		// add affiliate logic to specific products
		$orderClass = hikashop_get('class.order');
		if(empty($order->cart->products)) $order->cart = $orderClass->loadFullOrder($order->order_id);
		foreach($order->cart->products as $product){
		if(!in_array($product->product_id,array(1,2,3))){
		return true;
		}
		}
		// end of  add affiliate logic to specific products

Last edit: 13 years 1 month ago by seoweb.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 1 month ago #30932

You put it at the correct place.
So there must be a problem with that code. You should put traces in it to see where is problem.

Please Log in or Create an account to join the conversation.

  • Posts: 80
  • Thank you received: 1
13 years 4 weeks ago #30963

Hello Nicolas,

Does this look ok?

// add affiliate logic to specific products 
				 $orderClass = hikashop_get('class.order'); 
        	 if(empty($order->cart->products)){
			 $order->cart = $orderClass->loadFullOrder($order->order_id); 
        	 }
		 foreach($order->cart->products as $product){ 
       		 if(!in_array($product->product_id,array(1,2,3))){ 
       		 return true; 
       		 } 
       		 } 
// end of  add affiliate logic to specific products

Last edit: 13 years 4 weeks ago by seoweb.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 4 weeks ago #30964

Hi,

This looks like the code I posted before apart from the fact that you added some brackets which don't change anything.

Does that work for you ?

Please Log in or Create an account to join the conversation.

  • Posts: 80
  • Thank you received: 1
13 years 4 weeks ago #30967

Tested and works well. Was a bit confused with your comment that there is might be something wrong with the code. :-)

Please Log in or Create an account to join the conversation.

  • Posts: 586
  • Thank you received: 23
  • Hikaserial Subscription Hikashop Multisite
1 year 11 months ago #348173

Hi Nicolas,

Does this code still worked with the latest version?
we would also like to indicate a number of products to for which no fee will be paid.
It would also be nice to have some extra code where we can set an minimum order amount.
So you only get a fee when the orders are above some amount.

Kind regards,
Lumiga


Kind regards,
Lumiga

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
1 year 11 months ago #348175

Hi,

It still works but please note that it is some simplified solution.
This code will only add the affiliate fees to a order if all the products of the order are in the list of allowed products. Also, it doesn't handle variants.
A proper solution would handle the variants and calculate the affiliate fees based on the amount of the allowed products in the order and not the total of the order. And that's more complex to do.

Please Log in or Create an account to join the conversation.

Time to create page: 0.094 seconds
Powered by Kunena Forum