Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sshop
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
sshop
Commits
001b6f5c
Commit
001b6f5c
authored
Feb 29, 2024
by
Scott Carpenter
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3424121
by skaught. fix empty count and ensure tab always has title content.
parent
2b2dc3cc
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!19
Issue #3424121 by skaught. fix empty count and ensure tab always has title content.
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sshop.theme
+19
-2
19 additions, 2 deletions
sshop.theme
templates/commerce/commerce-product.html.twig
+16
-14
16 additions, 14 deletions
templates/commerce/commerce-product.html.twig
with
35 additions
and
16 deletions
sshop.theme
+
19
−
2
View file @
001b6f5c
...
...
@@ -113,8 +113,25 @@ function sshop_preprocess_commerce_product(&$vars) {
$product
=
$vars
[
'elements'
][
'#commerce_product'
];
/** @var \Drupal\comment\CommentFieldItemList $reviews */
if
(
$product
->
hasField
(
'field_reviews'
)
&&
$reviews
=
$product
->
get
(
'field_reviews'
))
{
$vars
[
'reviews_count'
]
=
$reviews
->
comment_count
;
$reviews
=
NULL
;
$variables
[
"published_reviews"
]
=
NULL
;
/** @var \Drupal\comment\CommentFieldItemList $reviews */
if
(
$product
->
hasField
(
'field_reviews'
)){
if
(
!
$product
->
get
(
'field_reviews'
)
->
isEmpty
()
){
$vars
[
'reviews_count'
]
=
$product
->
get
(
'field_reviews'
)
->
comment_count
;
}
$current_user
=
\Drupal
::
currentUser
();
$vars
[
'reviews_tab'
]
=
0
;
// Or handle as appropriate
if
(
$current_user
->
hasPermission
(
'access comments'
))
{
// Additionally, check if the user has access to view the field_reviews field
if
(
$product
->
get
(
'field_reviews'
)
->
access
(
'view'
,
$current_user
))
{
$vars
[
'reviews_tab'
]
=
1
;
}
}
}
$vars
[
'title'
]
=
strip_tags
(
$product
->
getTitle
());
...
...
This diff is collapsed.
Click to expand it.
templates/commerce/commerce-product.html.twig
+
16
−
14
View file @
001b6f5c
...
...
@@ -33,17 +33,16 @@
<li
class=
"active"
>
<a
data-toggle=
"tab"
href=
"#description"
>
{{
'Description'
|
t
}}
</a>
</li>
{%
if
reviews_count
%}
<li>
{%
if
reviews_tab
==
1
and
reviews_count
is
not
empty
%}
<li>
<a
data-toggle=
"tab"
href=
"#reviews"
>
{{
'Reviews'
|
t
}}
{%
if
reviews_count
>
0
%}
<span
class=
"reviews-count"
>
(
{{
reviews_count
}}
)
</span>
{%
endif
%}
</a>
</li>
</li>
{%
endif
%}
</ul>
...
...
@@ -54,7 +53,6 @@
{{
product.body
}}
</div>
</div>
{%
if
reviews_count
%}
<div
id=
"reviews"
name=
"reviews"
class=
"tab-pane fade"
>
<h3
class=
"tab-title"
>
{%
if
reviews_count
>
0
%}
...
...
@@ -67,6 +65,10 @@
{{
reviews_count
}}
reviews for
{{
title
}}
{%
endtrans
%}
{%
endif
%}
{%
else
%}
{%
trans
with
{
'context'
:
'product reviews title'
}
%}
No Reviews for
{{
title
}}
{%
endtrans
%}
{%
endif
%}
</h3>
...
...
@@ -74,7 +76,7 @@
{{
product.field_reviews
}}
</div>
</div>
{%
endif
%}
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment