Created
December 5, 2013 18:45
-
-
Save ksnider/7810941 to your computer and use it in GitHub Desktop.
This script adds up the total of all orders for an Infusionsoft contact and puts it in a custom field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Connect to the Infusionsoft API | |
| require("isdk.php"); | |
| $app = new iSDK; | |
| $app->cfgCon("connectionName"); | |
| // Get the contact ID | |
| $contactID = 19309; | |
| // $contactId = $_POST['Id']; | |
| // Query the Invoice table for all invoices | |
| $returnFields = array('DateCreated','InvoiceTotal'); | |
| $query = array('ContactId' => $contactID); | |
| $invoices = $app->dsQuery("Invoice",10,0,$query,$returnFields); | |
| echo "<pre>"; | |
| print_r($invoices); | |
| echo "</pre>"; | |
| $totalPurchases = 0; | |
| // Loop through the invoices and add the total to the variable $totalPurchases | |
| foreach ($invoices as $value) { | |
| $totalPurchases = $totalPurchases + $value['InvoiceTotal']; | |
| // Shorthand but harder to read | |
| // $totalPurchases += $totalPurchases; | |
| } | |
| echo "$".$totalPurchases . "<br/>"; | |
| // Update contact record with Total Purchases | |
| $data = array('_Purchases' => $totalPurchases); | |
| $update = $app->dsUpdate("Contact", $contactID, $data); | |
| echo $update; | |
| /* ************** | |
| PROJECT _ Once you have run this for all of your customers, modify to increment _Purchases by last purchase using billing automation or campaign trigger | |
| EXTEND - When total purchases = $X, apply a tag to kick off an email with a coupon | |
| ******************* */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment