Home > widget-integration > CartService > redirectToCartPage

CartService.redirectToCartPage() method

Redirect to cart page with proper locale handling Override for custom redirect logic or additional behavior

Common customization scenarios: - Add query parameters to cart URL - Redirect to custom checkout page - Add analytics tracking before redirect - Show loading indicator during redirect

Signature:

protected redirectToCartPage(): void;

Returns:

void

Example 1

Redirect to custom checkout

protected redirectToCartPage(): void {
  const useCustomCheckout = this.appService.getConfig().customCheckout;

  if (useCustomCheckout) {
    const checkoutUrl = this.buildCustomCheckoutUrl();
    this.safeRedirect(checkoutUrl);
  } else {
    super.redirectToCartPage();
  }
}

Example 2

Add tracking parameters

protected redirectToCartPage(): void {
  const currentLocale = this.getCurrentLocale();
  const cartUrl = currentLocale === '' ? '/cart' : `${currentLocale}/cart`;

  // Add tracking parameters
  const trackedUrl = `${cartUrl}?source=boost_widget&timestamp=${Date.now()}`;
  this.safeRedirect(trackedUrl);
}