public function QuotePane::prepare in Ubercart 8.4
Prepares a pane for display.
Parameters
\Drupal\uc_order\OrderInterface $order: The order that is being processed.
array $form: The checkout form array.
\Drupal\Core\Form\FormStateInterface $form_state: The checkout form state array.
Overrides CheckoutPanePluginBase::prepare
2 calls to QuotePane::prepare()
- QuotePane::process in shipping/
uc_quote/ src/ Plugin/ Ubercart/ CheckoutPane/ QuotePane.php - Processes a checkout pane.
- QuotePane::view in shipping/
uc_quote/ src/ Plugin/ Ubercart/ CheckoutPane/ QuotePane.php - Returns the contents of a checkout pane.
File
- shipping/
uc_quote/ src/ Plugin/ Ubercart/ CheckoutPane/ QuotePane.php, line 77
Class
- QuotePane
- Shipping quote checkout pane plugin.
Namespace
Drupal\uc_quote\Plugin\Ubercart\CheckoutPaneCode
public function prepare(OrderInterface $order, array $form, FormStateInterface $form_state) {
// If a quote was explicitly selected, add it to the order.
if (isset($form['panes']['quotes']['quotes']['quote_option']['#value']) && isset($form['panes']['quotes']['quotes']['quote_option']['#default_value']) && $form['panes']['quotes']['quotes']['quote_option']['#value'] !== $form['panes']['quotes']['quotes']['quote_option']['#default_value']) {
$quote_option = explode('---', $form_state
->getValue([
'panes',
'quotes',
'quotes',
'quote_option',
]));
$order->quote['method'] = $quote_option[0];
$order->quote['accessorials'] = $quote_option[1];
$order->data->uc_quote_selected = TRUE;
}
// If the current quote was never explicitly selected, discard it and
// use the default.
if (empty($order->data->uc_quote_selected)) {
unset($order->quote);
}
// Ensure that the form builder uses the default value to decide which
// radio button should be selected.
$input = $form_state
->getUserInput();
unset($input['panes']['quotes']['quotes']['quote_option']);
$form_state
->setUserInput($input);
$order->quote_form = uc_quote_build_quote_form($order, !$form_state
->get('quote_requested'));
$default_option = _uc_quote_extract_default_option($order->quote_form);
if ($default_option) {
$order->quote['rate'] = $order->quote_form[$default_option]['rate']['#value'];
$quote_option = explode('---', $default_option);
$order->quote['method'] = $quote_option[0];
$order->quote['accessorials'] = $quote_option[1];
$method = ShippingQuoteMethod::load($quote_option[0]);
$label = $method
->label();
$result = \Drupal::database()
->query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [
':id' => $order
->id(),
':type' => 'shipping',
]);
if ($lid = $result
->fetchField()) {
uc_order_update_line_item($lid, $label, $order->quote['rate']);
}
else {
uc_order_line_item_add($order
->id(), 'shipping', $label, $order->quote['rate']);
}
}
else {
unset($order->quote);
}
}