Zen Cart Logo
Forums / All Other Contributions/Addons / Idev Affiliates code for per-product commissions

Idev Affiliates code for per-product commissions

Views: 1,481

Results 1 to 8 of 8
14 Nov 2014, 7:49 PM
#1
barf avatar

barf

New Zenner

Join Date:
Jan 2012
Posts:
24
Plugin Contributions:
0

Idev Affiliates code for per-product commissions

I'm trying to intergrate our Idev Affiliate software with our Zen Cart. I have it integrated and it works fine for a single preset commission even with multiple tiers.. What we need to do is get the custom coding for "per-product commissions". According to Idev tech support(HA!) it will work but requires some custom coding which Idev states many times now that they don't do! According to the tutorial(HA!) you have to query the data base to send the products purchased along with the sale amount to the Idev tracking pixel in order for it to work. I have very limited experience in database and mysql and have tried every combination I could think of to make it work. Apparently I don't know what I'm doing because it still doesn't work. I had some questions such as what type "identifier" Idev software needs but all tech support(HA!) can tell me is they don't do custom coding and it will work with some custom coding. Seems to me it wouldn't be that hard to put the code in place to make it work from the beginning since it is supposed to be" a snap to integrate with the most popular carts in the world"(HA!). It integrated easily but not all of it!.

Here is a link to their "tutorial"(HA!) http://www.idevlibrary.com/docs/Per_Product_Commissions.pdf

Does anyone use this that could share the code or write the code real quick for me or let me pay you to do it if it works. I really need to get this and I'm about coded out on ideas. We can post and share any ideas because I know I'm not the only one that has this issue!

I attached the file they said to edit.

15 Nov 2014, 5:43 AM
#2
barf avatar

barf

New Zenner

Join Date:
Jan 2012
Posts:
24
Plugin Contributions:
0

Re: Idev Affiliates code for per-product commissions

Guess I'm the only fool in the bunch. Maybe I can hire someone to do the custom coding I need. Coders take a look and PM me a quote please.

15 Nov 2014, 8:42 AM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Idev Affiliates code for per-product commissions

I just updated this FAQ article with code that should work with v1.5.3:
http://www.zen-cart.com/content.php?322-Integrating-Sales-Analytics-and-Affiliates-Tools
This will send the list of products to iDev. It does NOT send individual commission override amounts ... you'll need to configure those per-product in your iDev settings.

