0

I created a marketplace (several stores on the same site) and the merchant can create a paid subscription to have the "Premium" role. Here's what I want to do:

  • The owner of a store has the role "Premium" = the website visitors have access to the button "Add to cart" on the product pages of his store.

  • The owner of a store does not have the role "Premium" = the website visitors do not have access to the button "Add to cart" on the product pages of his store.

How to disable the add to cart button (FOR VISITORS) if the owner of the store does not have the "Premium" role? *

Can I do that with a TWIG? If yes, how ?

Read my question. Depending on the role of the owner of a store, all users must be impacted.

WHY :

On my markerplace, I want to set up a paid subscription for sellers.

  • If the owner of a shop is not subscribed, he can not sell his products ("Added to Cart" button disabled).

  • If the owner of a shop is subscribed, he can sell his products (button "Added to cart" activated).

Whether the owner of a store is subscribed or not, everyone needs to see the stores and products. Only the "Add to Cart" button is impacted.

0

Yes, you can do this in twig file. So you will have to create a commerce product twig file(you can copy it from commerce module template). In the preprocess hook you will have to pass a value whether that product can show cart button or not. In your twig file you can use value of that flag around {{ product.variation }}. Add to cart button is rendered by this variable.

| improve this answer | |
  • Is this safe from caching? – Kevin Jun 19 '18 at 5:26
  • No, for that you will have to disable caching for product pages. – Bharat Jun 19 '18 at 7:45
  • @Bharat thank you for the explanations. This will disable the entire variation ? I only want to disable the "Add to Cart" button. Users should continue to see prices, references, and attributes. – user85517 Jun 19 '18 at 11:16
  • In that case, you can try form alter on add to cart form and check if you can get the variation id in $form somewhere, than load the author of that product and check it's role. – Bharat Jun 19 '18 at 13:31

Your Answer

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