Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Commerce Product Restriction

Security covered

Part of the Commerce ecosystem · 355 projects

View on drupal.org

This module allows restricting the purchase of products for customers, disabling purchase at the point of adding to cart and displaying a message in place of the add to cart button.

A field referencing these restrictions can be added to any product type or product variation type, and when the product or product variation is edited users can specify which conditions apply to purchase.

Restrictions can be applied on the product level or product variation level, or both. In future it may be possible to apply them for product types and product variation types as well.

Important note

in the short term the restrictions apply only at the add to cart step. This means using "add to cart link" etc may not protect purchases. This is due to the AvailabilityChecker functionality in commerce seeming not to maintain the current user, and instead running some checks as the anonymous user.

Included restriction plugins

Restrict purchase to:

  • A specific date period
  • Password protected
  • Restrict purchase quantity across all user's orders
  • Users with specified user roles
  • Specific users

To install

  1. Install and enable the module
  2. To a product type or product variation type, add a field of type Plugin -> Product restriction
  3. Important! In the "Manage form display", make sure the field has "Product restrictions" set as the widget.
  4. Edit a product or variation of that type to add restrictions.

Custom restriction plugins

This module creates a new ProductRestrictionPlugin type, which extends the existing Commerce Condition plugin type. You just need to create a @ProductRestrictionPlugin under Plugin/Commerce/ProductRestriction in which you:

  • specify an "evaluate" function to determine whether the user has access
  • provide a settings form to provide detail for the conditions
  • optionally specify an error message function

See the included plugins for examples.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Nov 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
1.1.0 Stable Nov 6, 2023
1.0.0 Stable Nov 6, 2023