Home Integration Methods Interspire Shopping Cart (especially for Google Checkout)

Interspire Shopping Cart (especially for Google Checkout)

This integration method will help you to integrate Post Affiliate Pro 4 with Interspire Shopping Cart 6.0+ in case when customers are not returned on the Interspire thank you page after payment with Google Checkout.
1
What is this script for?
This setup was created to track products ordered in Interspire Shopping Cart and paid with Google Checkout. What this script does is that it posts each different product ordered as a separate sale to PAP4 or whole cart as a one sale. For sale tracking PAP API tracking is used.
2
Adding visitorId field into ProductAddToCart template

Edit file /templates/__master/Snippets/ProductAddToCart.html
(if you have changed it in own template it is in directory: /templates/[used template]/Snippets/)

Add this row into form (after row <input type="hidden" name="currency_id" value="" />):

<input value="" name="product-private-data" type="hidden" id="pap_dx8vc2s5">


and after end of form tag "</form>"
add:
<script id="pap_x2s6df8d" src="http://www.yoursite.com/affiliate/scripts/notifysale.php" type="text/javascript">
</script>


Code below shows whole ProductAddToCart.html file after changes:

3
Adding visitorId param into Add To Cart links
Edit all template files where is used add to cart link. Add attribute id="affCookieLinkId" into tag <a> in <div class="ProductActionAdd">

And into click tracking code add (after line PostAffTracker.track()):
PostAffTracker.writeCookieToLink('affCookieLinkId', 'product-private-data');

Code below shows tag <div class="ProductActionAdd"> after changes:
List of files, which you need to edit in directory /templates/__master/Snippets/

BrandProductsItem.html
CategoryProductsItem.html
HomeFeaturedProductsItem.html
HomeNewProductsItem.html
HomeSaleProductsItem.html
ProductVendorsOtherProductsItem.html
SearchResultProductGrid.html
SideCategoryNewProducts.html
SideCategoryPopularProducts.html
SideCategoryTopSellers.html
SideNewProducts.html
SideRecentlyViewedProducts.html
SideTopSellers.html
SideTopSellersFirst.html
TagProductsItem.html
VendorFeaturedItemsItem.html
VendorProductsItem.html
4
Edit file class.cart.api.php

Edit file /includes/classes/class.cart.api.php

Find line public function AddItem( line number 1164 and add in the end of parameters new parameter $productPrivateData=null

It will look like:
public function AddItem($productId, $quantity=1, $variationDetails=null, $configurableOptions=array(), $cartItemId=null, $options=array(), $parentId=null, $reorder=false, $productPrivateData=null)

Next find cartProduct array (line 1319):
        $cartProduct = array(
            'product_id' => $productId,
            'variation_id' => $variation,
            'options' => $variationOptions,
            'quantity' => $quantity,
            'product_name' => $product['prodname'],
            'product_code' => $productCode,
            'product_price' => $productPrice,
            'original_price' => $originalPrice,
            'default_currency' => $defaultCurrency['currencyid'],
            'customer_group' => $customerGroup,
        );


add there 'product_private_data' => $productPrivateData

it will look like:
        $cartProduct = array(
            'product_id' => $productId,
            'variation_id' => $variation,
            'options' => $variationOptions,
            'quantity' => $quantity,
            'product_name' => $product['prodname'],
            'product_code' => $productCode,
            'product_price' => $productPrice,
            'original_price' => $originalPrice,
            'default_currency' => $defaultCurrency['currencyid'],
            'customer_group' => $customerGroup,
            'product_private_data' => $productPrivateData
        );

5
Edit file class.cart.php

Edit file /includes/classes/class.cart.php

Find line:
$cartItemId = $this->api->AddItem($product_id, $qty, $variation, $configurableFields, null, $options, null, false);

change it like:
$cartItemId = $this->api->AddItem($product_id, $qty, $variation, $configurableFields, null, $options, null, false, $productPrivateData);

And add this before it:
            $productPrivateData = '';
            if(isset($_REQUEST['product-private-data'])) {
                $productPrivateData = $_REQUEST['product-private-data'];
            }


It will look after changes:
6
Add sale tracking code into file class.handler.php in googlecheckout method
Edit file /modules/checkout/googlecheckout/class.handler.php

Find this code around line 925:
if (!$completed) {
            $GLOBALS['ISC_CLASS_LOG']->LogSystemError($this->logtype, sprintf(GetLang('GoogleCheckoutCantCompleteOrder'), isc_html_escape($pendingToken), isc_html_escape(var_export($completed, true))));
            return;
        }


add next code right after:

  foreach($cartContent[$vendorId][0] as $cartItemId => $product) {
    $productid = $product['data']['productid'];
    $productPrivateData = $product['product_private_data'];
  }

  if (strlen($productPrivateData) == 40) { 
      $accountId = substr($productPrivateData, 0, 8); 
      $visitorId = substr($productPrivateData, 8, 32);
  } else { 
      $visitorId = $productPrivateData;
      $accountId = 'default1';
  }
  //PAP api tracking code
  include 'PapApi.class.php';
  $saleTracker = new Pap_Api_SaleTracker('http://
www.yoursite.com/affiliate/scripts/sale.php');
  $saleTracker->setAccountId($accountId);
  $saleTracker->setCookieValue($visitorId);
  $sale1 = $saleTracker->createSale();
  $sale1->setTotalCost($vendorInfo['itemTotal']);
  $sale1->setOrderID($order['orderid']);
  $sale1->setProductID($productid);
  $saleTracker->register();
  //End PAP api tracking code


Below, you can see an example of how it will look like, if you want to create a transaction for each product:
This tracking method is using PAP API. Therefore you need to have your actual PapApi.class.php file in directory /modules/checkout/googlecheckout/
(You can download it from your merchant panel > start > tools > integration > api integration > Download PAP API).