* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\Api4\Product;
+
/**
* This class generates form components for Premiums.
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
if ($this->_id) {
- $params = ['id' => $this->_id];
- CRM_Contribute_BAO_Product::retrieve($params, $tempDefaults);
+ $tempDefaults = Product::get()->addWhere('id', '=', $this->_id)->execute()->first();
if (isset($tempDefaults['image']) && isset($tempDefaults['thumbnail'])) {
$defaults['imageUrl'] = $tempDefaults['image'];
$defaults['thumbnailUrl'] = $tempDefaults['thumbnail'];
$this->add('textarea', 'options', ts('Options'), ['cols' => 60, 'rows' => 3]);
- $this->add('select', 'period_type', ts('Period Type'), [
- 'rolling' => 'Rolling',
- 'fixed' => 'Fixed',
- ], FALSE, ['placeholder' => TRUE]);
+ $this->add('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), FALSE, ['placeholder' => TRUE]);
$this->add('text', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'fixed_period_start_day'));
$this->_processImages($params);
// Save the premium product to database
- $premium = CRM_Contribute_BAO_Product::create($params);
+ $premium = Product::save()->addRecord($params)->execute()->first();
CRM_Core_Session::setStatus(
- ts("The Premium '%1' has been saved.", [1 => $premium->name]),
+ ts("The Premium '%1' has been saved.", [1 => $premium['name']]),
ts('Saved'), 'success');
}