Skip to content
Snippets Groups Projects
Commit 543e381c authored by Scott Carpenter's avatar Scott Carpenter
Browse files

Issue #3424134 by SKAUGHT. sshop Reviews fiex only one 'review' logic

parent 2b2dc3cc
No related branches found
No related tags found
1 merge request!20Issue #3424134 by SKAUGHT. sshop Reviews fiex only one 'review' logic
......@@ -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());
......
......@@ -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 %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment