}
$optionsIds = array();
$maxIndex = CRM_Price_Form_Field::NUM_OPTION;
- $priceField2 = civicrm_api3('price_field', 'getsingle', array('id' => $priceField->id));
- if ($priceField2['html_type'] == 'Text') {
+ if ($priceField->html_type == 'Text') {
$maxIndex = 1;
$fieldOptions = civicrm_api3('price_field_value', 'get', array(
'price_field_id' => $priceField->id,
));
foreach ($fieldOptions['values'] as $option) {
$optionsIds['id'] = $option['id'];
+ // CRM-19741 If we are dealing with price fields that are Text only set the field value label to match
+ if (!empty($params['id']) && $priceField->label != $option['label']) {
+ $fieldValue = new CRM_Price_DAO_PriceFieldValue();
+ $fieldValue->label = $priceField->label;
+ $fieldValue->id = $option['id'];
+ $fieldValue->save();
+ }
}
}
$defaultArray = array();
throw new CRM_Core_Exception($e->getMessage());
}
}
- elseif (!empty($optionIds)) {
- $optionsLoad = civicrm_api3('price_field_value', 'get', array('id' => $optionIds['id']));
- $options = $optionsLoad['values'][$option['id']];
+ elseif (!empty($optionsIds)) {
+ $optionsLoad = civicrm_api3('price_field_value', 'get', array('id' => $optionsIds['id']));
+ $options = $optionsLoad['values'][$optionsIds['id']];
$options['is_active'] = CRM_Utils_Array::value('is_active', $params, 1);
try {
- CRM_Price_BAO_PriceFieldValue::create($options, $optionIds);
+ CRM_Price_BAO_PriceFieldValue::create($options, $optionsIds);
}
catch (Exception $e) {
$transaction->rollback();
$this->assertEquals(1, $result['values']['options_per_line']['type']);
}
+ /**
+ * CRM-19741
+ * Test updating the label of a texte price field and ensure price field value label is also updated
+ */
+ public function testUpdatePriceFieldLabel() {
+ $field = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ $this->callAPISuccess('price_field_value', 'create', array(
+ 'price_field_id' => $field['id'],
+ 'name' => 'rye grass',
+ 'label' => 'juicy and healthy',
+ 'amount' => 1,
+ 'financial_type_id' => 1,
+ ));
+ $priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety'));
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id']));
+ $this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']);
+ $this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id']));
+ $this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id']));
+ }
+
+ /**
+ * CRM-19741
+ * Confirm value label only updates if fiedl type is html.
+ */
+ public function testUpdatePriceFieldLabelNotUpdateField() {
+ $field = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, array('html_type' => 'Radio')));
+ $this->callAPISuccess('price_field_value', 'create', array(
+ 'price_field_id' => $field['id'],
+ 'name' => 'rye grass',
+ 'label' => 'juicy and healthy',
+ 'amount' => 1,
+ 'financial_type_id' => 1,
+ ));
+ $priceField = $this->callAPISuccess($this->_entity, 'create', array('id' => $field['id'], 'label' => 'Rose Variety'));
+ $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', array('price_field_id' => $field['id']));
+ $this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']);
+ $this->callAPISuccess('price_field_value', 'delete', array('id' => $priceFieldValue['id']));
+ $this->callAPISuccess($this->_entity, 'delete', array('id' => $field['id']));
+ }
+
}