Streamlining Purchases with URL-Based Cart Operations

Ecommerce icons on a flat background

The standard eCommerce workflow requires users to navigate to a product page and click an “Add to Cart” button. Simple. Direct. Most people are familiar with it. But for certain applications, you want to streamline this experience and remove as much friction as possible.

Membership renewals, email or SMS campaigns for specific products, quotes generated from sales reps, and embedded purchases within content. We developed the Commerce Cart Links module for these situations, and more.

The module exposes a /cart-links route that accepts product variation IDs, quantities, and optional parameters for controlling cart behavior and redirects. When a user visits a cart link URL, the module processes the specified product variations, adds them to a cart, and optionally redirects to a specified destination.

Here's a quick demo:

Use cases

Membership renewal workflows

Membership organizations with tiered structures can use cart links to send direct purchase links to members during renewal periods. Each member receives a URL specific to their membership tier, bypassing the need for them to navigate your website.

This approach reduces support overhead from members purchasing incorrect membership tiers and streamlines the renewal process for organizations managing thousands of members.

Email and marketing integrations

Cart links work well for email campaigns where you want to link directly to a purchase action. Instead of sending users to a product page where they need to click "Add to Cart," the link itself performs that action and can redirect to checkout, maintaining purchase momentum.

The module also supports aggregator platforms like Google Shopping and Facebook Marketplace, where ads can link directly to a checkout flow with the advertised product already in the cart.

For sites that combine content publishing with product sales—continuing education providers, standards organizations, technical documentation sites—cart links can be embedded within articles. A reader can click an inline link and immediately begin purchasing the referenced standard, course, or resource.

Free product fulfillment

For zero-cost products (such as free courses, samples, or trial memberships), cart links can be configured to redirect users directly to the resource after "purchase," effectively automating the fulfillment process without requiring interaction with the checkout form.

How Commerce Cart Links work

The module exposes the /cart-links route and accepts URL arguments in the format "{variation_id}-{quantity}." Multiple products can be added by chaining these arguments:

/cart-links/57-2
/cart-links/57-2/384-1

The first example adds two units of variation 57. The second adds two of variation 57 and one of variation 384.

It’s possible to prepopulate an entire cart, with several products, quantities, and variations, with a single link.

Query parameters

destination: By default, users are redirected to the cart form, but the destination query parameter works for cart links, so you can send them wherever you want.

/cart-links/57-2?destination=/checkout

store: Forces the use of a specific store ID when resolving or creating a cart, useful for multi-store installations.

existing: Controls how existing carts are handled. This parameter helps handle edge cases. Possible values:

  • new: Creates a new cart without affecting existing carts
  • empty: Empties the existing cart before adding products
  • delete: Deletes all existing carts before processing

Without this parameter, products are added to the default resolved cart for the user.

Validation

Cart links respect all Drupal Commerce availability checkers. If a product variation fails validation due to purchase restrictions, quantity limits, compatibility rules with other cart items, or user-specific constraints, the module returns appropriate error messages without adding the product.

Optional Referrer Validation

The module includes configuration options to whitelist referrer URLs. When enabled, cart links only process requests from specified domains, adding a security layer for implementations that need to control usage.

Configuration

Installation and configuration are minimal, since cart link behavior is controlled through URL parameters. The current module-level settings involve the referrer whitelist.

Current limitations

The module currently only supports Drupal Commerce’s default product variation entities. Sites using custom purchasable entity types will require additional development to work with cart links. Also, no default UI is included for cart links. They must be built manually, or custom admin pages can be built for specific use cases.

Potential roadmap

  • Administrative UI: Exposing cart link URLs in the product variation edit form or a dedicated management interface for easy copying and distribution.
  • Token Integration: Adding token support for dynamic cart link generation within text fields, allowing non-technical content editors to insert cart links using token replacement patterns.
  • Shortcode Support: Similar to WordPress shortcodes, allowing content editors to embed cart links using a simplified syntax within WYSIWYG editors.
  • Promotion/Coupon Integration: Extending cart links to automatically apply specific promotions or coupons during the add-to-cart operation, useful for campaign-specific discount links.

If you’d like to contribute help in any of these areas, let us know!

Add new comment