Groups filter hack for smaller groups listings
[civicrm-core.git] / CRM / Contribute / Form / ManagePremiums.php
index 45904ea49f2d114aa79026729bac73fb019aa9d8..0514965c6d7c3f83cdf52dc8b3c9ebff8ddca975 100644 (file)
@@ -15,6 +15,8 @@
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
+use Civi\Api4\Product;
+
 /**
  * This class generates form components for Premiums.
  */
@@ -35,8 +37,7 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
   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'];
@@ -115,10 +116,7 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
     $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'));
 
@@ -291,10 +289,10 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
     $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');
   }