init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
use Esun\Review\Block\Adminhtml\Review\Images;
|
||||
use Magento\Framework\Escaper;
|
||||
|
||||
/**
|
||||
* @var Images $block
|
||||
* @var Escaper $escaper
|
||||
*/
|
||||
$images = $block->getImages();
|
||||
if (!$images) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<style>
|
||||
.esun-admin-review-images {
|
||||
background: #fff;
|
||||
border: 1px solid #d6d6d6;
|
||||
margin-top: 2rem;
|
||||
padding: 1.8rem;
|
||||
}
|
||||
.esun-admin-review-images__title {
|
||||
color: #303030;
|
||||
font-size: 1.7rem;
|
||||
font-weight: 600;
|
||||
margin: 0 0 1.5rem;
|
||||
}
|
||||
.esun-admin-review-images__list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.esun-admin-review-images__item {
|
||||
color: #303030;
|
||||
display: grid;
|
||||
gap: .6rem;
|
||||
text-decoration: none;
|
||||
width: 120px;
|
||||
}
|
||||
.esun-admin-review-images__item img {
|
||||
border: 1px solid #d6d6d6;
|
||||
height: 120px;
|
||||
object-fit: cover;
|
||||
width: 120px;
|
||||
}
|
||||
.esun-admin-review-images__status {
|
||||
color: #666;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
</style>
|
||||
<div class="esun-admin-review-images">
|
||||
<h2 class="esun-admin-review-images__title"><?= $escaper->escapeHtml(__('Review Media')) ?></h2>
|
||||
<div class="esun-admin-review-images__list">
|
||||
<?php foreach ($images as $image): ?>
|
||||
<a class="esun-admin-review-images__item"
|
||||
href="<?= $escaper->escapeUrl($image['url']) ?>"
|
||||
target="_blank"
|
||||
rel="noopener">
|
||||
<?php if (($image['type'] ?? 'image') === 'video'): ?>
|
||||
<video src="<?= $escaper->escapeUrl($image['url']) ?>" controls preload="metadata" style="max-width:220px;max-height:160px"></video>
|
||||
<?php else: ?><img src="<?= $escaper->escapeUrl($image['thumb']) ?>" alt=""><?php endif; ?>
|
||||
<span class="esun-admin-review-images__status">
|
||||
<?= $escaper->escapeHtml((int)$image['status'] === 1 ? __('Visible') : __('Hidden')) ?>
|
||||
</span>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<head>
|
||||
<css src="Esun_Review::css/review.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<referenceContainer name="content.aside">
|
||||
<block class="Esun\Review\Block\Product\Review"
|
||||
name="esun.product.reviews"
|
||||
template="Esun_Review::product/reviews.phtml"
|
||||
after="product.info.additional"
|
||||
cacheable="false"
|
||||
ifconfig="catalog/review/active">
|
||||
<block class="Magento\Review\Block\Form"
|
||||
name="product.review.form"
|
||||
as="review_form"
|
||||
template="Esun_Review::review/form.phtml"
|
||||
ifconfig="catalog/review/active">
|
||||
<arguments>
|
||||
<argument name="button_lock_manager" xsi:type="object">Magento\Framework\View\Element\ButtonLockManager</argument>
|
||||
<argument name="jsLayout" xsi:type="array">
|
||||
<item name="components" xsi:type="array">
|
||||
<item name="review-form" xsi:type="array">
|
||||
<item name="component" xsi:type="string">Magento_Review/js/view/review</item>
|
||||
</item>
|
||||
</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
<container name="form.additional.review.info" as="form_additional_review_info"/>
|
||||
<container name="product.review.form.fields.before" as="form_fields_before" label="Review Form Fields Before"/>
|
||||
</block>
|
||||
</block>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<update handle="customer_account"/>
|
||||
<head><css src="Esun_Review::css/review.css"/><css src="Esun_Customer::css/account-dashboard.css"/></head>
|
||||
<body>
|
||||
<referenceContainer name="content">
|
||||
<block class="Esun\Review\Block\Customer\Awaiting" name="esun.review.customer.awaiting"
|
||||
template="Esun_Review::customer/awaiting.phtml" cacheable="false"/>
|
||||
</referenceContainer>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
|
||||
<referenceBlock name="product.info.product_additional_data" template="Esun_Review::product/view/list.phtml"/>
|
||||
</layout>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"><head><css src="Esun_Review::css/review.css"/></head><body><referenceContainer name="content"><block class="Esun\Review\Block\Order\ReviewableItems" name="esun.order.reviewable.items" template="Esun_Review::order/reviewable-items.phtml" after="esun.sales.order.detail" cacheable="false"/></referenceContainer></body></page>
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
/** @var \Esun\Review\Block\Customer\Awaiting $block */
|
||||
/** @var \Magento\Framework\Escaper $escaper */
|
||||
$items = $block->getItems();
|
||||
$ratings = $block->getRatings();
|
||||
?>
|
||||
<div class="esun-awaiting-reviews">
|
||||
<?php if ($items->getSize()): ?>
|
||||
<?php foreach ($items as $item): ?>
|
||||
<article class="esun-awaiting-review-card">
|
||||
<img src="<?= $escaper->escapeUrl($block->getImageUrl($item)) ?>"
|
||||
alt="<?= $escaper->escapeHtmlAttr($item->getName()) ?>" loading="lazy">
|
||||
<div class="esun-awaiting-review-card__info">
|
||||
<small><?= $escaper->escapeHtml(__('Order #%1', $item->getData('order_increment_id'))) ?></small>
|
||||
<h3><?= $escaper->escapeHtml($item->getName()) ?></h3>
|
||||
<form class="review-form esun-awaiting-review-form"
|
||||
action="<?= $escaper->escapeUrl($block->getPostUrl((int)$item->getProductId())) ?>"
|
||||
method="post" enctype="multipart/form-data" data-role="awaiting-review-form">
|
||||
<?= $block->getBlockHtml('formkey') ?>
|
||||
<input type="hidden" name="order_item_id" value="<?= (int)$item->getId() ?>">
|
||||
<fieldset class="fieldset review-fieldset">
|
||||
<?php foreach ($ratings as $rating): ?>
|
||||
<?php $ratingLabelId = 'awaiting_' . (int)$item->getId() . '_' . (int)$rating->getId() . '_label'; ?>
|
||||
<fieldset class="field required review-field-ratings">
|
||||
<legend class="label" id="<?= $escaper->escapeHtmlAttr($ratingLabelId) ?>">
|
||||
<span><?= $escaper->escapeHtml(__('Rating')) ?></span>
|
||||
</legend>
|
||||
<div class="control">
|
||||
<div class="nested">
|
||||
<div class="field choice review-field-rating">
|
||||
<div class="control review-control-vote">
|
||||
<?php $iterator = 1; ?>
|
||||
<?php foreach ($rating->getOptions() as $option): ?>
|
||||
<?php $optionId = 'awaiting_' . (int)$item->getId() . '_' . (int)$rating->getId() . '_' . (int)$option->getValue(); ?>
|
||||
<input required type="radio"
|
||||
class="radio"
|
||||
name="ratings[<?= (int)$rating->getId() ?>]"
|
||||
id="<?= $escaper->escapeHtmlAttr($optionId) ?>"
|
||||
value="<?= (int)$option->getId() ?>"
|
||||
aria-labelledby="<?= $escaper->escapeHtmlAttr($ratingLabelId . ' ' . $optionId . '_label') ?>">
|
||||
<label class="rating-<?= (int)$iterator ?>"
|
||||
id="<?= $escaper->escapeHtmlAttr($optionId . '_label') ?>"
|
||||
for="<?= $escaper->escapeHtmlAttr($optionId) ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr(__('%1 %2', $iterator, $iterator > 1 ? __('stars') : __('star'))) ?>">
|
||||
<span><?= $escaper->escapeHtml(__('%1 %2', $iterator, $iterator > 1 ? __('stars') : __('star'))) ?></span>
|
||||
</label>
|
||||
<?php $iterator++; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endforeach; ?>
|
||||
<div class="field review-field-text required">
|
||||
<label class="label" for="review_detail_<?= (int)$item->getId() ?>"><span><?= $escaper->escapeHtml(__('Review')) ?></span></label>
|
||||
<div class="control"><textarea id="review_detail_<?= (int)$item->getId() ?>" name="detail" rows="3" required></textarea></div>
|
||||
</div>
|
||||
<div class="field review-field-images">
|
||||
<span class="label"><span><?= $escaper->escapeHtml(__('Images or Video')) ?></span></span>
|
||||
<div class="control">
|
||||
<input class="esun-review-upload-input" id="review_images_<?= (int)$item->getId() ?>" type="file" name="review_images[]" multiple="multiple"
|
||||
accept="image/jpeg,image/png,image/gif,image/webp,video/mp4,video/webm,video/quicktime">
|
||||
<div class="esun-review-upload-row">
|
||||
<label class="esun-review-upload-control" for="review_images_<?= (int)$item->getId() ?>">
|
||||
<i class="iconfont icon-picture1" aria-hidden="true"></i>
|
||||
<span><?= $escaper->escapeHtml(__('Add Images or Videos')) ?></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="esun-review-upload-preview" data-role="review-image-preview"></div>
|
||||
<p class="note esun-review-upload-note"><?= $escaper->escapeHtml(__('You can add files in multiple selections. Supports JPG, PNG, GIF, WebP, MP4, WebM and MOV.')) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="actions-toolbar review-form-actions">
|
||||
<div class="primary actions-primary"><button class="action submit primary" type="submit"><span><?= $escaper->escapeHtml(__('Submit Review')) ?></span></button></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
<?= $block->getChildHtml('pager') ?>
|
||||
<?php else: ?>
|
||||
<div class="message info empty"><span><?= $escaper->escapeHtml(__('There are no products awaiting review.')) ?></span></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<script>
|
||||
require(['jquery'], function ($) {
|
||||
'use strict';
|
||||
|
||||
function getFileKey(file) {
|
||||
return [file.name, file.size, file.lastModified].join(':');
|
||||
}
|
||||
|
||||
function syncInputFiles(input, files) {
|
||||
if (typeof DataTransfer === 'undefined') {
|
||||
return;
|
||||
}
|
||||
var transfer = new DataTransfer();
|
||||
files.forEach(function (file) { transfer.items.add(file); });
|
||||
input.files = transfer.files;
|
||||
}
|
||||
|
||||
function renderPreviews(form, files) {
|
||||
var preview = form.find('[data-role=review-image-preview]').empty(),
|
||||
previousPreviewUrls = form.data('previewUrls') || [],
|
||||
previewUrls = [];
|
||||
|
||||
previousPreviewUrls.forEach(function (url) {
|
||||
if (window.URL && window.URL.revokeObjectURL) {
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
|
||||
files.forEach(function (file) {
|
||||
var key = getFileKey(file),
|
||||
item = $('<span class="esun-review-upload-preview__item">').attr('data-file-key', key),
|
||||
remove = $('<button class="esun-review-upload-preview__remove" type="button">')
|
||||
.attr({'aria-label': '<?= $escaper->escapeJs(__('Remove')) ?>', title: '<?= $escaper->escapeJs(__('Remove')) ?>'})
|
||||
.text('×');
|
||||
|
||||
if (file.type.match(/^video\//) && window.URL && window.URL.createObjectURL) {
|
||||
var videoUrl = window.URL.createObjectURL(file);
|
||||
previewUrls.push(videoUrl);
|
||||
$('<video preload="metadata" muted playsinline>')
|
||||
.attr({src: videoUrl, title: file.name})
|
||||
.appendTo(item);
|
||||
} else if (file.type.match(/^image\//)) {
|
||||
var image = $('<img>').attr('alt', file.name).appendTo(item),
|
||||
reader = new FileReader();
|
||||
reader.onload = function (event) { image.attr('src', event.target.result); };
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
$('<span class="esun-review-upload-preview__file">').text(file.name).appendTo(item);
|
||||
}
|
||||
item.append(remove).appendTo(preview);
|
||||
});
|
||||
form.data('previewUrls', previewUrls);
|
||||
}
|
||||
|
||||
$('.esun-awaiting-reviews').on('change', 'input[name="review_images[]"]', function () {
|
||||
var input = this,
|
||||
form = $(input).closest('form'),
|
||||
previousFiles = $(input).data('selectedFiles') || [],
|
||||
newFiles = Array.prototype.slice.call(input.files || []),
|
||||
files = previousFiles.slice(),
|
||||
knownFiles = {};
|
||||
previousFiles.forEach(function (file) {
|
||||
knownFiles[getFileKey(file)] = true;
|
||||
});
|
||||
newFiles.forEach(function (file) {
|
||||
var key = getFileKey(file);
|
||||
if (!knownFiles[key]) {
|
||||
files.push(file);
|
||||
knownFiles[key] = true;
|
||||
}
|
||||
});
|
||||
syncInputFiles(input, files);
|
||||
$(input).data('selectedFiles', files);
|
||||
renderPreviews(form, files);
|
||||
});
|
||||
|
||||
$('.esun-awaiting-reviews').on('click', '.esun-review-upload-preview__remove', function () {
|
||||
var form = $(this).closest('form'),
|
||||
input = form.find('input[name="review_images[]"]')[0],
|
||||
removeKey = $(this).closest('[data-file-key]').attr('data-file-key'),
|
||||
files = ($(input).data('selectedFiles') || []).filter(function (file) {
|
||||
return getFileKey(file) !== removeKey;
|
||||
});
|
||||
syncInputFiles(input, files);
|
||||
$(input).data('selectedFiles', files);
|
||||
renderPreviews(form, files);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var \Magento\Review\Block\Product\ReviewRenderer $block */
|
||||
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
|
||||
/** @var \Magento\Framework\Escaper $escaper */
|
||||
|
||||
$url = $block->getReviewsUrl() . '#reviews';
|
||||
$urlForm = $block->getReviewsUrl() . '#review-form';
|
||||
?>
|
||||
<?php if ($block->isReviewEnabled()): ?>
|
||||
<?php $rating = $block->getRatingSummary(); ?>
|
||||
<div class="product-reviews-summary short<?= !$rating ? ' no-rating' : '' ?>">
|
||||
<?php if ($rating):?>
|
||||
<div class="rating-summary">
|
||||
<span class="label"><span><?= $escaper->escapeHtml(__('Rating')) ?>:</span></span>
|
||||
<div class="rating-result"
|
||||
id="rating-result_<?= /* @noEscape */ $block->getProduct()->getId() ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr($rating) ?>%">
|
||||
<span style="width: <?= $escaper->escapeHtmlAttr($rating) ?>%;">
|
||||
<span><?= $escaper->escapeHtml($rating) ?>%</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
<div class="reviews-actions">
|
||||
<a class="action view"
|
||||
href="<?= $escaper->escapeUrl($url) ?>"><?= $escaper->escapeHtml($block->getReviewsCount()) ?>
|
||||
<span><?= ($block->getReviewsCount() == 1) ?
|
||||
$escaper->escapeHtml(__('Review')) : $escaper->escapeHtml(__('Reviews')) ?>
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($block->isReviewEnabled() && $block->getDisplayIfEmpty()): ?>
|
||||
<div class="product-reviews-summary short empty">
|
||||
<div class="reviews-actions">
|
||||
<a class="action add" href="<?= $escaper->escapeUrl($urlForm) ?>">
|
||||
<?= $escaper->escapeHtml(__('Be the first to review this product')) ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php /** @var \Esun\Review\Block\Order\ReviewableItems $block */ /** @var \Magento\Framework\Escaper $escaper */ $ratings=$block->getRatings(); ?>
|
||||
<section class="block esun-order-reviews"><div class="block-title"><strong><?= $escaper->escapeHtml(__('Review Your Purchases')) ?></strong></div><div class="block-content">
|
||||
<?php foreach($block->getItems() as $item): ?><div class="esun-order-review-item"><div><strong><?= $escaper->escapeHtml($item->getName()) ?></strong><?php if($block->hasReviewed($item)):?><span class="esun-order-review-status"><?= $escaper->escapeHtml(__('Reviewed')) ?></span><?php elseif(!$block->canReview($item)):?><span class="esun-order-review-status"><?= $escaper->escapeHtml(__('Available after payment')) ?></span><?php endif;?></div>
|
||||
<?php if($block->canReview($item)):?><details><summary class="action primary"><?= $escaper->escapeHtml(__('Write a Review')) ?></summary><form class="review-form" action="<?= $escaper->escapeUrl($block->getPostUrl((int)$item->getProductId())) ?>" method="post" enctype="multipart/form-data"><?= $block->getBlockHtml('formkey') ?><input type="hidden" name="order_item_id" value="<?= (int)$item->getId() ?>">
|
||||
<fieldset class="fieldset"><div class="field required"><label class="label"><span><?= $escaper->escapeHtml(__('Your Rating')) ?></span></label><div class="control"><?php foreach($ratings as $rating):?><div><span><?= $escaper->escapeHtml($rating->getRatingCode()) ?></span><?php foreach($rating->getOptions() as $option):?><label><input required type="radio" name="ratings[<?= (int)$rating->getId() ?>]" value="<?= (int)$option->getId() ?>"> <?= (int)$option->getValue() ?></label><?php endforeach;?></div><?php endforeach;?></div></div>
|
||||
<div class="field required"><label class="label"><span><?= $escaper->escapeHtml(__('Review')) ?></span></label><div class="control"><textarea name="detail" required></textarea></div></div><div class="field"><label class="label"><span><?= $escaper->escapeHtml(__('Images or Video')) ?></span></label><div class="control"><input type="file" name="review_images[]" multiple accept="image/jpeg,image/png,image/gif,image/webp,video/mp4,video/webm,video/quicktime"><p class="note"><?= $escaper->escapeHtml(__('Upload JPG, PNG, GIF, WebP, MP4, WebM or MOV files.')) ?></p></div></div></fieldset><button class="action primary" type="submit"><span><?= $escaper->escapeHtml(__('Submit Review')) ?></span></button></form></details><?php endif;?></div><?php endforeach;?></div></section>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $block \Esun\Review\Block\Product\Review
|
||||
*/
|
||||
$canShowReviewForm = $block->canShowReviewForm();
|
||||
$mageInit = [
|
||||
'*' => [
|
||||
'Esun_Review/js/product-reviews' => [
|
||||
'productReviewUrl' => $block->getProductReviewUrl(),
|
||||
],
|
||||
],
|
||||
'.product-reviews-section' => [
|
||||
'Esun_Review/js/review-form-modal' => [],
|
||||
],
|
||||
];
|
||||
?>
|
||||
<div class="page-main page-main-reviews" id="reviews">
|
||||
<div class="columns">
|
||||
<div class="column main">
|
||||
<div class="product-full-width-section product-reviews-section">
|
||||
<div id="product-review-container" data-role="product-review"></div>
|
||||
<?php if ($canShowReviewForm): ?>
|
||||
<div class="esun-review-form-modal" data-role="esun-review-form-modal" hidden>
|
||||
<div class="esun-review-form-modal__overlay" data-role="esun-review-form-close"></div>
|
||||
<div class="esun-review-form-modal__dialog" role="dialog" aria-modal="true" aria-label="<?= $block->escapeHtmlAttr(__('Write A Review')) ?>">
|
||||
<button class="esun-review-form-modal__close" type="button" data-role="esun-review-form-close">×</button>
|
||||
<?= $block->getChildHtml() ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/x-magento-init">
|
||||
<?= /* @noEscape */ json_encode($mageInit, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) ?>
|
||||
</script>
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\View\Helper\SecureHtmlRenderer;
|
||||
use Magento\Review\Block\Product\View\ListView;
|
||||
|
||||
/**
|
||||
* @var ListView $block
|
||||
* @var SecureHtmlRenderer $secureRenderer
|
||||
* @var Escaper $escaper
|
||||
*/
|
||||
$imageBlock = $block->getLayout()->createBlock(\Esun\Review\Block\Review\Images::class);
|
||||
$reviewData = $block->getLayout()->createBlock(\Esun\Review\Block\Review\Data::class);
|
||||
$productId = $reviewData ? $reviewData->getCurrentProductId((int)$block->getProductId()) : 0;
|
||||
$collection = $reviewData ? $reviewData->getReviewsCollection($productId, 10) : $block->getReviewsCollection();
|
||||
$_items = $collection->getItems();
|
||||
$toolbar = $block->getChildBlock('toolbar');
|
||||
if ($toolbar) {
|
||||
$toolbar->setCollection($collection);
|
||||
}
|
||||
$summary = $reviewData ? $reviewData->getSummary($productId) : ['score' => 0.0, 'count' => 0, 'percent' => 0];
|
||||
$customerPhotos = $reviewData ? $reviewData->getCustomerPhotos($productId) : [];
|
||||
$canWriteReview = false;
|
||||
$reviewIds = array_map(static fn ($review): int => (int)$review->getReviewId(), $_items);
|
||||
$customerIds = array_map(static fn ($review): int => (int)$review->getCustomerId(), $_items);
|
||||
$votes = $reviewData ? $reviewData->getVotes($reviewIds) : [];
|
||||
$reviewPercents = $reviewData ? $reviewData->getReviewPercents($reviewIds) : [];
|
||||
$customerNames = $reviewData ? $reviewData->getCustomerNames($customerIds) : [];
|
||||
$allPhotoUrls = array_column($customerPhotos, 'url');
|
||||
?>
|
||||
<div class="block review-list esun-customer-reviews" id="customer-reviews"
|
||||
data-mage-init='{"Esun_Review/js/review-vote":{"voteUrl":"<?= $escaper->escapeUrl($reviewData ? $reviewData->getVoteUrl() : '') ?>"}}'>
|
||||
<div class="esun-customer-reviews__header">
|
||||
<div class="esun-customer-reviews__summary">
|
||||
<h2 class="product-section-title"><?= $escaper->escapeHtml(__('Customer Reviews')) ?></h2>
|
||||
<div class="esun-review-stars" aria-label="<?= $escaper->escapeHtmlAttr(__('%1 out of 5 stars', $summary['score'])) ?>">
|
||||
<span class="esun-review-stars__base">★★★★★</span>
|
||||
<span class="esun-review-stars__fill" style="width: <?= (int)$summary['percent'] ?>%;">★★★★★</span>
|
||||
</div>
|
||||
<span class="esun-customer-reviews__score">
|
||||
<?= $escaper->escapeHtml(number_format((float)$summary['score'], 1)) ?>
|
||||
<span>(<?= $escaper->escapeHtml(__('%1Reviews', (int)$summary['count'])) ?>)</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="esun-customer-reviews__actions">
|
||||
<div class="esun-customer-reviews__photos-wrap">
|
||||
<?php if ($customerPhotos): ?>
|
||||
<div class="esun-customer-reviews__photos-title"><?= $escaper->escapeHtml(__('Customer Photos')) ?></div>
|
||||
<div class="esun-customer-reviews__photos"
|
||||
data-mage-init='{"Esun_Catalog/js/drag-scroll":{},"Esun_Review/js/review-images":{}}'>
|
||||
<?php foreach ($customerPhotos as $index => $photo): ?>
|
||||
<button class="esun-review-images__thumb esun-customer-reviews__photo"
|
||||
type="button"
|
||||
data-index="<?= (int)$index ?>"
|
||||
data-images="<?= $escaper->escapeHtmlAttr(json_encode($allPhotoUrls)) ?>">
|
||||
<img src="<?= $escaper->escapeUrl($photo['thumb']) ?>" alt="">
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($canWriteReview): ?>
|
||||
<button class="esun-write-review-trigger" type="button" data-role="esun-write-review-trigger">
|
||||
<span><?= $escaper->escapeHtml(__('Write A Review')) ?></span>
|
||||
<span class="esun-write-review-trigger__arrow" aria-hidden="true"></span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="block-content esun-customer-reviews__content">
|
||||
<?php if (count($_items)): ?>
|
||||
<ol class="items review-items esun-review-items">
|
||||
<?php foreach ($_items as $_review): ?>
|
||||
<?php
|
||||
$reviewId = (int)$_review->getReviewId();
|
||||
$images = $imageBlock ? $imageBlock->getImages($reviewId) : [];
|
||||
$reviewMedia = array_map(static fn (array $media): array => [
|
||||
'type' => (string)($media['type'] ?? 'image'),
|
||||
'url' => (string)($media['url'] ?? ''),
|
||||
'thumb' => (string)($media['thumb'] ?? $media['url'] ?? ''),
|
||||
], $images);
|
||||
$reviewVotes = $votes[$reviewId] ?? ['up' => 0, 'down' => 0, 'customer_vote' => 0];
|
||||
$percent = (int)($reviewPercents[$reviewId] ?? 0);
|
||||
$reviewMeta = [
|
||||
'customer_id' => (int)$_review->getCustomerId(),
|
||||
];
|
||||
$customerName = $customerNames[(int)$reviewMeta['customer_id']] ?? (string)$_review->getNickname();
|
||||
$createdAt = $_review->getCreatedAt() ? date('Y.m.d', strtotime((string)$_review->getCreatedAt())) : '';
|
||||
?>
|
||||
<li class="item review-item esun-review-item" itemscope itemprop="review" itemtype="http://schema.org/Review">
|
||||
<div class="esun-review-item__heading">
|
||||
<span class="esun-review-item__avatar" aria-hidden="true"></span>
|
||||
<div class="esun-review-item__author">
|
||||
<strong itemprop="author"><?= $escaper->escapeHtml($customerName) ?></strong>
|
||||
<time itemprop="datePublished" datetime="<?= $escaper->escapeHtmlAttr($createdAt) ?>">
|
||||
<?= $escaper->escapeHtml($createdAt) ?>
|
||||
</time>
|
||||
</div>
|
||||
</div>
|
||||
<div class="esun-review-stars esun-review-item__stars" aria-label="<?= $escaper->escapeHtmlAttr(__('%1 out of 5 stars', round($percent / 20, 1))) ?>">
|
||||
<span class="esun-review-stars__base">★★★★★</span>
|
||||
<span class="esun-review-stars__fill" style="width: <?= (int)$percent ?>%;">★★★★★</span>
|
||||
</div>
|
||||
<div class="esun-review-item__content" itemprop="description">
|
||||
<?= /* @noEscape */ nl2br($escaper->escapeHtml($_review->getDetail())) ?>
|
||||
</div>
|
||||
<div class="esun-review-item__media-row">
|
||||
<?php if ($images): ?>
|
||||
<div class="esun-review-images" data-mage-init='{"Esun_Review/js/review-images":{}}'>
|
||||
<?php foreach ($images as $index => $image): ?>
|
||||
<?php if (($image['type'] ?? 'image') === 'video'): ?>
|
||||
<button class="esun-review-images__thumb esun-review-video-thumb"
|
||||
type="button"
|
||||
aria-label="<?= $escaper->escapeHtmlAttr(__('Play review video')) ?>"
|
||||
data-index="<?= (int)$index ?>"
|
||||
data-media="<?= $escaper->escapeHtmlAttr(json_encode($reviewMedia, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT)) ?>">
|
||||
<video preload="metadata" muted playsinline src="<?= $escaper->escapeUrl($image['url']) ?>"></video>
|
||||
<span class="esun-review-video-thumb__play" aria-hidden="true"></span>
|
||||
</button>
|
||||
<?php else: ?><button class="esun-review-images__thumb"
|
||||
type="button"
|
||||
data-index="<?= (int)$index ?>"
|
||||
data-media="<?= $escaper->escapeHtmlAttr(json_encode($reviewMedia, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT)) ?>">
|
||||
<img src="<?= $escaper->escapeUrl($image['thumb']) ?>" alt="">
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="esun-review-votes"
|
||||
data-review-id="<?= (int)$reviewId ?>"
|
||||
data-can-vote="<?= $reviewData && $reviewData->canVote($reviewMeta) ? '1' : '0' ?>">
|
||||
<button class="esun-review-vote<?= (int)$reviewVotes['customer_vote'] === 1 ? ' is-active' : '' ?>"
|
||||
type="button"
|
||||
data-vote-type="1"
|
||||
aria-label="<?= $escaper->escapeHtmlAttr(__('Thumb up')) ?>">
|
||||
<span class="esun-review-vote__icon">♡</span>
|
||||
<span data-role="vote-up-count"><?= (int)$reviewVotes['up'] ?></span>
|
||||
</button>
|
||||
<button class="esun-review-vote<?= (int)$reviewVotes['customer_vote'] === -1 ? ' is-active' : '' ?>"
|
||||
type="button"
|
||||
data-vote-type="-1"
|
||||
aria-label="<?= $escaper->escapeHtmlAttr(__('Thumb down')) ?>">
|
||||
<span class="esun-review-vote__icon">♡</span>
|
||||
<span data-role="vote-down-count"><?= (int)$reviewVotes['down'] ?></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
<div class="toolbar review-toolbar esun-review-toolbar"><?= $block->getChildHtml('toolbar') ?></div>
|
||||
<?php else: ?>
|
||||
<p class="esun-review-empty"><?= $escaper->escapeHtml(__('There are no reviews yet.')) ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/** @var \Magento\Review\Block\Form $block */
|
||||
/** @var \Magento\Framework\Escaper $escaper */
|
||||
$escaper = $escaper ?? $block;
|
||||
?>
|
||||
<form action="<?= $escaper->escapeUrl($block->getAction()) ?>"
|
||||
class="review-form"
|
||||
method="post"
|
||||
id="review-form"
|
||||
enctype="multipart/form-data"
|
||||
data-role="product-review-form"
|
||||
data-bind="scope: 'review-form'">
|
||||
<?= $block->getBlockHtml('formkey') ?>
|
||||
<?= $block->getChildHtml('form_fields_before') ?>
|
||||
<fieldset class="fieldset review-fieldset" data-hasrequired="<?= $escaper->escapeHtmlAttr(__('* Required Fields')) ?>">
|
||||
<?php if ($block->getRatings() && $block->getRatings()->getSize()): ?>
|
||||
<span id="input-message-box"></span>
|
||||
<fieldset class="field required review-field-ratings">
|
||||
<legend class="label"><span><?= $escaper->escapeHtml(__('Your Rating')) ?></span></legend><br/>
|
||||
<div class="control">
|
||||
<div class="nested" id="product-review-table">
|
||||
<?php foreach ($block->getRatings() as $_rating): ?>
|
||||
<div class="field choice review-field-rating">
|
||||
<label class="label" id="<?= $escaper->escapeHtmlAttr($_rating->getRatingCode()) ?>_rating_label"><span><?= $escaper->escapeHtml(__('Your Rating')) ?></span></label>
|
||||
<div class="control review-control-vote">
|
||||
<?php $options = $_rating->getOptions(); ?>
|
||||
<?php $iterator = 1; foreach ($options as $_option): ?>
|
||||
<input type="radio"
|
||||
name="ratings[<?= $escaper->escapeHtmlAttr($_rating->getId()) ?>]"
|
||||
id="<?= $escaper->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $escaper->escapeHtmlAttr($_option->getValue()) ?>"
|
||||
value="<?= $escaper->escapeHtmlAttr($_option->getId()) ?>"
|
||||
class="radio"
|
||||
data-validate="{'rating-required':true}"
|
||||
aria-labelledby="<?= $escaper->escapeHtmlAttr($_rating->getRatingCode()) ?>_rating_label <?= $escaper->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $escaper->escapeHtmlAttr($_option->getValue()) ?>_label" />
|
||||
<label class="rating-<?= $escaper->escapeHtmlAttr($iterator) ?>" for="<?= $escaper->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $escaper->escapeHtmlAttr($_option->getValue()) ?>" title="<?= $escaper->escapeHtmlAttr(__('%1 %2', $iterator, $iterator > 1 ? __('stars') : __('star'))) ?>" id="<?= $escaper->escapeHtmlAttr($_rating->getRatingCode()) ?>_<?= $escaper->escapeHtmlAttr($_option->getValue()) ?>_label"><span><?= $escaper->escapeHtml(__('%1 %2', $iterator, $iterator > 1 ? __('stars') : __('star'))) ?></span></label>
|
||||
<?php $iterator++; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<input type="hidden" name="validate_rating" class="validate-rating" value="" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endif ?>
|
||||
<div class="field review-field-nickname required esun-review-hidden-field">
|
||||
<div class="control"><input type="hidden" name="nickname" id="nickname_field" data-bind="value: nickname()" /></div>
|
||||
</div>
|
||||
<div class="field review-field-summary required esun-review-hidden-field">
|
||||
<div class="control"><input type="hidden" name="title" id="summary_field" /></div>
|
||||
</div>
|
||||
<div class="field review-field-text required">
|
||||
<label for="review_field" class="label"><span><?= $escaper->escapeHtml(__('Review')) ?></span></label>
|
||||
<div class="control"><textarea name="detail" id="review_field" cols="5" rows="3" data-validate="{required:true}" data-bind="value: review().detail"></textarea></div>
|
||||
</div>
|
||||
<div class="field review-field-images">
|
||||
<label for="review_images" class="label"><span><?= $escaper->escapeHtml(__('Images or Video')) ?></span></label>
|
||||
<div class="control">
|
||||
<input type="file"
|
||||
name="review_images[]"
|
||||
id="review_images"
|
||||
multiple
|
||||
accept="image/jpeg,image/png,image/gif,image/webp,video/mp4,video/webm,video/quicktime"
|
||||
onchange="window.esunRenderReviewImagePreview && window.esunRenderReviewImagePreview(this)">
|
||||
<div class="esun-review-upload-preview" data-role="review-image-preview"></div>
|
||||
<p class="note"><?= $escaper->escapeHtml(__('Upload JPG, PNG, GIF, WebP, MP4, WebM or MOV files.')) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="actions-toolbar review-form-actions">
|
||||
<div class="primary actions-primary">
|
||||
<button type="submit" class="action submit primary"><span><?= $escaper->escapeHtml(__('Submit Review')) ?></span></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
window.esunRenderReviewImagePreview = window.esunRenderReviewImagePreview || function (input) {
|
||||
var preview = input && input.form ? input.form.querySelector('[data-role="review-image-preview"]') : null,
|
||||
files = input && input.files ? Array.prototype.slice.call(input.files) : [];
|
||||
|
||||
if (!preview) {
|
||||
return;
|
||||
}
|
||||
preview.innerHTML = '';
|
||||
files.forEach(function (file) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
var image = document.createElement('img');
|
||||
image.src = event.target.result;
|
||||
image.alt = file.name || '';
|
||||
preview.appendChild(image);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<script type="text/x-magento-init">
|
||||
{
|
||||
"[data-role=product-review-form]": {
|
||||
"Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
|
||||
},
|
||||
"#review-form": {
|
||||
"Magento_Review/js/error-placement": {},
|
||||
"Magento_Review/js/validate-review": {},
|
||||
"Magento_Captcha/js/checkout/captcha": {}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \Magento\Review\Block\Product\ReviewRenderer $block
|
||||
* @var \Magento\Framework\Escaper $escaper
|
||||
*/
|
||||
?>
|
||||
<?php if ($block->isReviewEnabled()): ?>
|
||||
<?php
|
||||
$reviewsCount = (int)$block->getData('esun_reviews_count');
|
||||
$rating = (int)$block->getData('esun_rating_summary');
|
||||
$ratingValue = $rating > 0 ? number_format($rating / 20, 1) : '';
|
||||
$reviewsUrl = $block->getReviewsUrl() . '#reviews';
|
||||
?>
|
||||
<div class="product-reviews-summary<?= !$rating ? ' no-rating' : '' ?> esun-review-summary">
|
||||
<div class="rating-summary">
|
||||
<span class="label"><span><?= $escaper->escapeHtml(__('Rating')) ?>:</span></span>
|
||||
<div class="rating-result"
|
||||
id="rating-result_<?= $escaper->escapeHtmlAttr($block->getProduct()->getId()) ?>"
|
||||
title="<?= $escaper->escapeHtmlAttr((string)$rating) ?>%">
|
||||
<span style="width: <?= $escaper->escapeHtmlAttr((string)$rating) ?>%;"><span></span></span>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($reviewsCount > 0): ?>
|
||||
<a class="esun-review-summary__meta" href="<?= $escaper->escapeUrl($reviewsUrl) ?>">
|
||||
<span class="esun-review-summary__score"><?= $escaper->escapeHtml($ratingValue) ?></span>
|
||||
<span class="esun-review-summary__count">(<?= $escaper->escapeHtml((string)$reviewsCount) ?><?= $escaper->escapeHtml($reviewsCount === 1 ? __('Review') : __('Reviews')) ?>)</span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,547 @@
|
||||
.catalog-product-view
|
||||
.product-info-main
|
||||
.product-reviews-summary.esun-review-summary {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 0 0 18px;
|
||||
}
|
||||
|
||||
.esun-customer-reviews .action.primary,
|
||||
.esun-order-review-item .action.primary,
|
||||
.esun-awaiting-reviews .action.primary,
|
||||
.review-form .action.primary {
|
||||
background: #18aa59;
|
||||
background-image: none;
|
||||
border-color: #18aa59;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.esun-customer-reviews .action.primary:hover,
|
||||
.esun-customer-reviews .action.primary:focus,
|
||||
.esun-order-review-item .action.primary:hover,
|
||||
.esun-order-review-item .action.primary:focus,
|
||||
.esun-awaiting-reviews .action.primary:hover,
|
||||
.esun-awaiting-reviews .action.primary:focus,
|
||||
.review-form .action.primary:hover,
|
||||
.review-form .action.primary:focus {
|
||||
background: #148f4b;
|
||||
background-image: none;
|
||||
border-color: #148f4b;
|
||||
color: #fff;
|
||||
}
|
||||
.catalog-product-view
|
||||
.product-info-main
|
||||
.product-reviews-summary.esun-review-summary
|
||||
.rating-summary {
|
||||
display: flex;
|
||||
margin: 0;
|
||||
}
|
||||
.catalog-product-view
|
||||
.product-info-main
|
||||
.product-reviews-summary.esun-review-summary
|
||||
.rating-summary
|
||||
.label {
|
||||
display: none;
|
||||
}
|
||||
.catalog-product-view
|
||||
.product-info-main
|
||||
.product-reviews-summary.esun-review-summary
|
||||
.rating-result {
|
||||
margin: 0;
|
||||
}
|
||||
.catalog-product-view .product-info-main .esun-review-summary__meta {
|
||||
color: #888;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
text-decoration: none;
|
||||
}
|
||||
.catalog-product-view .product-info-main .esun-review-summary__score {
|
||||
margin-right: 4px;
|
||||
}
|
||||
.rating-summary .rating-result > span:before {
|
||||
color: #ffd800;
|
||||
}
|
||||
.catalog-product-view .esun-review-images {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin: 14px 0 0;
|
||||
}
|
||||
.catalog-product-view .esun-review-images__thumb {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
height: 72px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
position: relative;
|
||||
width: 72px;
|
||||
}
|
||||
.catalog-product-view .esun-review-images__thumb img,
|
||||
.catalog-product-view .esun-review-images__thumb video {
|
||||
border-radius: 6px;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
width: 100%;
|
||||
}
|
||||
.catalog-product-view .esun-review-video-thumb__play {
|
||||
align-items: center;
|
||||
background: rgba(0, 0, 0, 0.58);
|
||||
border: 2px solid #fff;
|
||||
border-radius: 50%;
|
||||
display: inline-flex;
|
||||
height: 30px;
|
||||
justify-content: center;
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 30px;
|
||||
}
|
||||
.catalog-product-view .esun-review-video-thumb__play:after {
|
||||
border-bottom: 6px solid transparent;
|
||||
border-left: 9px solid #fff;
|
||||
border-top: 6px solid transparent;
|
||||
content: "";
|
||||
margin-left: 2px;
|
||||
}
|
||||
.catalog-product-view .page-main-reviews {
|
||||
margin: 50px auto 0;
|
||||
padding: 0;;
|
||||
}
|
||||
.catalog-product-view .product-reviews-section .product-section-title,
|
||||
.catalog-product-view .esun-customer-reviews .product-section-title {
|
||||
border: 0;
|
||||
color: #333;
|
||||
font-size: 34px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 8px;
|
||||
line-height: 1.2;
|
||||
margin: 0 0 42px;
|
||||
position: relative;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.catalog-product-view .product-reviews-section .product-section-title:after,
|
||||
.catalog-product-view .esun-customer-reviews .product-section-title:after {
|
||||
background: #18a957;
|
||||
border-radius: 999px;
|
||||
bottom: -22px;
|
||||
content: "";
|
||||
height: 2px;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
width: 50px;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__header {
|
||||
align-items: flex-start;
|
||||
display: grid;
|
||||
gap: 28px;
|
||||
grid-template-columns: minmax(280px, 1fr) minmax(420px, 780px);
|
||||
margin-bottom: 36px;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__summary {
|
||||
min-width: 0;
|
||||
}
|
||||
.catalog-product-view .esun-review-stars {
|
||||
color: #cfcfcf;
|
||||
display: inline-block;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.catalog-product-view .esun-review-stars__base,
|
||||
.catalog-product-view .esun-review-stars__fill {
|
||||
display: block;
|
||||
}
|
||||
.catalog-product-view .esun-review-stars__fill {
|
||||
color: #ffd800;
|
||||
left: 0;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__score {
|
||||
color: #888;
|
||||
display: inline-flex;
|
||||
font-size: 15px;
|
||||
gap: 8px;
|
||||
margin-left: 20px;
|
||||
vertical-align: 2px;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__actions {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 36px;
|
||||
justify-content: flex-end;
|
||||
justify-self: end;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos-wrap {
|
||||
align-items: flex-end;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: auto;
|
||||
max-width: 580px;
|
||||
min-width: 0;
|
||||
text-align: right;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos-title {
|
||||
color: #333;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8px;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos {
|
||||
cursor: grab;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
justify-content: flex-end;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
user-select: none;
|
||||
width: max-content;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos.is-dragging {
|
||||
cursor: grabbing;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photo {
|
||||
flex: 0 0 88px;
|
||||
height: 88px;
|
||||
width: 88px;
|
||||
}
|
||||
.catalog-product-view .esun-write-review-trigger {
|
||||
align-items: center;
|
||||
align-self: center;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
color: #18a957;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
gap: 16px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.catalog-product-view .esun-write-review-trigger:hover,
|
||||
.catalog-product-view .esun-write-review-trigger:focus,
|
||||
.catalog-product-view .esun-write-review-trigger:active {
|
||||
background: transparent;
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
color: #18a957;
|
||||
outline: 0;
|
||||
}
|
||||
.catalog-product-view .esun-write-review-trigger__arrow {
|
||||
border-right: 2px solid #18a957;
|
||||
border-top: 2px solid #18a957;
|
||||
height: 7px;
|
||||
transform: rotate(45deg);
|
||||
width: 7px;
|
||||
}
|
||||
.catalog-product-view .esun-review-items {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.catalog-product-view .esun-review-item {
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
margin: 0;
|
||||
padding: 24px 0 28px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__heading {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__avatar {
|
||||
background: #b7b7b7;
|
||||
border-radius: 50%;
|
||||
flex: 0 0 32px;
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__author {
|
||||
display: grid;
|
||||
gap: 2px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__author strong {
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__author time {
|
||||
color: #777;
|
||||
font-size: 13px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__stars {
|
||||
display: inline-block;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__content {
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
line-height: 1.55;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__media-row {
|
||||
align-items: flex-end;
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.catalog-product-view .esun-review-votes {
|
||||
align-items: center;
|
||||
display: inline-flex;
|
||||
gap: 12px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.catalog-product-view .esun-review-vote {
|
||||
align-items: center;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
color: #333;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
font-size: 13px;
|
||||
gap: 4px;
|
||||
padding: 0;
|
||||
}
|
||||
.catalog-product-view .esun-review-votes[data-can-vote="0"] .esun-review-vote {
|
||||
cursor: default;
|
||||
}
|
||||
.catalog-product-view .esun-review-vote.is-active {
|
||||
color: #18a957;
|
||||
}
|
||||
.catalog-product-view
|
||||
.esun-review-vote[data-vote-type="-1"]
|
||||
.esun-review-vote__icon {
|
||||
display: inline-block;
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar {
|
||||
border-top: 0;
|
||||
margin-top: 28px;
|
||||
text-align: center;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .pages {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .toolbar-amount,
|
||||
.catalog-product-view .esun-review-toolbar .limiter {
|
||||
display: none;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .pages {
|
||||
align-items: center;
|
||||
display: inline-flex;
|
||||
gap: 24px;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .pages-items {
|
||||
align-items: center;
|
||||
display: inline-flex;
|
||||
gap: 20px;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .item a,
|
||||
.catalog-product-view .esun-review-toolbar .item strong {
|
||||
align-items: center;
|
||||
background: #cfe8dc;
|
||||
border-radius: 999px;
|
||||
color: transparent;
|
||||
display: inline-flex;
|
||||
height: 8px;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
text-decoration: none;
|
||||
width: 8px;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .item.current strong {
|
||||
background: #18a957;
|
||||
height: 8px;
|
||||
width: 30px;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .item.pages-item-previous a,
|
||||
.catalog-product-view .esun-review-toolbar .item.pages-item-next a {
|
||||
background: transparent;
|
||||
border-right: 2px solid #18a957;
|
||||
border-top: 2px solid #18a957;
|
||||
border-radius: 0;
|
||||
height: 10px;
|
||||
width: 10px;
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .item.pages-item-previous a {
|
||||
transform: rotate(-135deg);
|
||||
}
|
||||
.catalog-product-view .esun-review-toolbar .item.pages-item-next a {
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
.catalog-product-view .esun-review-form-modal {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
inset: 0;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
position: fixed;
|
||||
z-index: 1002;
|
||||
}
|
||||
.catalog-product-view .esun-review-form-modal[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.catalog-product-view .esun-review-form-modal__overlay {
|
||||
background: rgba(0, 0, 0, 0.58);
|
||||
inset: 0;
|
||||
position: absolute;
|
||||
}
|
||||
.catalog-product-view .esun-review-form-modal__dialog {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
max-height: calc(100vh - 48px);
|
||||
max-width: 720px;
|
||||
overflow: auto;
|
||||
padding: 32px;
|
||||
position: relative;
|
||||
width: min(720px, 100%);
|
||||
z-index: 1;
|
||||
}
|
||||
.catalog-product-view .esun-review-form-modal__close {
|
||||
align-items: center;
|
||||
background: #111;
|
||||
border: 2px solid #fff;
|
||||
border-radius: 50%;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
font-size: 28px;
|
||||
height: 40px;
|
||||
justify-content: center;
|
||||
line-height: 40px;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
top: 12px;
|
||||
width: 40px;
|
||||
}
|
||||
.catalog-product-view .esun-review-hidden-field,
|
||||
.catalog-product-view .review-field-rating > .label {
|
||||
display: none;
|
||||
}
|
||||
.catalog-product-view .esun-review-upload-preview {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.catalog-product-view .esun-review-upload-preview img {
|
||||
border-radius: 6px;
|
||||
height: 72px;
|
||||
object-fit: cover;
|
||||
width: 72px;
|
||||
}
|
||||
.esun-review-lightbox {
|
||||
align-items: center;
|
||||
background: rgba(0, 0, 0, 0.62);
|
||||
display: flex;
|
||||
inset: 0;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
}
|
||||
.esun-review-lightbox[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.esun-review-lightbox__image {
|
||||
border-radius: 8px;
|
||||
max-height: min(90vh, 680px);
|
||||
max-width: min(90vw, 680px);
|
||||
object-fit: contain;
|
||||
}
|
||||
.esun-review-lightbox__video {
|
||||
background: #000;
|
||||
border-radius: 8px;
|
||||
max-height: 90vh;
|
||||
max-width: 90vw;
|
||||
width: min(90vw, 960px);
|
||||
}
|
||||
.esun-review-lightbox__image[hidden],
|
||||
.esun-review-lightbox__video[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.esun-review-lightbox__close,
|
||||
.esun-review-lightbox__prev,
|
||||
.esun-review-lightbox__next {
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border: 1px solid #18a957;
|
||||
border-radius: 999px;
|
||||
color: #18a957;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
font-size: 30px;
|
||||
height: 44px;
|
||||
justify-content: center;
|
||||
line-height: 0.8;
|
||||
position: fixed;
|
||||
width: 44px;
|
||||
}
|
||||
.esun-review-lightbox__close {
|
||||
background: #1d0e0d;
|
||||
border: 3px solid #fff;
|
||||
color: #fff;
|
||||
right: 24px;
|
||||
top: 24px;
|
||||
}
|
||||
.esun-review-lightbox__prev {
|
||||
left: 24px;
|
||||
top: 50%;
|
||||
}
|
||||
.esun-review-lightbox__next {
|
||||
right: 24px;
|
||||
top: 50%;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.catalog-product-view .esun-customer-reviews__header {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__actions {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
justify-content: flex-start;
|
||||
justify-self: stretch;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos-wrap {
|
||||
align-items: flex-start;
|
||||
margin-left: 0;
|
||||
max-width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
.catalog-product-view .esun-customer-reviews__photos {
|
||||
justify-content: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
.catalog-product-view .product-reviews-section .product-section-title,
|
||||
.catalog-product-view .esun-customer-reviews .product-section-title {
|
||||
font-size: 20px;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
.catalog-product-view .esun-review-item__media-row {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
.catalog-product-view .esun-review-votes {
|
||||
align-self: flex-end;
|
||||
}
|
||||
}
|
||||
.catalog-product-view .esun-review-item:last-child{border-bottom:0}.esun-order-review-item{padding:16px 0;border-bottom:1px solid #ddd}.esun-order-review-status{margin-left:12px;color:#666}.esun-order-review-item details{margin-top:12px}.esun-order-review-item summary{display:inline-block;cursor:pointer}.esun-order-review-item form{margin-top:16px;max-width:720px}
|
||||
@@ -0,0 +1,47 @@
|
||||
define([
|
||||
'jquery'
|
||||
], function ($) {
|
||||
'use strict';
|
||||
|
||||
function loadReviews(url, fromPages) {
|
||||
$.ajax({
|
||||
url: url,
|
||||
cache: true,
|
||||
dataType: 'html',
|
||||
showLoader: false,
|
||||
loaderContext: $('.product-reviews-section')
|
||||
}).done(function (data) {
|
||||
$('#product-review-container').html(data).trigger('contentUpdated');
|
||||
$('[data-role="product-review"] .pages a').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
loadReviews($(this).attr('href'), true);
|
||||
});
|
||||
}).always(function () {
|
||||
if (fromPages) {
|
||||
$('html, body').animate({
|
||||
scrollTop: $('#reviews').offset().top - 50
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return function (config) {
|
||||
$(function () {
|
||||
if (config.productReviewUrl) {
|
||||
loadReviews(config.productReviewUrl, location.hash === '#reviews');
|
||||
}
|
||||
|
||||
$('.product-info-main .reviews-actions a').on('click', function (event) {
|
||||
var anchor = $(this).attr('href').replace(/^.*?(#|$)/, ''),
|
||||
target = $('#' + anchor);
|
||||
|
||||
if (target.length) {
|
||||
event.preventDefault();
|
||||
$('html, body').animate({
|
||||
scrollTop: target.offset().top - 50
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
define(['jquery', 'mage/translate'], function ($, $t) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $root = $(element),
|
||||
$modal = $root.find('[data-role="esun-review-form-modal"]');
|
||||
|
||||
function openModal() {
|
||||
if (!$modal.length) {
|
||||
return;
|
||||
}
|
||||
$modal.removeAttr('hidden');
|
||||
$('body').addClass('esun-review-form-modal-open');
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
if (!$modal.length) {
|
||||
return;
|
||||
}
|
||||
$modal.attr('hidden', true);
|
||||
$('body').removeClass('esun-review-form-modal-open');
|
||||
}
|
||||
|
||||
$root.on('click', '[data-role="esun-write-review-trigger"]', openModal);
|
||||
$root.on('click', '[data-role="esun-review-form-close"]', closeModal);
|
||||
|
||||
$(document).on('keyup.esunReviewFormModal', function (event) {
|
||||
if (event.key === 'Escape') {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
function renderImagePreview(input) {
|
||||
var files = Array.prototype.slice.call(input.files || []),
|
||||
$preview = $(input).closest('form').find('[data-role="review-image-preview"]');
|
||||
|
||||
$preview.empty();
|
||||
$.each(files, function (index, file) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
$('<img/>', {
|
||||
src: event.target.result,
|
||||
alt: file.name
|
||||
}).appendTo($preview);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
|
||||
$root.on('change', '#review_images', function () {
|
||||
renderImagePreview(this);
|
||||
});
|
||||
|
||||
$(document)
|
||||
.off('change.esunReviewImages', '#review_images')
|
||||
.on('change.esunReviewImages', '#review_images', function () {
|
||||
renderImagePreview(this);
|
||||
});
|
||||
|
||||
$root.on('submit', '#review-form', function () {
|
||||
var $form = $(this),
|
||||
detail = $.trim($form.find('#review_field').val() || ''),
|
||||
nickname = $.trim($form.find('#nickname_field').val() || '');
|
||||
|
||||
if (!nickname) {
|
||||
nickname = $.trim($('.customer-name, .logged-in').first().text()) || $t('Customer');
|
||||
$form.find('#nickname_field').val(nickname);
|
||||
}
|
||||
|
||||
$form.find('#summary_field').val(detail.substring(0, 120) || $t('Review'));
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,104 @@
|
||||
define(['jquery'], function ($) {
|
||||
'use strict';
|
||||
|
||||
var $modal;
|
||||
|
||||
function ensureModal() {
|
||||
if ($modal) {
|
||||
return $modal;
|
||||
}
|
||||
|
||||
$modal = $('<div/>', {'class': 'esun-review-lightbox', hidden: true})
|
||||
.append($('<button/>', {'class': 'esun-review-lightbox__close', type: 'button', text: '×'}))
|
||||
.append($('<button/>', {'class': 'esun-review-lightbox__prev', type: 'button', text: '‹'}))
|
||||
.append($('<img/>', {'class': 'esun-review-lightbox__image', alt: ''}))
|
||||
.append($('<video/>', {
|
||||
'class': 'esun-review-lightbox__video',
|
||||
controls: true,
|
||||
hidden: true,
|
||||
playsinline: true,
|
||||
preload: 'metadata'
|
||||
}))
|
||||
.append($('<button/>', {'class': 'esun-review-lightbox__next', type: 'button', text: '›'}))
|
||||
.appendTo(document.body);
|
||||
|
||||
$modal.on('click', '.esun-review-lightbox__close', close);
|
||||
$modal.on('click', '.esun-review-lightbox__prev', function () {
|
||||
show(($modal.data('index') || 0) - 1);
|
||||
});
|
||||
$modal.on('click', '.esun-review-lightbox__next', function () {
|
||||
show(($modal.data('index') || 0) + 1);
|
||||
});
|
||||
|
||||
return $modal;
|
||||
}
|
||||
|
||||
function stopVideo() {
|
||||
var video = $modal && $modal.find('.esun-review-lightbox__video').get(0);
|
||||
|
||||
if (!video) {
|
||||
return;
|
||||
}
|
||||
video.pause();
|
||||
video.removeAttribute('src');
|
||||
video.load();
|
||||
}
|
||||
|
||||
function show(index) {
|
||||
var media = $modal.data('media') || [],
|
||||
item,
|
||||
video;
|
||||
|
||||
if (!media.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
index = (index + media.length) % media.length;
|
||||
$modal.data('index', index);
|
||||
item = media[index];
|
||||
|
||||
if (item.type === 'video') {
|
||||
$modal.find('.esun-review-lightbox__image').attr('hidden', true).removeAttr('src');
|
||||
video = $modal.find('.esun-review-lightbox__video')
|
||||
.removeAttr('hidden')
|
||||
.attr('src', item.url)
|
||||
.get(0);
|
||||
video.load();
|
||||
video.play().catch(function () {});
|
||||
return;
|
||||
}
|
||||
|
||||
stopVideo();
|
||||
$modal.find('.esun-review-lightbox__video').attr('hidden', true);
|
||||
$modal.find('.esun-review-lightbox__image').removeAttr('hidden').attr('src', item.url);
|
||||
}
|
||||
|
||||
function close() {
|
||||
stopVideo();
|
||||
$modal.attr('hidden', true);
|
||||
}
|
||||
|
||||
function getMedia($button) {
|
||||
var media = $button.data('media'),
|
||||
images;
|
||||
|
||||
if (Array.isArray(media)) {
|
||||
return media;
|
||||
}
|
||||
images = $button.data('images') || [];
|
||||
return images.map(function (url) {
|
||||
return {type: 'image', url: url, thumb: url};
|
||||
});
|
||||
}
|
||||
|
||||
return function (config, element) {
|
||||
$(element).on('click', '.esun-review-images__thumb', function () {
|
||||
var $button = $(this),
|
||||
media = getMedia($button);
|
||||
|
||||
ensureModal();
|
||||
$modal.data('media', media).attr('hidden', false);
|
||||
show(parseInt($button.data('index'), 10) || 0);
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
define(['jquery'], function ($) {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var $root = $(element),
|
||||
voteUrl = config.voteUrl || '';
|
||||
|
||||
$root.on('click', '.esun-review-vote', function () {
|
||||
var $button = $(this),
|
||||
$votes = $button.closest('.esun-review-votes'),
|
||||
reviewId = parseInt($votes.data('review-id'), 10) || 0,
|
||||
voteType = parseInt($button.data('vote-type'), 10) || 0;
|
||||
|
||||
if (!voteUrl || !reviewId || $votes.data('can-vote') !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: voteUrl,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
review_id: reviewId,
|
||||
vote_type: voteType,
|
||||
form_key: $('input[name="form_key"]').first().val() || ($.mage && $.mage.cookies ? $.mage.cookies.get('form_key') : '')
|
||||
}
|
||||
}).done(function (response) {
|
||||
if (!response || !response.success) {
|
||||
return;
|
||||
}
|
||||
|
||||
$votes.find('[data-role="vote-up-count"]').text(response.up || 0);
|
||||
$votes.find('[data-role="vote-down-count"]').text(response.down || 0);
|
||||
$votes.find('.esun-review-vote').removeClass('is-active');
|
||||
$votes.find('[data-vote-type="' + response.customer_vote + '"]').addClass('is-active');
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user