To use it, delete the tpl_footer.php file they gave you (it's not compatible with modern PHP versions anyway) and create the file mentioned in the article using the code posted there. (insert your correct iDev URL and profile ID number)

Once you get it working, feel free to donate at: www.zen-cart.com/donate

17 Nov 2014, 12:26 AM
#4
barf avatar

barf

New Zenner

Join Date:
Jan 2012
Posts:
24
Plugin Contributions:
0

Re: Idev Affiliates code for per-product commissions

DrByte, Thanks! Through a little manipulation I'm almost getting the code to work. It seemed to take a combination of new and old code to get it to do so.
Scenario of how it's working now:
Product A pays flat rate of $XXX.XX commission set up on per product commission
Product B and all other products pay Standard commissions with 2 tiers as set up in IDEV (1)=10% - (2)=4% - (3)=1%

If someone buys Prod A it pays flat rate per product commission as set up and tiers pay accordingly also

Now, if someone buys product A and adds product b to the order, the 1st tier only gets the per product flat rate commission from the product A and the two tiers get the regular sales commissions as set up on both products. The first tier doesn't get the commission of product b included.

If 2 different products with a per product commission are in the order then everything works as planned as long as they don't add any products that don't have a per product commission set in IDEV. 1st tier gets both per product commissions and 2nd and 3rd tier gets commission they are supposed too.

If someone buys product b type only, all tiers get the regular set commissions as set up in IDEV.

I wonder why the 1st tier only gets the single commission from product a and doesn't include product b type commission?

I'm including the code page attached to this post. I had to combine both codes. Theirs and yours. Some of it might be over kill but I'm not a coder by any means and don't claim to be. All I know is it almost works like this. I put the code you so kindly pointed me too in with their code the best I knew how. Maybe it needs to have code to tell it if per product commissions are in there then make sure to check for regular products that don't have per product commission and include them also? Just stabbing at ideas!

Did I see somewhere, or better yet is there a plugin that would make it where if someone bought Product A from Product A category then Zencart wouldn't allow any other items to be included in the order with it? I know shipping has one because of Hazmat orders and such. I remember seeing that. That might be what I'm thinking of.

Also as I stated before I can hire a coder, I think, if I need too and can afford it. The site owner has agreed to make a donation when we are finished but I have no idea what would be fare because I'm not familiar with hiring coders or what might be a fair donation for Zencart. I don't want to make a donation and have someone say"that cheap %&*#$#% only donated $$$. LOL

17 Nov 2014, 6:38 AM
#5
barf avatar

barf

New Zenner

Join Date:
Jan 2012
Posts:
24
Plugin Contributions:
0

Re: Idev Affiliates code for per-product commissions

Forgot to do something. Here's the file that sends Idev the data from Zencart.

18 Nov 2014, 3:39 PM
#6
barf avatar

barf

New Zenner

Join Date:
Jan 2012
Posts:
24
Plugin Contributions:
0

Re: Idev Affiliates code for per-product commissions

Anybody have any thoughts on this?

21 Nov 2014, 10:28 AM
#7
barf avatar

barf

New Zenner

Join Date:
Jan 2012
Posts:
24
Plugin Contributions:
0

Re: Idev Affiliates code for per-product commissions

Here's the code that I ended up using. Maybe no one wants to open the file. This is the tail end that does the query and send the call to our idev. This works but you can see up above it's still not quite right. Any input on the matter would be greatly appreciated.

<?PHP }
if ((int)$orders_id > 0) {
  $IDEV = $db->Execute("select class, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '".(int)$orders_id."' AND class in ('ot_coupon', 'ot_subtotal', 'ot_group_pricing')");
  while (!$IDEV->EOF) {
    switch ($IDEV->fields['class']) {
      case 'ot_subtotal':
       $order_subtotal = $IDEV->fields['value'];
        break;
      case 'ot_coupon':
       $coupon_amount = $IDEV->fields['value'];
        break;
      case 'ot_group_pricing':
       $group_pricing_amount = $IDEV->fields['value'];
        break;
    }
    $IDEV->MoveNext();
  }    
  if (!isset($order_summary['products_ordered_models'])) {
  $products_array = array();
  $products_query = "SELECT products_id, products_model
                     FROM " . TABLE_ORDERS_PRODUCTS . "
                     WHERE orders_id = :ordersID
                     ORDER BY products_id";
  $products_query = $db->bindVars($products_query, ':ordersID', $orders_id, 'integer');
  $products = $db->Execute($products_query);
  while (!$products->EOF) {
    $products_array[urlencode($products->fields['products_id'])] = urlencode($products->fields['products_model']);
    $products->MoveNext();
  }
  $idev_sale_amount = ($order_subtotal - $coupon_amount - $group_pricing_amount);
  $idev_sale_amount = number_format($idev_sale_amount,2,'.','');
  
  $idev_coupon_code = mysql_query("select coupon_code from " . TABLE_ORDERS . " where orders_id = '" . (int)$orders_id . "'");
  $idev_coupon_code = mysql_fetch_array($idev_coupon_code);
  $idev_coupon_code = $idev_coupon_code['coupon_code'];
  
  $order_summary['products_ordered_ids'] = implode('|', array_keys($products_array));
  $order_summary['products_ordered_models'] = implode('|', array_values($products_array));

} 

 echo '<script type="text/javascript" src="https://www.mysite.com/idevaffiliate/sale.php?profile=1&idev_saleamt=' . $order_summary['commissionable_order_formatted'] . 
       '&idev_ordernum=' . $order_summary['order_number'] . '&products_purchased=' . $order_summary['products_ordered_models'] . '&coupon_code=' . urlencode($order_summary['coupon_code']) .
       '"></script>';


echo "</td></tr></table>";
}

?>
14 Dec 2014, 2:45 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Idev Affiliates code for per-product commissions

Barf:

Now, if someone buys product A and adds product b to the order, the 1st tier only gets the per product flat rate commission from the product A and the two tiers get the regular sales commissions as set up on both products. The first tier doesn't get the commission of product b included.

If 2 different products with a per product commission are in the order then everything works as planned as long as they don't add any products that don't have a per product commission set in IDEV. 1st tier gets both per product commissions and 2nd and 3rd tier gets commission they are supposed too.

If someone buys product b type only, all tiers get the regular set commissions as set up in IDEV.

I wonder why the 1st tier only gets the single commission from product a and doesn't include product b type commission?
You might first check with iDev to see whether what you're asking is possible.
The code I supplied is passing the product details. What iDev does with that is something you might need to take up with them.