function uc_cart_pane_quotes in Ubercart 8.4
Same name and namespace in other branches
- 5 shipping/uc_quote/uc_quote.module \uc_cart_pane_quotes()
- 6.2 shipping/uc_quote/uc_quote.module \uc_cart_pane_quotes()
- 7.3 shipping/uc_quote/uc_quote.module \uc_cart_pane_quotes()
Cart pane callback.
See also
1 string reference to 'uc_cart_pane_quotes'
- uc_quote_uc_cart_pane in shipping/
uc_quote/ uc_quote.module - Implements hook_uc_cart_pane().
File
- shipping/
uc_quote/ uc_quote.module, line 384 - The controller module for fulfillment modules that process physical goods.
Code
function uc_cart_pane_quotes($form, FormStateInterface $form_state, $items) {
$order = Order::create([
'uid' => \Drupal::currentUser()
->id(),
]);
$order->delivery_country = $form_state
->getValue('delivery_country') ?: uc_store_default_country();
$order->delivery_zone = $form_state
->getValue('delivery_zone') ?: '';
$order->delivery_postal_code = $form_state
->getValue('delivery_postal_code') ?: '';
$order->products = $items;
$form['#attached']['library'][] = 'uc_quote/uc_quote.styles';
$form['address'] = [
'#type' => 'uc_address',
'#default_value' => [
'delivery_country' => $order->delivery_country,
'delivery_zone' => $order->delivery_zone,
'delivery_postal_code' => $order->delivery_postal_code,
],
'#required' => TRUE,
'#key_prefix' => 'delivery',
];
$form['get_quote'] = [
'#type' => 'button',
'#value' => t('Calculate'),
'#ajax' => [
'callback' => 'uc_quote_cart_returned_rates',
'wrapper' => 'quote',
],
];
\Drupal::moduleHandler()
->loadInclude('uc_quote', 'inc', 'uc_quote.pages');
$quotes = uc_quote_assemble_quotes($order);
$quote_options = [];
if (!empty($quotes)) {
foreach ($quotes as $method => $data) {
foreach ($data as $accessorial => $quote) {
$key = $method . '---' . $accessorial;
if (isset($quote['rate'])) {
$quote_options[$key] = t('@label: @price', [
'@label' => $quote['option_label'],
'@price' => $quote['format'],
]);
}
}
}
}
$form['quote'] = [
'#theme' => 'item_list',
'#items' => $quote_options,
'#prefix' => '<div id="quote">',
'#suffix' => '</div>',
];
return $form;
}