Answers.Body: <p>You can use <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildAmount/" rel="nofollow noreferrer">Build Amount</a> hook to alter the price. If you want to trigger the change on form submit than you can use $form->_flagSubmitted. This is set to true when form is submitted. You can also use <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">buildform</a> or <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess/" rel="nofollow noreferrer">post process</a> hook. But validateForm is a bad option.</p>
  
  <pre><code>function xxx_civicrm_buildAmount($pageType, &amp;$form, &amp;$amount) {
    if (get_class($form) == 'CRM_Event_Form_Registration_Register' &amp;&amp; $form-&gt;_flagSubmitted) { 
      foreach ($amount as $key =$value) {
        foreach ($value['options'] as $pid =$value) {
          $amount[$key]['options'][$pid]['amount'] = $value['amount'] - ($value['amount'] * 0.1);
        }
      }
    }
  }
  </code></pre>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T10:50:42.220Z
Answers.Text: Hi Pradeep,
  Interesting, I've now got the code executing in buildAmount as you suggested with the _flagSubmitted = true.
  The $form is being updated but the changes still aren't being transferred to the database.
  Here's the $form record I'm trying to update which worked before.
  $form->_priceSet['fields'][$priceset_id]['options'][$pricefield_id]['amount'] = $amount;
  R
Answers.UserDisplayName: Artiemart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T11:13:11.570Z
Answers.Text: use $amount variable to update the price.(updated ans to add smaple code snippet)
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T12:10:06.350Z
Answers.Text: Thanks  I've put it into place... $amount is correctly updated, but the values still aren't going into the database... zero in civicrm_financial_item.
Answers.UserDisplayName: Artiemart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T12:13:32.923Z
Answers.Text: Can you provide code snippet?
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T12:27:42.887Z
Answers.Text: <code> function hooks_civicrm_buildAmount( $pageType, &$form, &$amount ){
   if($form->_flagSubmitted){
  
      $priceset_fed = $form->_submitValues['priceset_fed'];
      $pricefield_fed = $form->_submitValues['pricefield_fed'];
      $priceset_club = $form->_submitValues['priceset_club'];
      $pricefield_club = $form->_submitValues['pricefield_club'];
      $amount[$priceset_fed]['options'][$pricefield_fed]['amount'] = $form->_submitValues['montant_quotepart_fed'];
     $amount[$priceset_club]['options'][$pricefield_club]['amount'] = $form->_submitValues['montant_quotepart_club'];
     }
  }</code>
Answers.UserDisplayName: Artiemart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T12:30:23.767Z
Answers.Text: Sorry for the layout, I'm having problems with the code tag.
Answers.UserDisplayName: Artiemart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T12:48:21.220Z
Answers.Text: you doing it wrong. You need to have the price option selected in  $form->_submitValues i.e in $form->_params which will be used to calculate total amount. Since you setting this only on main form i feel those values are not available on Confirm. You probably might have to use PostProcess hook as well.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T13:15:17.057Z
Answers.Text: I can confirm that the price options are selected in _submitValues
  price_2618 (String, 4 characters ) 9167
  "use PostProcess hook as well"..? Set which values in PostProcess.
  Thanks for your help...
Answers.UserDisplayName: Artiemart
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T13:22:56.460Z
Answers.Text: I am not sure, you might need to add a condition in buildAmount hook as   if (get_class($form) == 'CRM_Contribute_Form_Contribution_Main' && $form->_flagSubmitted) {
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T10:21:51.577Z
Answers.LastActivityDate: 2018-06-21T11:12:44.347Z
Answers.LastEditDate: 2018-06-21T11:12:44.347Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I'm looking for help on adjusting a priceset amount in a hook at the end of a membership signup.
  Until now under 4.7 for reasons of multi-level priceset complexity I've been adjusting priceset amounts via the hook_civicrm_validateForm by adjusting the values in the $form object. This has been working fine, but this is now longing working in 5.1.2. 
  I realise that strictly speaking I shouldn't modify the $form in the validateForm hook.
  "The hook is intended for validation rather than altering form values."
  However I can't see anywhere else to change the amounts.
  I have two questions, i) Can anyone explain the difference in behaivour between 4.7 and 5.1.2? ii) is there a better place or method to adjust the priceset amount? </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-21T07:27:20.703Z
