|
8 | 8 | /** |
9 | 9 | * Implements hook_civicrm_copy(). |
10 | 10 | */ |
11 | | -function percentagepricesetfield_civicrm_copy($objectName, &$object) { |
| 11 | +function percentagepricesetfield_civicrm_copy($objectName, &$object, $original_id = NULL) { |
12 | 12 | if (strtolower($objectName) == 'set') { |
13 | | - // Get the price set that this one was copied from, basd on the convention |
14 | | - // that copied price sets always have '__Copy_id_[N]_' or '_Copy_id_[N]_' appended |
15 | | - // to their name, where [N] is an integer. |
16 | | - // Notes: |
17 | | - // - [N] is often, but not always, the ID of the new price set, because N is |
18 | | - // calculated using max(id)+1, and max(id) is not always equivalent to the |
19 | | - // next serial ID.) |
20 | | - // - Note the difference between leading "__" and leading "_" in the appended |
21 | | - // strings. This seems to vary by CiviCRM version, older versions using two |
22 | | - // underscores, and newer versions using only one. |
23 | | - $original_price_set_name = preg_replace('/_+Copy_id_[0-9]+_$/', '', $object->name); |
24 | | - $params = array( |
25 | | - 'name' => $original_price_set_name, |
26 | | - ); |
27 | | - CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceSet', $params, $source_price_set); |
| 13 | + if (!$original_id) { |
| 14 | + // If we don't know the original price set id, we cannot copy the |
| 15 | + // Percentage Price Fields configurations. Therefore, alert the user and |
| 16 | + // skip any further action. |
| 17 | + CRM_Core_Session::setStatus(E::ts('If the new Price Set contains any Percentage Price Set Fields, they were not fully configured. Please double-check the configuration of any such fields in the new Price Set.'), 'Caution.', 'error'); |
| 18 | + return; |
| 19 | + } |
| 20 | + |
28 | 21 | // Get all percentage fields in the source prices set: |
29 | | - $source_percentage_field_ids = _percentagepricesetfield_get_percentage_field_ids($source_price_set['id'], FALSE); |
| 22 | + $source_percentage_field_ids = _percentagepricesetfield_get_percentage_field_ids($original_id, FALSE); |
30 | 23 | foreach ($source_percentage_field_ids as $field_id) { |
31 | 24 | // Get the percentage price field values for this field. |
32 | 25 | $source_percentage_values = _percentagepricesetfield_get_settings($field_id, FALSE); |
|
0 commit comments