Last active
June 28, 2017 21:49
-
-
Save enminc/cfc1f1c924d0a73b214c9031387f0a18 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$feeds = array( | |
array('transaction_id' => 123,'customer' => array('...customer data...'),'details' => array('...line items...')), | |
array('transaction_id' => 456,'customer' => array('...customer data...'),'details' => array('...line items...')) | |
); | |
foreach($feeds as $transaction) { | |
$detailTrans = array(); | |
foreach ($transaction['details'] as $k => $detail) { | |
$new_detail = $modx->newObject('FCartTransactionDetails'); | |
$new_detail->fromArray($detail); | |
$detailTrans[] = $new_detail; | |
} | |
$customerTrans = $modx->newObject('FCartTransactionCustomer'); | |
$customerTrans->fromArray($transaction['customer']); | |
$newTransRecord = $modx->newObject('FCartTransactions'); | |
$newTransRecord->fromArray($transaction); | |
$newTransRecord->addOne($customerTrans); | |
$newTransRecord->addMany($detailTrans); | |
$recordSaved = $newTransRecord->save(); | |
} | |
// Results | |
//FCartTransactions = 2 records | |
//FCartTransactionCustomer = 2 records | |
## FCartTransactionDetails = 3 records | |
#1 82329803 2013-06-12 06:57:49 GB Logo Shirt 16.00 1 0.510 | |
#2 82379757 2013-06-12 06:57:49 GB Logo Shirt 16.00 1 0.510 | |
#3 82379757 2013-06-12 09:25:10 GB Logo Shirt 16.00 1 1.000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment