($this->_priceSetId || !empty($_POST['price_set_id']))
) {
$buildPriceSet = TRUE;
- $getOnlyPriceSetElements = TRUE;
- if (!$this->_priceSetId) {
- $this->_priceSetId = $_POST['price_set_id'];
- $getOnlyPriceSetElements = FALSE;
- }
-
$this->buildPriceSet();
-
- // get only price set form elements.
- if ($getOnlyPriceSetElements) {
+ if (!$this->isSubmitted()) {
+ // This is being called in overload mode to render the price set.
return;
}
}
/**
* Get the price set ID.
*
- * Note that the function currently returns NULL if not submitted
- * but will over time be fixed to always return an ID.
+ * @api Supported for external use.
*
* @return int|null
*/
- protected function getPriceSetID() {
- return $this->getSubmittedValue('price_set_id') ?: CRM_Utils_Request::retrieve('priceSetId', 'Integer');
+ public function getPriceSetID(): ?int {
+ $priceSetID = $this->getSubmittedValue('price_set_id') ?: CRM_Utils_Request::retrieve('priceSetId', 'Integer');
+ // Ideally we would use $this->isFormBuilt() here to know when to access the _POST
+ // array directly. However, the parent sets isBuilt before, building the form,
+ // rather than after.
+ if (!$priceSetID && !empty($this->getSubmitValue('price_set_id'))) {
+ return (int) $this->getSubmitValue('price_set_id');
+ }
+ return $priceSetID ?? NULL;
}
/**
* buildQuickForm.
*/
public function buildForm() {
+ // @todo - move this to the end of the function - then it can be checked
+ // ie $this->isBuilt() to determine whether variables are not yet in getSubmittedValues()
$this->_formBuilt = TRUE;
$this->preProcess();
[$params, $lineItem] = self::getLine($params, $lineItem, $priceSetID, $field, $id);
}
$order = new CRM_Financial_BAO_Order();
- $order->setLineItems($lineItem);
+ $order->setLineItems((array) $lineItem);
$params['amount_level'] = $order->getAmountLevel();
$params['amount'] = $order->getTotalAmount();
$params['tax_amount'] = $order->getTotalTaxAmount();