Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #103 from mjwconsult/importpriceFieldID
Browse files Browse the repository at this point in the history
Allow to define a specific priceFieldID on import
  • Loading branch information
artfulrobot authored Jan 7, 2021
2 parents 95068ed + 590ea7d commit 799fc12
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cli/import-from-gc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
// What financial type do you want to use?
define('GC_IMPORT_FINANCIAL_TYPE_NAME', 'Donation (regular)');

// What price field do you want to use? Make sure the id exists!
define('GC_IMPORT_PRICE_FIELD_ID', 1);

// You can set a date here, or use NULL
// define('GC_IMPORT_SINCE', '2019-05-01T00:00:00Z');
define('GC_IMPORT_SINCE', NULL);
Expand All @@ -64,6 +67,9 @@ class GCImport
/** @var int financial type. */
public $financialTypeID;

/** @var int Price Field */
public $priceFieldID;

/** @var null|string date. */
public $importSince;

Expand Down Expand Up @@ -124,7 +130,7 @@ class GCImport
* @param String $financialTypeName
* @param null|String $importSince (date)
*/
public function __construct($financialTypeName, $importSince = NULL, $confirmCreateRecur=TRUE, $logDir=NULL) {
public function __construct($financialTypeName, $priceFieldID, $importSince = NULL, $confirmCreateRecur=TRUE, $logDir=NULL) {
civicrm_initialize();

if ($logDir !== NULL) {
Expand All @@ -145,6 +151,8 @@ public function __construct($financialTypeName, $importSince = NULL, $confirmCre
throw new InvalidArgumentException("Failed to find financial type '$financialTypeName'");
}

$this->priceFieldID = $priceFieldID;

$this->confirmCreateRecur = (bool) $confirmCreateRecur;

if ($importSince) {
Expand Down Expand Up @@ -328,7 +336,7 @@ public function getPaymentsToImport($subscription) {
'financial_type_id' => $this->financialTypeID,
'line_total' => $payment->amount / 100,
'unit_price' => $payment->amount / 100,
"price_field_id" => 1,
'price_field_id' => $this->priceFieldID,
'qty' => 1,
]]
]
Expand Down Expand Up @@ -488,7 +496,7 @@ public function createInitialPendingContrib($subscription, $contactID, $contribR
'line_item' => [[
'line_total' => $subscription->amount / 100,
'unit_price' => $subscription->amount / 100,
"price_field_id" => 1,
'price_field_id' => $this->priceFieldID,
'financial_type_id' => $this->financialTypeID,
'qty' => 1,
]]
Expand Down Expand Up @@ -622,6 +630,7 @@ public function saveAffectedSummary() {
try {
$importer = new GCImport(
GC_IMPORT_FINANCIAL_TYPE_NAME,
GC_IMPORT_PRICE_FIELD_ID,
GC_IMPORT_SINCE,
GC_CONFIRM_BEFORE_CREATING_RECUR,
GC_PRIVATE_OUTPUT_DIR
Expand Down

0 comments on commit 799fc12

Please sign in to comment.