Summer Cart has all the tools and features to enable online merchants easily build a working store from top to bottom. Whether you sell a dozen of niche specialties, or list hundreds of mass products, you will get high visibility and popularity of your operation through a masterly crafted store.

Integration of Post Affiliate Pro with Summer Cart will require to modify not just footer of your shop (to add click tracking code), but also 2 shopping cart classes. See details of this integration below.

1.

Click integration

Click tracking code should be stored into file skins/<skin_name>/customer/footer.tmpl

If you don't have this file in your skin, just copy it from skeleton directory to your theme directory and add click tracking code, which is prepared for you in Post Affiliate Pro (menu Tools -> Integration -> Click tracking)

Add this code before </body> tag in your footer.html template.

Because Summer cart integration can't use Flash cookies tracking (only browser cookies are used), we will need to disable flash cookie tracking, by adding following line to click tracking code:

PostAffTracker.disableTrackingMethod('F');

It should be stored right after line 

PostAffTracker.setAccountId('default1');

in your click integration code in footer.tmpl file.

2.

Sale Integration

Sale integration will work in 2 steps and integration is done by calling PAP API requests to Post Affiliate Pro directly from php code of your shopping cart.

In first step will be created transaction in Post Affiliate Pro (status Pending) and later, when order will be delivered to your customer, transaction in Post Affiliate Pro will change status to Approved.

3.

Add transaction step

Your shopping cart will create order in time, when is visitor redirected to payment processor (e.g. Paypal). In same time is created transaction in Post Affiliate Pro (status Pending)

Open the shopping cart file: /include/sc/util/order/OrdersInProgress.php

so that we can place there the sale tracking code right at the end of class scOrdersInProgress .

In order to track the entire order as 1 transaction (commission) in Post Affiliate Pro (even if multiple items are purchased during the particular order) use the following code:

private function registerNewPostAffiliateProTransaction($order) {
    include_once('<PATHTOPAP_API>/PapApi.class.php');
    $saleTracker = new Pap_Api_SaleTracker('http://URL_TO_PostAffiliatePro/scripts/sale.php');

    $productIDs = '';
    $items = $order->getOrderItems();
    foreach($items as $item) {
       $productIDs .= $item->get('OrderItemProductCode').',';
    }

    $sale = $saleTracker->createSale();
    $papOrderDetails = $order->getOrderTotalLines();
    $sale->setTotalCost($papOrderDetails[0]->get('OrderTotalLineCustomerCurrencyAmount'));
    $sale->setOrderID($order->getPK());
    $sale->setProductID($productIDs);
 
    $saleTracker->register();
}

If you wish each item purchased during the order to be tracked as a separate transaction (commission) in Post Affiliate Pro, then use the following code:

private function registerNewPostAffiliateProTransaction($order) {
    include_once('<PATH_TO_PAP_API>/PapApi.class.php');
    $saleTracker = new Pap_Api_SaleTracker('http://URL_TO_PostAffiliatePro/scripts/sale.php');
      $items = $order->getOrderItems();
      foreach($items as $item) {
          $sale = $saleTracker->createSale();
          $sale->setTotalCost($item->get('OrderItemTotal'));
          $sale->setOrderID($order->getPK());
          $sale->setProductID($item->get('OrderItemProductCode'));
      }
      $saleTracker->register();
    }

IMPORTANT: this method should be stored before end of class, it means before last } in file /include/sc/util/order/OrdersInProgress.php

IMPORTANT: Don't forget to replace <PATH_TO_PAP_API> with correct path to PapApi.class.php file.

PapApi.class.php file can be downloaded from your Post Affiliate Pro installation in menu Tools-> Integration -> Api Integration

Copy it to your server, where is installed your shop and set the correct path on place of <PATH_TO_PAP_API>.

4.

Add transaction step

Now we should use the method registerNewPostAffiliateProTransaction, which we added in previous step.

Please add following line of code into method createOrder right before last line 

return $this->_lastOrderId;

$this->registerNewPostAffiliateProTransaction($order);

5.

Change status of transaction

Status of existing transactions in Post Affiliate Pro can be controlled by changing of status in your shopping cart. 

Following code will change status of PAP transaction to Approved, if you will set your shopping cart order to status Delivered.

And it will set PAP transaction to status Declined, if you will set your shopping cart order to status Cancelled, Failed Or Returned.

Edit your shopping cart file /include/sc/domainobj/Order.php and at the end of class Order add following method:

    private function updatePostAffiliateProTransaction() {
      try {
  		  include_once('<PATH_TO_PAP_API>/PapApi.class.php');
        $session = new Gpf_Api_Session("http://URL_TO_PostAffiliatePro/scripts/server.php");
        
        if(!$session->login("<MERCHANT_USERNAME>","<MERCHANT_PASSWORD>")) {
          return false;
        } 
        
        
        $request = new Pap_Api_TransactionsGrid($session);
        $request->addFilter("orderid", Gpf_Data_Filter::LIKE, $this->getPK());
        $request->addFilter("rtype", Gpf_Data_Filter::EQUALS, 'S');
        try {
        	$request->sendNow();
        	$grid = $request->getGrid();
        	$recordset = $grid->getRecordset();
        } catch (Exception $e) {
          return false;
        }

        foreach($recordset as $rec) {
          $transaction = new Pap_Api_Transaction($session);
          $transaction->setTransid($rec->get('transid'));
          try {
        	  if(!$transaction->load()) {
        	   return false;
        	  } else {
        	     if ($transaction->getStatus() != 'D') {
                  $newStatus = '';      
                  switch($this->get('OrderStatus')) {
                    case scOrderStatus::ORDER_STATUS_UNFINISHED:
              		  case scOrderStatus::ORDER_STATUS_PAYMENT_PENDING:
              		  case scOrderStatus::ORDER_STATUS_NEW:
              		  case scOrderStatus::ORDER_STATUS_IN_PROGRESS:
              		  case scOrderStatus::ORDER_STATUS_ON_HOLD:
              		  case scOrderStatus::ORDER_STATUS_QUEUED:
              		    $newStatus = 'P';
              		    break;
              		  case scOrderStatus::ORDER_STATUS_RETURNED:
              	    case scOrderStatus::ORDER_STATUS_PAYMENT_FAILED:
              		  case scOrderStatus::ORDER_STATUS_CANCELLED:
              		    $newStatus = 'D';
              		    break;
              		  case scOrderStatus::ORDER_STATUS_DELIVERED:
              		    $newStatus = 'A';
              		    break;
            		  default:
            		    return false;
                  }
                  // changing the status of a transaction
                  if (strlen($newStatus) && $transaction->getStatus() != $newStatus) {
                    $transaction->setStatus($newStatus);
                    $transaction->save();
                  }
               }
        	  }
          } catch (Exception $e) {
            return false;
          }
        }
        } catch (Exception $e) {
          return false;
        }      
        return true;
    }
IMPORTANT: this method should be stored before end of class, it means before last } in file /include/sc/domainobj/Order.php
IMPORTANT: Don't forget to replace <PATH_TO_PAP_API> with correct path to PapApi.class.php file.
PapApi.class.php file can be downloaded from your Post Affiliate Pro installation in menu Tools-> Integration -> Api Integration.
Copy it to your server, where is installed your shop and set the correct path on place of  <PATH_TO_PAP_API>.
IMPORTANT: On place of <MERCHANT_USERNAME> use your merchant username and on place of <MERCHANT_PASSWORD> use your password. API request will use your user credentials to access transactions in your Post Affiliate Pro installation.

6.

Change status of transaction

Now we should use the method, which we added to class Order.

Add the following line of code (found in the box below) into file /include/sc/domainobj/Order.php to  the very end of the   updateOrderStatus and setOrderStatus methods.

$this->updatePostAffiliateProTransaction();

7.

Custom Order Statuses

In case you plan to use custom order statuses in your Summer Cart, you should adapt method updatePostAffiliateProTransaction in your shopping cart file /include/sc/domainobj/Order.php.

in switch function you should add new case statements, where value will be ID of your custom status.