1

We would like to be able to restrict access to buy products.

  • A product could be members-only
  • Users who are already members should be prevented from buying membership again until near expiry.

If there is no access to buy, the "add to cart" button should not be shown. There also needs to be a check during checkout, for example in case the a member added a membership to the cart as anonymous then logged in, they still should not be able to buy membership.

We don't want to restrict access to view products. Non-members should be able to see the benefits of membership, and what extra things they could buy. The price should still be visible for products that cannot be bought (so we can't hide the entire "Add to Cart" form as that's where the price comes from).

Please can someone explain how to achieve this?

2

I believe that good start is to implement EventSubscriber listening on ProductEvents::FILTER_VARIATIONS event. It was introduced to filter out some product variations based on different aspects, such as stock, date, etc.

| improve this answer | |
  • Many thanks I will give that a try and report back. – AdamS Jun 25 '18 at 20:07
  • This is a good solution many thanks, but commerce seems to be missing this part "There also needs to be a check during checkout, for example in case the a member added a membership to the cart as anonymous then logged in, they still should not be able to buy membership." – AdamS Jul 29 '18 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.