Advise regarding the Affiliate statistics needed

  • Posts: 80
  • Thank you received: 1
12 years 10 months ago #41522

Hello,

At the moment I am working on some changes to Affiliate statistics. Say, I have some products in my store The first one cost 39.99 and is eligible to the Affiliate program.

This logic might be used in a file components/com_hikashop/views/affiliate/tmpl/sales.php to show how much money the reseller is going to get based on a order_full_price looks like this:

if ($row->order_full_price == 39.9900){
echo '£20.00';
}
elseif ($row->order_full_price == 79.9800){
echo '£40.00';
}

The second one cost 24.99 and is also eligible to the Affiliate program. For this one this logic will work:
elseif($row->order_full_price == 24.9900){
echo '£10.00';
}
elseif($row->order_full_price == 49.9800){
echo '£20.00';
}
else
echo 'No rule for this!';

and so on...

As you understand the major problem here is if the product price will change or there will be another product within the order which will make the order_full_price different from predefined ones, all the calculations will be wrong.

So... I am looking to make calculations based on product_id + order_product_quantity + order_product_price (which are stored in different tables _hikashop_order_product and _hikashop_order) and ideally the discount value to be deducted from predefined payout figure (20.00 or 40.00 as shown in the first example) if the reseller gave the discount code to the customer and is happy to get the discount code value deducted form his profit.

Please advise how can I accomplish the task.

Last edit: 12 years 10 months ago by seoweb.

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

  • Posts: 83103
  • Thank you received: 13418
  • MODERATOR
12 years 10 months ago #41676

Hi,

Do like that:

$orderClass = hikashop_get('class.order');
$allOrderInfo = $orderClass->loadFullOrder($row->order_id);
Then, you can loop through the products of the order like that:
foreach($allOrderInfo->products as $product){
  //my calculations code
}

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

  • Posts: 80
  • Thank you received: 1
12 years 10 months ago #42819

Hello,


I am getting an error:

Warning: Invalid argument supplied for foreach() in /home/didamobi/public_html/templates/didamobile/html/com_hikashop/affiliate/sales.php on line 182
N/A 

should be something wrong here:
foreach($allOrderInfo->products as $product){

Please advise

Last edit: 12 years 10 months ago by seoweb.

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

  • Posts: 83103
  • Thank you received: 13418
  • MODERATOR
12 years 10 months ago #42837

If you get that error, it means that the system could not load the order information.

I think that it's because you're not the owner of the order. In that case, you need to change the code:
$allOrderInfo = $orderClass->loadFullOrder($row->order_id);

to:
$allOrderInfo = $orderClass->loadFullOrder($row->order_id,false, false);

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

  • Posts: 80
  • Thank you received: 1
12 years 10 months ago #42861

No, still no luck.

At the moment I use this code:

$orderClass = hikashop_get('class.order');
                        $allOrderInfo = $orderClass->loadFullOrder($row->order_id);

                        $affil_array = array(
                                    25 => 20, // for product with id 25 there is £20 payout
                                    39 => 20,
                                    40 => 20,
				    45 => 20
                        );

                        $affil_total = 0;
                        
                            foreach($this->order->products as $product){
                            if (array_key_exists($product->order_product_id, $affil_array)) {
                                $affil_total+= ($affil_array[$product->order_product_id]*$product->order_product_quantity);
                            }
                               
                        }

                        echo ($affil_total>0)?'£'.number_format($affil_total, 2, '.', ''):'N/A'; 

Any more ideas?

Thanx

Last edit: 12 years 10 months ago by seoweb.

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

  • Posts: 83103
  • Thank you received: 13418
  • MODERATOR
12 years 10 months ago #42908

Your code doesn't use the modification of my previous message and the variable of the foreach is different from what I said in my first message. Finally, it should be product_id and not order_product_id that you use in your code. Thus, it should be:

$orderClass = hikashop_get('class.order');
                        $allOrderInfo = $orderClass->loadFullOrder($row->order_id,false, false);
 
                        $affil_array = array(
                                    25 => 20, // for product with id 25 there is £20 payout
                                    39 => 20,
                                    40 => 20,
				    45 => 20
                        );
 
                        $affil_total = 0;
 
                            foreach($allOrderInfo->products as $product){
                            if (array_key_exists($product->product_id, $affil_array)) {
                                $affil_total+= ($affil_array[$product->product_id]*$product->order_product_quantity);
                            }
 
                        }
 
                        echo ($affil_total>0)?'£'.number_format($affil_total, 2, '.', ''):'N/A'; 

The following user(s) said Thank You: seoweb

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

  • Posts: 80
  • Thank you received: 1
12 years 9 months ago #45124

Thanx Nikolas,

Could you, please, advice on how to implement the same for the back end view of Affiliates -> Partners where the TOTAL_UNPAID_AMOUNT are shown?

Regards,
SeoWeb

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

  • Posts: 83103
  • Thank you received: 13418
  • MODERATOR
12 years 9 months ago #45314

For the total unpaid amount of that listing, it's the file "listing" of the view "user" that you should edit in a similar manner.

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

Time to create page: 0.071 seconds
Powered by Kunena Forum