Right now the "item" column in the cart shows the line item title.
At the same time, the cart module provides a "cart" view mode for each purchasable entity type.
We should switch the item column to showing the entity rendered in that "cart" view mode, allowing us to achieve the mockup:
https://www.drupal.org/files/issues/Cart%20View%20-%201.0.jpg
So in the variation case there's:
- product title
- sku
- attributes
- view link
We should create a template file by default, to show the users how it's supposed to be done.
Then if they add an image, they can just make the output render in two columns by changing the template file.

Of course, people will still be free to edit the view as before, but using a rendered entity is a good best practise to introduce.
Also deprecates half of https://www.drupal.org/project/commerce_product_attributes.

Comments

bojanz created an issue. See original summary.

vasike’s picture

Status: Active » Needs review
StatusFileSize
new4.06 KB

there is patch for this:
- update the Cart view, replace the line item title with the line item Purchased entity using Cart view mode
- Build extra field for product variation "line_item_label" using hook_entity_extra_field_info and hook_ENTITY_TYPE_view hooks in commerce_product.module
- Add Cart Entity view display config for the default product variation to Cart module
This display (view mode) config includes the new "line_item_label" extra display field + sku. Price is hidden.

imho this "line_item_label" should be available as both display field and view field for product variations.
Maybe also the "view link" should be available as extra display field.

vasike’s picture

Patch updates:
- Add templates for the Product variation
commerce-product-variation--cart.html.twig
- implement template_preprocess_commerce_product_variation()
- implement hook_theme_suggestions_commerce_product_variation, for this one build a generic commerce helper function _commerce_theme_suggestions_commerce_entity.
- Add template for the Product variation for cart view mode
commerce-product-variation--cart.html.twig - it includes also a link to product page as it is in the issue description mockup.

I uploaded 2 patch files, one adds the cart view mode template in the cart module and the other directly in the product module.
In both case it seems the theming doesn't know to use it.
Only if i put this file in the current theme, templates subfolder, the template will be used in the cart page.

mglaman’s picture

/**
 * Implements hook_theme().
 */
function commerce_order_theme($existing, $type, $theme, $path) {
  return [
    'commerce_order' => [
      'render element' => 'elements',
    ],
    'commerce_order_edit_form' => [
      'render element' => 'form',
    ],
  ];
}

You need to tell Drupal the module is providing the theme hook.

mglaman’s picture

Wow last comment was off.

+++ b/modules/product/commerce_product.module
@@ -17,6 +21,10 @@ function commerce_product_theme() {
+    'commerce_product_variation' => [
+      'render element' => 'elements',
+      'base hook' => 'commerce_product_variation',

Do not need base hook here.

Add

commerce_product_variation__user as a copy of this (reference base hook here)

mglaman’s picture

+++ b/modules/order/commerce_order.module
@@ -18,6 +18,10 @@ function commerce_order_theme($existing, $type, $theme, $path) {
     'commerce_order' => [
       'render element' => 'elements',
     ],
+    'commerce_order__user' => [
+      'base hook' => 'commerce_order',
+      'render element' => 'elements',
+    ],

See what I did here in #2646196: Create the order view route and mode for users

vasike’s picture

@mglaman : thanks for the suggestion.
So i followed mglaman suggestion about templates and made a PR which includes the commit from another PR for #2652704: Port display_submitted to product types - to avoid conflicts and use some code already there.

https://github.com/drupalcommerce/commerce/pull/310

vasike’s picture

PR updated
- Remove code for the other isssue #2652704: Port display_submitted to product types, won't fix
- but keep the theming code needed here
- also add the the cart display mode definition for the product variations. it was missing for PR (not added from previous patches).

https://github.com/drupalcommerce/commerce/pull/310

  • bojanz committed a763579 on 8.x-2.x authored by vasike
    Issue #2640490 by vasike: Show the rendered purchased entity in the cart...
bojanz’s picture

Status: Needs review » Fixed

Committed the final version, thanks.

Status: Fixed » Closed (fixed)

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