Each entity type that can be used as a line item source (such as commerce_product_variation) must be given a "cart" view mode.

We'll need to do this by implementing hook_rebuild() in the cart module.

Process:
1) Take the entity manager from \Drupal::service('entity.manager')
2) Find a list of relevant entity types:

    $entityTypes = \Drupal::service('entity.manager')->getDefinitions();
    $sourceEntityTypes = array_filter($entityTypes, function($entityType) {
      return $entityType->isSubclassOf('\Drupal\commerce\LineItemSourceInterface');
    });

3) For each entity type id, try to load the "cart" view mode, using EntityViewMode::load($entity_type . '.cart').
4) If missing, create it, using EntityViewMode::create() and then $entity->save().

If this works, you will be able to clear the caches, go to the "Manage display" tab of a product variation type, and see a Cart view mode.

CommentFileSizeAuthor
#7 cart-view-mode-2543390-7.patch1.81 KBdbolinovski
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Issue summary: View changes
joshtaylor’s picture

joshtaylor’s picture

Assigned: Unassigned » joshtaylor
joshtaylor’s picture

Status: Active » Needs review
joshtaylor’s picture

Status: Needs review » Needs work
joshtaylor’s picture

Test breakage not related to this issue.

dbolinovski’s picture

hook_rebuild() implementation.

bojanz’s picture

  • bojanz committed f2d8748 on 8.x-2.x authored by dbolinovski
    Issue #2543390 by dbolinovski: Provide a cart view mode for each...

Status: Fixed » Closed (fixed)

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