Post by gamersoutlet » Sat Jul 19, 2014 8:07 pm

Hi guys,
I'm running a web shop which includes an affiliate program.
I changed the total calculation so that the affiliates will only get payed for the product price. An exception for this was discounts, which were included into the calculation if existed. So affiliate calculation is always 'Product price - Discount'.

Now I've introduced payment fees into my system as well. Currently, my affiliates get a commission from the price including the payment fee, which kinda destroys its purpose. Would appreciate if someone can help me change the calculation so it wont include that.

Here is the sample of my code:

Code: Select all

			if (isset($this->request->cookie['tracking'])) {
				$this->load->model('affiliate/affiliate');
				
				$affiliate_info = $this->model_affiliate_affiliate->getAffiliateByCode($this->request->cookie['tracking']);
				$subtotal = $this->cart->getSubTotal();
				
				if ($affiliate_info) {
					$data['affiliate_id'] = $affiliate_info['affiliate_id']; 
					// $data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
					$aff_total = $total;
					foreach($taxes as $_v) {
					  $aff_total -= $_v;
					}
					$data['commission'] = ($aff_total / 100) * $affiliate_info['commission']; 
				} else {
					$data['affiliate_id'] = 0;
					$data['commission'] = 0;
				}
			} else {
				$data['affiliate_id'] = 0;
				$data['commission'] = 0;
			}
Last edited by gamersoutlet on Sun Jul 20, 2014 3:46 pm, edited 1 time in total.

New member

Posts

Joined
Thu Dec 12, 2013 3:12 pm

Post by ocmta » Sun Jul 20, 2014 12:03 am

What exactly is "payment fee"? If it's some order total, you can do like this, above $data['commission'] = ... :

Code: Select all

foreach($total_data as $_v) {
  if($_v['code'] == 'payment_fee') { //replace payment_fee with that total's code
    $aff_total -= $_v['value'];
  }
}

Extensions for affiliates (openCart 1, 2, 3):
Advanced Multi Level Affiliate System
Customer and Affiliate Accounts Combined into one Account
Affiliate Tracking with Coupons
Discount for Referred Customers - Order Total
Type Tracking Code
Mass Pay
Affiliate Transactions for openCart 3
Affiliate Pack X - all modules with 40% discount


Active Member

Posts

Joined
Mon Mar 12, 2012 11:21 am


Post by gamersoutlet » Sun Jul 20, 2014 3:46 pm

payment fee is an extension I use to add the paypal fee to my order.
Either way, I managed to solve this mathematically instead of code wise:

Code: Select all

				if ($affiliate_info) {
					$data['affiliate_id'] = $affiliate_info['affiliate_id']; 
					// $data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
					$aff_total = $total;
					foreach($taxes as $_v) {
					  $aff_total -= $_v;
					}
					$payment_fee = $aff_total - $subtotal;
					  $aff_total -= $payment_fee;
					
					$data['commission'] = ($aff_total / 100) * $affiliate_info['commission']; 
				} else {
					$data['affiliate_id'] = 0;
					$data['commission'] = 0;
				}
			} else {
				$data['affiliate_id'] = 0;
				$data['commission'] = 0;
			}

New member

Posts

Joined
Thu Dec 12, 2013 3:12 pm
Who is online

Users browsing this forum: No registered users and 2 guests