implement TwingleShop integration

This commit is contained in:
Marc Michalsky 2024-03-21 11:53:57 +01:00 committed by Jens Schuppe
parent ea46e6a747
commit 8cfa270dff
60 changed files with 5200 additions and 106 deletions

View file

@ -251,6 +251,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
// Assign template variables.
$this->assign('op', $this->_op);
$this->assign('twingle_use_shop', (int) Civi::settings()->get('twingle_use_shop'));
$this->assign('profile_name', $profile_name);
$this->assign('is_default', $is_default);
@ -354,6 +355,10 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
static::getPrefixOptions()
);
// Add script and css for Twingle Shop integration
Civi::resources()->addScriptUrl(E::url('js/twingle_shop.js'));
Civi::resources()->addStyleFile(E::LONG_NAME, 'css/twingle_shop.css');
$payment_instruments = CRM_Twingle_Profile::paymentInstruments();
$this->assign('payment_instruments', $payment_instruments);
foreach ($payment_instruments as $pi_name => $pi_label) {
@ -523,6 +528,42 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
['class' => 'crm-select2 huge', 'multiple' => 'multiple']
);
if (Civi::settings()->get('twingle_use_shop')) {
$this->add(
'checkbox', // field type
'enable_shop_integration', // field name
E::ts('Enable Shop Integration'), // field label
FALSE,
[]
);
$this->add(
'select', // field type
'shop_financial_type', // field name
E::ts('Default Financial Type'), // field label
static::getFinancialTypes(), // list of options
TRUE,
['class' => 'crm-select2 huge']
);
$this->add(
'select', // field type
'shop_donation_financial_type', // field name
E::ts('Financial Type for top up donations'), // field label
static::getFinancialTypes(), // list of options
TRUE,
['class' => 'crm-select2 huge']
);
$this->add(
'checkbox', // field type
'shop_map_products', // field name
E::ts('Map Products as Price Fields'), // field label
FALSE, // is not required
[]
);
}
$this->addButtons([
[
'type' => 'submit',
@ -566,9 +607,6 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
CRM_Core_Session::setStatus($e->getMessage(), E::ts('Warning'));
}
}
catch (ProfileValidationError $e) {
$this->setElementError($e->getAffectedFieldName(), $e->getMessage());
}
}
return parent::validate();
@ -993,5 +1031,4 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
}
return static::$_campaigns;
}
}

View file

@ -29,14 +29,16 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
* List of all settings options.
*/
public static $SETTINGS_LIST = [
'twingle_prefix',
'twingle_use_sepa',
'twingle_dont_use_reference',
'twingle_protect_recurring',
'twingle_protect_recurring_activity_type',
'twingle_protect_recurring_activity_subject',
'twingle_protect_recurring_activity_status',
'twingle_protect_recurring_activity_assignee',
'twingle_prefix',
'twingle_use_sepa',
'twingle_dont_use_reference',
'twingle_protect_recurring',
'twingle_protect_recurring_activity_type',
'twingle_protect_recurring_activity_subject',
'twingle_protect_recurring_activity_status',
'twingle_protect_recurring_activity_assignee',
'twingle_use_shop',
'twingle_access_key',
];
/**
@ -105,13 +107,25 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
]
);
$this->addButtons([
[
'type' => 'submit',
'name' => E::ts('Save'),
'isDefault' => TRUE,
],
]);
$this->add(
'checkbox',
'twingle_use_shop',
E::ts("Use Twingle Shop Integration")
);
$this->add(
'text',
'twingle_access_key',
E::ts("Twingle Access Key")
);
$this->addButtons(array(
array (
'type' => 'submit',
'name' => E::ts('Save'),
'isDefault' => TRUE,
)
));
// set defaults
foreach (self::$SETTINGS_LIST as $setting) {
@ -124,8 +138,7 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
}
/**
* Custom form validation, because the activity creation fields
* are only mandatory if activity creation is active
* Custom form validation, as some fields are mandatory only when others are active.
* @return bool
*/
public function validate() {
@ -146,6 +159,14 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form {
}
}
// Twingle Access Key is required if Shop Integration is enabled
if (
CRM_Utils_Array::value('twingle_use_shop', $this->_submitValues) &&
!CRM_Utils_Array::value('twingle_access_key', $this->_submitValues, FALSE)
) {
$this->_errors['twingle_access_key'] = E::ts("An Access Key is required to enable Twingle Shop Integration");
}
return (0 == count($this->_errors));
}