[MOD] Affiliate module (Updated)

Modules, Add-ons and custom code that's more than just a quick hack or Mod.

[MOD] Affiliate module (Updated)

Postby Martin » Thu Sep 26, 2013 6:20 pm

I needed an affiliate module for 6.1.1 so having found this one:
http://cnedelcu.blogspot.co.uk/2010/12/ ... spire.html

... I opted to update it to suit my needs and also bring it up to speed with version 6.1.x

Features over the original:
  • Fixed to work with 6.1.1
  • Bug fix: commission details record correct rates
  • Bug fix: removed max EOL formatting that caused all sorts of problems with the original affiliate.php file!
  • Added: Spread of commission rates based on order value instead of one rate fits all
  • Added: Affiliate access/rewards only available to customer accounts who are members of a specified customer group
  • Updated: Heavily edited the original affiliate pitch to suit my requirements (ie: no pressure sales) and include T&C items
  • Added: Removes commission from affiliate, in full, if the order status is changed to refunded or cancelled
  • Logs affiliate sales to log... There is no admin panel/indicators to show which are affiliate sales (TODO?)


Note: This is not for commercial redistribution or reuse including in ISC rip offs (yes, I'm referring to you cartaddons, Mr_isc, etc...)
It's also NOT supported... Use entirely at your own risk...

The modifications/changes to the original instructions are:

SQL:
Code: Select all
ALTER TABLE `isc_orders` ADD `ordaffiliate` INT( 11 ) NOT NULL DEFAULT '0' COMMENT 'ID of the affiliate who got the sale'

(Replaces the original SQL command by adding a default value)


Open: init.php

At end of file, insert
Code: Select all
require_once(ISC_BASE_PATH . '/lib/affiliate.php');   //MOD Affiliate

(Replaces the code insert originally suggested)


Open: class.checkout.php

Find:
Code: Select all
      $newOrder = array(
         'orderpaymentmodule' => $providerId,
         'ordcurrencyid' => $selectedCurrency['currencyid'],
         'ordcurrencyexchangerate' => $selectedCurrency['currencyexchangerate'],
         'ordipaddress' => getIp(),
         'ordstatus' => $orderStatus,


After, Add:
Code: Select all
         'ordaffiliate' => isset($_COOKIE["ref"]) ? intval($_COOKIE["ref"]) : "0",   //MOD Affiliate



Open: /lib/orders.php

Find:
Code: Select all
      if (OrderIsComplete($status)) {
         $updatedOrder['orddateshipped'] = time();
      }


Replace with:
Code: Select all
   //MOD Affiliate
      if (OrderIsComplete($status)) {
         $updatedOrder['orddateshipped'] = time();
         
         // Give affiliate credit!
         if (!empty($order['ordaffiliate'])) {
            require_once("affiliate.php");
            GiveAffiliateCredit($order);
         }
      }
   //MOD END Affiliate

(Replaces the code insert originally suggested)

Find:
Code: Select all
            // Marked as refunded or cancelled, need to cancel the gift certificates in this order too if there are any
            $updatedCertificates = array(
               "giftcertstatus" => 3
            );
            $GLOBALS['ISC_CLASS_DB']->UpdateQuery("gift_certificates", $updatedCertificates, "giftcertorderid='" . $GLOBALS['ISC_CLASS_DB']->Quote($orderId) . "'");


After, Add:
Code: Select all
            //MOD Affiliate
            // Remove affiliate credit!
            if (!empty($order['ordaffiliate'])) {
               require_once("affiliate.php");
               GiveAffiliateCredit($order, true);   // Cancel the credit
            }
            //MOD END Affiliate





Open: class.account.php

Find:
Code: Select all
               case "reorder": {
                  $this->DoReorder();
                  break;
               }


After, Add:
Code: Select all
               case "affiliate": {
                        DisplayAffiliateAccountPage();
                        $this->MyAccountPage();
                        break;
                    }


Find:
Code: Select all
$GLOBALS['ISC_LANG']['RecentlyViewedItemsDescription'] = sprintf(GetLang('RecentlyViewedItemsDescription'), $GLOBALS['StoreName']);


After add,
Code: Select all
         //MOD Affiliate
         $GLOBALS['AFFILIATE_LINK'] = "<li><a href='account.php?action=affiliate#affiliate' title='Manage my affiliate account'>Affiliate account</a> - Manage your affiliate account and view your sales</li>";
         //MOD END Affiliate



Open: /templates/[theme]/account.html

Find:
Code: Select all
                  <li><a href="%%GLOBAL_ShopPath%%/account.php?action=recent_items">%%LNG_RecentlyViewedItems%%</a> - %%LNG_RecentlyViewedItemsDescription%%</li>
               </ul>


Replace with:
Code: Select all
                  <li><a href="%%GLOBAL_ShopPath%%/account.php?action=recent_items">%%LNG_RecentlyViewedItems%%</a> - %%LNG_RecentlyViewedItemsDescription%%</li>
                  %%GLOBAL_AFFILIATE_LINK%%
               </ul>
               %%GLOBAL_AFFILIATE_LINK%%

(Replaces the code insert originally suggested)
Attachments
affiliate-6.1.1.zip
ISC 6.1.1 affiliate.php update
(4.24 KiB) Downloaded 386 times
Martin
Site Admin
Site Admin
 
Posts: 1855
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK

Re: [MOD] Affiliate module (Updated)

Postby crisbds » Fri Oct 18, 2013 8:21 pm

Is to add the control panel (backend) in the profile of each user which affiliate account is he buying? If so, how? Thank you ... sorry for the english, I'm using google translator uahauhauahua! :mrgreen: :oops:
crisbds
 
Posts: 1
Joined: Fri Oct 18, 2013 8:18 pm
Location: Brasil

Re: [MOD] Affiliate module (Updated)

Postby dannypritchett01 » Tue Nov 28, 2017 12:00 am

Hey Martin,

I hope you are still around. I implemented this module in our store some time ago but have just recently discovered a problem and hope that you know how to fix it.

According to the affiliate page a customer can share a link with: ?ref=123 at the end of a url to get credit for sales.

One of our customers just found out that if they go to http://www.site.com/products.php?product=Product-Name?ref=123 then they get the following error...

Not Found

The page you were looking for appears to have been moved, deleted or does not exist.

This is most likely due to:
•An outdated link on another site
•A typo in the address / URL


Any Idea? How can we fix it so that any url on our store can be used with the ?ref=123 such as pages, products, etc?

Thank You So Much,
Danny
dannypritchett01
 
Posts: 3
Joined: Thu Jan 10, 2013 6:26 pm
Location: USA

Re: [MOD] Affiliate module (Updated)

Postby Martin » Thu Dec 14, 2017 12:39 pm

dannypritchett01 wrote:One of our customers just found out that if they go to http://www.site.com/products.php?product=Product-Name?ref=123 then they get the following error...


You can't have two question characters in a URL... what you need to do is change the second ? to an ampersand...

ie: http://www.site.com/products.php?produc ... me&ref=123

Does that help?
Martin
Site Admin
Site Admin
 
Posts: 1855
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK


Return to [SC] Custom Code

Who is online

Users browsing this forum: No registered users and 1 guest

cron