protected function Cart::getAddItemRedirect in Ubercart 8.4
Computes the destination Url for an add-to-cart action.
Redirect Url is chosen in the following order:
- Query parameter "destination"
- Cart config variable "uc_cart.settings.add_item_redirect"
Return value
\Drupal\Core\Url A Url destination for redirection.
1 call to Cart::getAddItemRedirect()
- Cart::addItem in uc_cart/
src/ Cart.php - Adds an item to the cart.
File
- uc_cart/
src/ Cart.php, line 154
Class
- Cart
- Utility class providing methods for the management of shopping carts.
Namespace
Drupal\uc_cartCode
protected function getAddItemRedirect() {
// Check for 'destination=' query string.
$query = \Drupal::request()->query;
$destination = $query
->get('destination');
if (!empty($destination)) {
return Url::fromUri('base:' . $destination);
}
// Save current Url to session before redirecting
// so we can go "back" here from the cart.
$session = \Drupal::service('session');
$session
->set('uc_cart_last_url', Url::fromRoute('<current>')
->toString());
$redirect = \Drupal::config('uc_cart.settings')
->get('add_item_redirect');
if ($redirect != '<none>') {
return Url::fromUri('base:' . $redirect);
}
else {
return Url::fromRoute('<current>', [], [
'query' => UrlHelper::filterQueryParameters($query
->all()),
]);
}
}