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
543e381c
Commit
543e381c
authored
Feb 29, 2024
by
Scott Carpenter
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3424134
by SKAUGHT. sshop Reviews fiex only one 'review' logic
parent
2b2dc3cc
No related branches found
No related tags found
1 merge request
!20
Issue #3424134 by SKAUGHT. sshop Reviews fiex only one 'review' logic
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sshop.theme
+25
-1
25 additions, 1 deletion
sshop.theme
templates/commerce/commerce-product.html.twig
+3
-1
3 additions, 1 deletion
templates/commerce/commerce-product.html.twig
with
28 additions
and
2 deletions
sshop.theme
+
25
−
1
View file @
543e381c
...
...
@@ -114,7 +114,31 @@ function sshop_preprocess_commerce_product(&$vars) {
/** @var \Drupal\comment\CommentFieldItemList $reviews */
if
(
$product
->
hasField
(
'field_reviews'
)
&&
$reviews
=
$product
->
get
(
'field_reviews'
))
{
$vars
[
'reviews_count'
]
=
$reviews
->
comment_count
;
$vars
[
'reviews_count'
]
=
1
;
//$reviews->comment_count;
$database
=
\Drupal
::
database
();
$current_user
=
\Drupal
::
currentUser
();
// Seek all Variations of this Product, if user has bought.
$query
=
$database
->
select
(
'commerce_order'
,
'co'
);
$query
->
leftJoin
(
'commerce_order_item'
,
'coi'
,
'co.order_id = coi.order_id'
);
$query
->
leftJoin
(
'commerce_product__variations'
,
'cpv'
,
'coi.purchased_entity = cpv.variations_target_id AND cpv.entity_id = :product_id'
,
[
':product_id'
=>
$product
->
id
()]);
$query
->
fields
(
'co'
,
[
'order_id'
])
->
condition
(
'co.state'
,
'completed'
)
->
condition
(
'co.uid'
,
$current_user
->
id
())
->
condition
(
'cpv.entity_id'
,
$product
->
id
())
->
isNotNull
(
'cpv.variations_target_id'
);
$result
=
$query
->
distinct
()
->
countQuery
()
->
execute
()
->
fetchField
();
$vars
[
'current_has_order'
]
=
$result
;
// User can ever only make one comment on THIS PRODUCT.
$query
=
$database
->
select
(
'comment_field_data'
,
'co'
);
$query
->
condition
(
'co.entity_type'
,
'commerce_product'
);
$query
->
condition
(
'co.field_name'
,
'field_reviews'
);
$query
->
condition
(
'co.uid'
,
$current_user
->
id
());
$query
->
condition
(
'co.entity_id'
,
$product
->
id
());
$result
=
$query
->
distinct
()
->
countQuery
()
->
execute
()
->
fetchField
();
$vars
[
'current_has_reviewed'
]
=
$result
;
}
$vars
[
'title'
]
=
strip_tags
(
$product
->
getTitle
());
...
...
This diff is collapsed.
Click to expand it.
templates/commerce/commerce-product.html.twig
+
3
−
1
View file @
543e381c
...
...
@@ -71,7 +71,9 @@
</h3>
<div
class=
"reviews-content"
>
{%
if
current_has_order
>
0
and
current_has_reviewed
==
0
%}
<div
class=
"add-review"
>
{{
product.field_reviews
}}
</div>
{%
endif
%}
</div>
</div>
{%
endif
%}
...
...
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