Comments.Text: Did you ever try the buildAmount hook?
Comments.UserDisplayName: user4278
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-21T07:58:13.217Z
Comments.Text: Hi,
  if I'm not mistaken buildAmount is called even before buildForm. I need to adjust the priceset amount taking into account fields adjusted by the user in the form interface.
  So I need to intervine at the time of submitting the form.
Comments.UserDisplayName: Artiemart
Tags: <price-sets>
Title: Can no longer modifiying priceset amounts in hooks in 5.1.2
ThreadText: # Can no longer modifiying priceset amounts in hooks in 5.1.2
  
  (Asked by: username_0 on 2018-06-21)
  
  I'm looking for help on adjusting a priceset amount in a hook at the end of a membership signup.
  Until now under 4.7 for reasons of multi-level priceset complexity I've been adjusting priceset amounts via the hook\_civicrm\_validateForm by adjusting the values in the $form object. This has been working fine, but this is now longing working in 5.1.2.
  I realise that strictly speaking I shouldn't modify the $form in the validateForm hook.
  "The hook is intended for validation rather than altering form values."
  However I can't see anywhere else to change the amounts.
  I have two questions, i) Can anyone explain the difference in behaivour between 4.7 and 5.1.2? ii) is there a better place or method to adjust the priceset amount?
  
  **Tags:** price-sets
  
  > **Comments:**
  > **username_1**: Did you ever try the buildAmount hook?  
  > **username_0**: Hi, if I'm not mistaken buildAmount is called even before buildForm. I need to adjust the priceset amount taking into account fields adjusted by the user in the form interface. So I need to intervine at the time of submitting the form.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-06-21. Score: 1
  
  You can use Build Amount hook to alter the price. If you want to trigger the change on form submit than you can use $form->_flagSubmitted. This is set to true when form is submitted. You can also use buildform or post process hook. But validateForm is a bad option.
  function xxx_civicrm_buildAmount($pageType, &$form, &$amount) {
    if (get_class($form) == 'CRM_Event_Form_Registration_Register' && $form->_flagSubmitted) { 
      foreach ($amount as $key =$value) {
        foreach ($value['options'] as $pid =$value) {
          $amount[$key]['options'][$pid]['amount'] = $value['amount'] - ($value['amount'] * 0.1);
        }
      }
    }
  }
  
  HTH
  Pradeep
  
  > **Comments:**
  > **username_0**: Hi Pradeep, Interesting, I've now got the code executing in buildAmount as you suggested with the _flagSubmitted = true. The $form is being updated but the changes still aren't being transferred to the database. Here's the $form record I'm trying to update which worked before. $form->_priceSet['fields'][$priceset_id]['options'][$pricefield_id]['amount'] = $amount; R  
  > **username_2**: use $amount variable to update the price.(updated ans to add smaple code snippet)  
  > **username_0**: Thanks  I've put it into place... $amount is correctly updated, but the values still aren't going into the database... zero in civicrm_financial_item.  
  > **username_2**: Can you provide code snippet?  
  > **username_0**: <code> function hooks_civicrm_buildAmount( $pageType, &$form, &$amount ){  if($form->_flagSubmitted){      $priceset_fed = $form->_submitValues['priceset_fed'];     $pricefield_fed = $form->_submitValues['pricefield_fed'];     $priceset_club = $form->_submitValues['priceset_club'];     $pricefield_club = $form->_submitValues['pricefield_club'];     $amount[$priceset_fed]['options'][$pricefield_fed]['amount'] = $form->_submitValues['montant_quotepart_fed'];    $amount[$priceset_club]['options'][$pricefield_club]['amount'] = $form->_submitValues['montant_quotepart_club'];    } }</code>  
  > **username_0**: Sorry for the layout, I'm having problems with the code tag.  
  > **username_2**: you doing it wrong. You need to have the price option selected in  $form->_submitValues i.e in $form->_params which will be used to calculate total amount. Since you setting this only on main form i feel those values are not available on Confirm. You probably might have to use PostProcess hook as well.  
  > **username_0**: I can confirm that the price options are selected in _submitValues price_2618 (String, 4 characters ) 9167 "use PostProcess hook as well"..? Set which values in PostProcess. Thanks for your help...  
  > **username_2**: I am not sure, you might need to add a condition in buildAmount hook as   if (get_class($form) == 'CRM_Contribute_Form_Contribution_Main' && $form->_flagSubmitted) {  
  
  ---
  
  