Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
#2896815: Replace the order summary view with a Twig template has landed and demonstrated two things:
1) Twig is more performant and easier to customize for these use cases
2) We can still support using a View
So, let's apply the same recipe to the cart block view.
Comment | File | Size | Author |
---|---|---|---|
#13 | 2906024-13.patch | 7.19 KB | Thomas Cys |
| |||
#12 | 2906024-12.patch | 7.19 KB | Thomas Cys |
#8 | cart_block_simple-2906024-8.patch | 7.24 KB | waspper |
#5 | 2906024-5.patch | 7.12 KB | mglaman |
|
Comments
Comment #2
Thomas CysAdded PR for this issue: https://github.com/drupalcommerce/commerce/pull/784
Comment #3
Thomas CysComment #4
Thomas CysComment #5
mglamanRebased patch against HEAD. Reviewing tests, which I forgot I was blocker on for this.
Comment #6
mglamanComment #7
bojanz CreditAttribution: bojanz at Centarro commentedThere are a few problems here:
1) Missing wrapper div that would allow CSS targetting (probably the same wrapper we use for the view?)
2) Unexpected template name. We generally name templates after the role they have, not the markup they contain. So this doesn't match what we did with the checkout order summary, for example. I'd expect the template to be called commerce-cart-block.html.twig
3) Not following coding standards (4 spaces instead of 2, lack of ending newline)
4) Lack of the usual docs block on top
Comment #8
waspper CreditAttribution: waspper as a volunteer and at Skilld commentedReviewed #5, and added some changes.
Not sure about advice No. 2 at #7, because template is provided for block content. Whole block will remain using the "commerce_cart_block" theme, because adding some content. Therefore, template was named to "commerce-cart-block-content-simple", to match better with its purpose. What do you think? :)
Comment #9
waspper CreditAttribution: waspper as a volunteer and at Skilld commentedComment #11
Thomas CysComment #12
Thomas CysComment #13
Thomas CysComment #14
Thomas CysDon't mind #12
Thanks for the patch waspper.
I just renamed the new template file from commerce-cart-block-content-simple to commerce-cart-block-content.
Comment #15
agoradesign CreditAttribution: agoradesign commentedWhen touching the CartBlock class already, we should take the chance and clean up cache metadata.
I've just found some needless lines:
Within build(), a CacheableMetadata object is created and populated, but never attached anywhere.
Further I'm unsure whether the cache context added directly to the render array is redundant - we already have implemented getCacheContexts(). I never needed to define this twice in any block I've created so far.
@bojanz: if this should go into a separate issue, tell me, I can provide a patch (didn't do it because it would only break this one, if it gets sooner committed)
Comment #16
charlieweb82 CreditAttribution: charlieweb82 at Acro Commerce commentedTesting the patch and the template reference commerce-cart-block-content.html.twig in the code don’t load any changes like add a class or delete elements from the template, should be nice to load different field separately, also not use table in a small space. view cart should use in the template div to display like table.
Comment #17
Thomas CysNot 100% sure what you mean by
Remember that this twig file only mimics the view (commerce_cart_block) that is provided by the commerce_cart module. The twig file in this patch should not vary from that.