In Commerce 1.x products were shown with a product display node. My understanding is, that this is no longer necessary in Commerce 2.x

An anonymous user does not have access to view a Commerce Product. What is the Commerce 2.x way of displaying products?

Comments

platinum1 created an issue. See original summary.

agoradesign’s picture

This is the 2.x way, only the permissions are not defined at the moment.

platinum1’s picture

Thank you. I appreciate the quick feedback!

platinum1’s picture

What is the planing for creating permissions for Commerce Products?

bojanz’s picture

Next week or so. We're busy on checkout at the moment.

platinum1’s picture

Thank you Bojan. That would be very helpful.

agoradesign’s picture

I plan to work on theming the product page of my current project next week. I may post a patch here which includes the permissions.

bojanz’s picture

@agoradesign
Permissions need to be done in the Entity API module, and then applied to every entity type. There's a pull request in the fago/entity repository already, but it hasn't been finished.

agoradesign’s picture

I've added a related issue, which fits to general topic of how to display the fields and attributes of variations within the product template

platinum1’s picture

@bojanz
Do you have an update on the Entity API module regarding the permissions?

agoradesign’s picture

@platinum1

Here's a workaround for you. Implement this in a custom function, if you want to have general access to product entities. For a more fine grain, role-based approach, you'd need to define permissions of course:

function YOURMODULE_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
  if ($operation == 'view' && $entity instanceof \Drupal\commerce_product\Entity\ProductInterface && $entity->isPublished()) {
    return \Drupal\Core\Access\AccessResult::allowed();
  }
  return \Drupal\Core\Access\AccessResult::neutral();
}
bojanz’s picture

Title: How to display products? » Add temporary access code to allow anon users to view products and their variations
Category: Support request » Task

Retitling. Opened #2715273: Implement full permissions for every entity type to track the full fix.

  • bojanz committed 80c3206 on 8.x-2.x
    Issue #2690817 by agoradesign, bojanz: Add temporary access code to...
bojanz’s picture

Status: Active » Fixed

Committed a combination of #11 and a variations fix.

platinum1’s picture

Cool. Temporary works for the project.
Thank you guys!

agoradesign’s picture

Btw when removing my custom code, I saw that I obviously added the same variation part in the meantime :D

thanks anyway for the fix :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.