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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | rendered_purchased_entity_in_cart-2640490-3-1.patch | 10.34 KB | vasike |
| #3 | rendered_purchased_entity_in_cart-2640490-3.patch | 10.1 KB | vasike |
| #2 | rendered_purchased_entity_in_cart-2640490-2.patch | 4.06 KB | vasike |
Comments
Comment #2
vasikethere 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.
Comment #3
vasikePatch 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.
Comment #4
mglamanYou need to tell Drupal the module is providing the theme hook.
Comment #5
mglamanWow last comment was off.
Do not need base hook here.
Add
commerce_product_variation__user as a copy of this (reference base hook here)
Comment #6
mglamanSee what I did here in #2646196: Create the order view route and mode for users
Comment #7
vasike@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
Comment #8
vasikePR 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
Comment #10
bojanz commentedCommitted the final version, thanks.