提交 e781bd7b 编写于 作者: R root

product review section

上级 3e821ca4
......@@ -31,6 +31,7 @@ class Index {
'name' => Yii::$service->store->getStoreAttrVal($this->_product['name'],'name'),
'image' => $this->_product['image'],
'sku' => $this->_product['sku'],
'spu' => $this->_product['spu'],
'price_info' => $this->getProductPriceInfo(),
'tier_price' => $this->_product['tier_price'],
'media_size' => [
......@@ -42,7 +43,8 @@ class Index {
'options' => $this->getSameSpuInfo(),
'custom_option' => $this->_product['custom_option'],
'description' => Yii::$service->store->getStoreAttrVal($this->_product['description'],'description'),
'_id' => $this->_product['_id'],
'review_count' => Yii::$service->product->review->getCountBySpu($this->_product['spu']),
];
}
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\modules\Catalog\block\reviewproduct;
use Yii;
use fec\helpers\CModule;
use fec\helpers\CRequest;
use yii\base\InvalidValueException;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Add {
public function getLastData(){
$_id = Yii::$app->request->get('_id');
if(!$_id){
Yii::$service->page->message->addError('product _id is empty');
return [];
}
$product = Yii::$service->product->getByPrimaryKey($_id);
if(!$product['spu']){
Yii::$service->page->message->addError('product _id:'.$_id.' is not exist in product collection');
return [];
}
$price_info = $this->getProductPriceInfo($product);
$spu = $product['spu'];
$image = $product['image'];
$main_img = isset($image['main']['image']) ? $image['main']['image'] : '';
$url_key = $product['url_key'];
$name = Yii::$service->store->getStoreAttrVal($product['name'],'name');
return [
'name' => $name,
'spu' => $spu,
'price_info' => $price_info,
'main_img' => $main_img,
'url' => Yii::$service->url->getUrl($url_key),
];
}
protected function getProductPriceInfo($product){
$price = $product['price'];
$special_price = $product['special_price'];
$special_from = $product['special_from'];
$special_to = $product['special_to'];
return Yii::$service->product->price->getCurrentCurrencyProductPriceInfo($price,$special_price,$special_from,$special_to);
}
protected function getSpuData(){
$spu = $this->_product['spu'];
$filter = [
'select' => ['size',],
'where' => [
['spu' => $spu],
],
'asArray' => true,
];
$coll = Yii::$service->product->coll($filter);
if(is_array($coll['coll']) && !empty($coll['coll'])){
foreach($coll['coll'] as $one){
$spu = $one['spu'];
}
}
}
}
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appfront\modules\Catalog\controllers;
use Yii;
use fec\helpers\CModule;
use fec\helpers\CRequest;
use fecshop\app\appfront\modules\AppfrontController;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class ReviewproductController extends AppfrontController
{
public function init(){
parent::init();
Yii::$service->page->theme->layoutFile = 'product_view.php';
}
#
public function actionAdd()
{
//echo 1;exit;
$data = $this->getBlock()->getLastData();
return $this->render($this->action->id,$data);
}
}
......@@ -3,7 +3,7 @@ body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset,
body {color: #333;font: 1em/1.55 Verdana,Arial,Helvetica,sans-serif;}
a{color: #666;text-decoration: none;}
ol, ul {list-style: outside none none;}
img{border:none;}
h1, h2, h3, h4, h5, h6 {
color: #444;
font-family: Bitter,Myriad Pro,Verdana,serif;
......@@ -844,6 +844,7 @@ button{
margin-left: -3px;
padding: 0;
background:none;
height:auto;
}
button.redBtn:hover{
background:none;
......@@ -1512,11 +1513,6 @@ td:nth-child(2n) {
#review_description li{
width:940px;
border-bottom:1px solid #ccc;
padding:15px 0 ;
}
.review_description_left a span{
display: block;
height: 32px;
......@@ -1682,10 +1678,6 @@ border: solid 1px #adadad;
width:44px;float:right;height:28px;margin-right:5px;
}
#review_description {
border-top: 1px solid #ccc;
}
.fieldset {
background: #fefefe none repeat scroll 0 0;
......@@ -1929,8 +1921,6 @@ border-bottom:1px solid #bbb;
a.pre_images {
background: rgba(0, 0, 0, 0) url("../images/tag.png") no-repeat scroll -104px -80px;
border-radius: 0;
......@@ -1974,12 +1964,9 @@ a.next_images {
.product_info{
.product_description_info{
list-style:none;
margin:0;
margin:25px 0 ;
padding:0;
text-decoration:none;
font-family:'Microsoft YaHei';
......@@ -1987,7 +1974,7 @@ a.next_images {
}
.product_info li {
.product_description_info #nav-container li {
border-right: 2px solid #eee;
cursor: pointer;
float: left;
......@@ -2000,28 +1987,218 @@ a.next_images {
}
.product_info ul{
.product_description_info #nav-container ul{
width:1200px;
margin:0 auto;
}
.product_info .nav{
.product_description_info .nav{
height:52px;
width:100%;
background:#f5f5f5;
}
.product_info .nav .cur{
.product_description_info .nav .cur{
background:#fff;
border-top:2px solid #1a92cf;
color:#1a92cf;
}
.product_info .fixed{
.product_description_info .fixed{
position:fixed;
top:0;
top:0;
left:0;
z-index:999999999;
}
.product_info a{
.product_description_info #nav-container a{
color:#505050;
}
.product_page{font-size:12px;}
.product_description_info #text{padding:20px 10px;}
.scroll_left a {
color: #4c6b99;
font-family: Georgia;
font-size: 19px;
line-height: 40px;
text-decoration: none;
}
.scroll_horizontal {
padding: 30px 0 10px;
position: relative;
width: 100%;
}
.product-Reviews .scroll_horizontal .box {
padding: 15px 0 0;
}
.scroll_horizontal .box {
border-top: 1px solid #ccc;
margin: 0 auto;
overflow: hidden;
padding: 10px 0 0;
position: relative;
width: 1170px;
}
.product-Reviews_top {
padding: 20px 0 20px 10px;
width: 100%;
}
.view_all_review {
background: #eee none repeat scroll 0 0;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
color: #fff;
height: 22px;
margin: 15px 0;
text-align: center;
}
#review_description li{
border-bottom: 1px solid #ddd;
margin-bottom:15px;
}
.view_all_review a {
color: #333;
line-height: 20px;
}
.review_description_left a {
color: #000;
text-decoration: none;
}
.product-Reviews_top a {
font-family: Georgia;
text-transform: uppercase;
}
.review_star_5 {
background: rgba(0, 0, 0, 0) url("../images/Star_5.png") no-repeat scroll 0 0;
}
.review_star {
display: block;
height: 15px;
width: 69px;
}
.currentprice {
color: #4c6b99;
font-size: 16px;
}
.product-description_em {
color: #cc0000;
font: 17px/12px Segoeui,Arial,Verdana,serif;
margin: 0 3px;
}
.star_1, .star_2, .star_3, .star_4, .star_5 {
background: rgba(0, 0, 0, 0) url("../images/product_rating_big_blank_star.png") repeat scroll 0 0;
display: block;
height: 30px;
width: 30px;
}
.full_star {
background: rgba(0, 0, 0, 0) url("../images/product_rating_big_full_star.png") repeat scroll 0 0;
}
#reviews_form_list li {
float: left;
margin-top: 10px;
width: 360px;
}
#reviews_form_list label {
color: #707070;
font: bold 11px/13px Segoeui-Bold,Myriad Pro,Verdana,serif;
}
.review_span_error {
color: #f00;
display: block;
height: 20px;
}
#reviews_form_list select {
width: 336px;
background: #fff none repeat scroll 0 0;
border: 1px solid #ccc;
border-radius: 2px;
color: #444;
display: inline-block;
font: 12px/33px Segoeui,Arial,Verdana,serif;
height: 33px;
overflow: hidden;
padding-left: 10px;
position: relative;
text-decoration: none !important;
text-overflow: ellipsis;
white-space: nowrap;
}
#review_review_field {
border: 1px solid #ccc;
border-radius: 2px;
color: #777;
height: 100px;
padding: 0 10px;
resize: none;
width: 676px;
}
.verification_code_input {
height: 30px;
padding: 0 10px;
width: 86px;
}
.product-Reviews_bottom button {
margin: 8px 0 0;
}
......
<div class="main container one-column">
<div class="col-main">
<div class="product_view">
<div class="product_info">
<h1><?= $name; ?></h1>
<div>
<div class="rbc_cold">
<span>
<span class="average_rating">Average rating :</span>
<span class="review_star review_star_4" style="font-weight:bold;" itemprop="average">0</span>
<a rel="nofollow" href="http://www.intosmile.com/fashion-solid-color-long-sleeve-round-neck-dress-1-1-1-1-1.html">
(<span itemprop="count">0 reviews</span>)
</a>
</span>
</div>
</div>
<div class="item_code">Item Code: <?= $sku; ?></div>
<div class="price_info">
<?php # 价格部分
$priceView = [
'view' => 'catalog/product/index/price.php'
];
$priceParam = [
'price_info' => $price_info,
];
?>
<?= Yii::$service->page->widget->render($priceView,$priceParam); ?>
<div class="product_page">
<div class="product_view">
</div>
<div style="height:300px;">
<div class="product_options">
<?php # options部分
$optionsView = [
'view' => 'catalog/product/index/options.php'
];
$optionsParam = [
'options' => $options,
];
?>
<?= Yii::$service->page->widget->render($optionsView,$optionsParam); ?>
<div class="product_info">
<h1><?= $name; ?></h1>
<div>
<div class="rbc_cold">
<span>
<span class="average_rating">Average rating :</span>
<span class="review_star review_star_4" style="font-weight:bold;" itemprop="average">0</span>
<a rel="nofollow" href="http://www.intosmile.com/fashion-solid-color-long-sleeve-round-neck-dress-1-1-1-1-1.html">
(<span itemprop="count">0 reviews</span>)
</a>
</span>
</div>
</div>
<div class="product_custom_options">
<?php # custom options部分
$optionsView = [
'view' => 'catalog/product/index/custom_option.php'
<div class="item_code">Item Code: <?= $sku; ?></div>
<div class="price_info">
<?php # 价格部分
$priceView = [
'view' => 'catalog/product/index/price.php'
];
$optionsParam = [
'custom_option' => $custom_option,
$priceParam = [
'price_info' => $price_info,
];
?>
<?= Yii::$service->page->widget->render($optionsView,$optionsParam); ?>
<?= Yii::$service->page->widget->render($priceView,$priceParam); ?>
</div>
<div class="product_qty pg">
<div class="label">Qty:</div>
<div class="rg">
<input type="text" name="qty" class="qty" value="1" />
<div style="height:300px;">
<div class="product_options">
<?php # options部分
$optionsView = [
'view' => 'catalog/product/index/options.php'
];
$optionsParam = [
'options' => $options,
];
?>
<?= Yii::$service->page->widget->render($optionsView,$optionsParam); ?>
</div>
<div class="product_custom_options">
<?php # custom options部分
$optionsView = [
'view' => 'catalog/product/index/custom_option.php'
];
$optionsParam = [
'custom_option' => $custom_option,
];
?>
<?= Yii::$service->page->widget->render($optionsView,$optionsParam); ?>
</div>
<div class="clear"></div>
</div>
<div class="addtocart">
<button type="button" id="js_registBtn" class="redBtn"><em><span><i></i>Add To Cart</span></em></button>
<div class="myFavorite_nohove" id="myFavorite">
<a href="javascript:void(0);" class="addheart" id="divMyFavorite" rel="nofollow" onclick="addFavorite(this)" value="http://www.intosmile.fr/favorite/product/add?sku=gyxh0682" url="">
Add to Favorites
</a>
<div class="product_qty pg">
<div class="label">Qty:</div>
<div class="rg">
<input type="text" name="qty" class="qty" value="1" />
</div>
<div class="clear"></div>
</div>
<div class="addtocart">
<button type="button" id="js_registBtn" class="redBtn"><em><span><i></i>Add To Cart</span></em></button>
<div class="myFavorite_nohove" id="myFavorite">
<a href="javascript:void(0);" class="addheart" id="divMyFavorite" rel="nofollow" onclick="addFavorite(this)" value="http://www.intosmile.fr/favorite/product/add?sku=gyxh0682" url="">
Add to Favorites
</a>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<div class="tier_price_info">
<?php # tier price 部分。
$priceView = [
'view' => 'catalog/product/index/tier_price.php'
];
$priceParam = [
'tier_price' => $tier_price,
];
?>
<?= Yii::$service->page->widget->render($priceView,$priceParam); ?>
</div>
</div>
<div class="tier_price_info">
<?php # tier price 部分。
$priceView = [
'view' => 'catalog/product/index/tier_price.php'
];
$priceParam = [
'tier_price' => $tier_price,
];
?>
<?= Yii::$service->page->widget->render($priceView,$priceParam); ?>
<div class="media_img">
<div class="col-left ">
<?php # 图片部分。
$imageView = [
'view' => 'catalog/product/index/image.php'
];
$imageParam = [
'media_size' => $media_size,
'image' => $image,
'productImgMagnifier' => $productImgMagnifier,
];
?>
<?= Yii::$service->page->widget->render($imageView,$imageParam); ?>
</div>
</div>
<div class="clear"></div>
</div>
<div class="media_img">
<div class="col-left ">
<?php # 图片部分。
$imageView = [
'view' => 'catalog/product/index/image.php'
];
$imageParam = [
'media_size' => $media_size,
'image' => $image,
'productImgMagnifier' => $productImgMagnifier,
];
?>
<?= Yii::$service->page->widget->render($imageView,$imageParam); ?>
</div>
<div class="product_description_info">
<div class="nav" id="nav-container">
<ul id="nav-box">
<li class="nav_tab cur" rel="description">DESCRIPTION</li>
<li class="nav_tab" rel="reviews">REVIEWS</li>
<li class="nav_tab" rel="questions">SHIPPING & PAYMENT</li>
<li class="nav_tab" rel="wholesale">WHOLESALE</li>
</ul>
</div>
<div id="text">
<div class="text-description" style="">
<?= $description; ?>
</div>
<div class="text-reviews" style="">
<?php # review部分。
$reviewView = [
'view' => 'catalog/product/index/review.php'
];
$reviewParam = [
'_id' => $_id,
'review_count' => $review_count,
'spu' => $spu,
];
?>
<?= Yii::$service->page->widget->render($reviewView,$reviewParam); ?>
</div>
<div class="text-questions" style="width:100%;height:500px;background:blue;text-align:center;">text3</div>
<div class="text-wholesale" style="width:100%;height:500px;background:yellow;text-align:center;">text2</div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="product_info">
<div class="nav" id="nav-container">
<ul id="nav-box">
<li class="nav_tab cur" rel="description">DESCRIPTION</li>
<li class="nav_tab" rel="reviews">REVIEWS</li>
<li class="nav_tab" rel="questions">QUESTIONS</li>
<li class="nav_tab" rel="wholesale">WHOLESALE</li>
</ul>
</div>
<div id="text">
<div class="text-description" style="width:100%;height:500px;background:green;text-align:center;">text1</div>
<div class="text-reviews" style="width:100%;height:500px;background:yellow;text-align:center;">text2</div>
<div class="text-questions" style="width:100%;height:500px;background:blue;text-align:center;">text3</div>
<div class="text-wholesale" style="width:100%;height:500px;background:yellow;text-align:center;">text2</div>
</div>
</div>
<div class="proList">
</div>
</div>
</div>
<script>
<?php $this->beginBlock('add_to_cart') ?>
// add to cart js
<?php $this->beginBlock('add_to_cart') ?>
$(document).ready(function(){
$("#js_registBtn").click(function(){
$(this).addClass("dataUp");
});
});
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['add_to_cart'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
<?php $this->beginBlock('product_info_tab') ?>
//tab 切换js
<?php $this->beginBlock('product_info_tab') ?>
var navContainer = document.getElementById("nav-container");
var navBox = document.getElementById("nav-box");
var text = document.getElementById("text");
......@@ -170,43 +184,36 @@
}
}
};
for(var i=0;i<navBoxChild.length;i++){
var interval;
navBoxChild[i].index = i;
navBoxChild[i].onclick = function(){
var self = this;
clearInterval(interval);
if(document.body.scrollTop){
scroll = document.body;
}else if(document.documentElement.scrollTop){
scroll = document.documentElement;
}
interval = setInterval(function(){
if(scroll.scrollTop + a<=textChild[self.index].offsetTop){
scroll.scrollTop += 40;
if(scroll.scrollTop + a>=textChild[self.index].offsetTop){
scroll.scrollTop = textChild[self.index].offsetTop-a;
clearInterval(interval);
}
}else{
scroll.scrollTop /= 1.1;
if(scroll.scrollTop + a<=textChild[self.index].offsetTop){
scroll.scrollTop = textChild[self.index].offsetTop-a;
clearInterval(interval);
}
}
},40);
};
}
for(var i=0;i<navBoxChild.length;i++){
var interval;
navBoxChild[i].index = i;
navBoxChild[i].onclick = function(){
var self = this;
clearInterval(interval);
if(document.body.scrollTop){
scroll = document.body;
}else if(document.documentElement.scrollTop){
scroll = document.documentElement;
}
interval = setInterval(function(){
if(scroll.scrollTop + a<=textChild[self.index].offsetTop){
scroll.scrollTop += 40;
if(scroll.scrollTop + a>=textChild[self.index].offsetTop){
scroll.scrollTop = textChild[self.index].offsetTop-a;
clearInterval(interval);
}
}else{
scroll.scrollTop /= 1.1;
if(scroll.scrollTop + a<=textChild[self.index].offsetTop){
scroll.scrollTop = textChild[self.index].offsetTop-a;
clearInterval(interval);
}
}
},40);
};
}
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['product_info_tab'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
......
<?php
$_id = $parentThis['_id'];
$review_count = $parentThis['review_count'];
$spu = $parentThis['spu'];
$_id = $parentThis['_id'];
?>
<div class="product-Reviews">
<div id="pic_list_2" class="scroll_horizontal">
<div class="scroll_left">
<a href="">Product Review</a>
</div>
<div class="clear"></div>
<div class="box">
<div class="product-Reviews_top">
<ul id="review_description">
<li>
<div class="review_description_left">
<a href="#" class="review_star review_star_5" onclick="javascript:return false;"></a>
<p>By fashion</p>
<span>2016-10-25 10:06:43</span>
</div>
<div class="review_description_right">
<input id="review_url_407" value="http://www.intosmile.com/review/product/addreply?id=407" type="hidden">
<span class="review_description_right_span"><b>good</b></span>
<div class="review_description_centen">
<div class="addsize"></div>
<br>
<div class="review-content">
i like this sweater
</div>
<br>
</div>
</div>
<div class="clear"></div>
</li>
<li>
<div class="review_description_left">
<a href="#" class="review_star review_star_5" onclick="javascript:return false;"></a>
<p>By fashion</p>
<span>2016-10-25 10:06:43</span>
</div>
<div class="review_description_right">
<input id="review_url_407" value="http://www.intosmile.com/review/product/addreply?id=407" type="hidden">
<span class="review_description_right_span"><b>good</b></span>
<div class="review_description_centen">
<div class="addsize"></div>
<br>
<div class="review-content">
i like this sweater
</div>
<br>
</div>
</div>
<div class="clear"></div>
</li>
<li>
<div class="review_description_left">
<a href="#" class="review_star review_star_5" onclick="javascript:return false;"></a>
<p>By fashion</p>
<span>2016-10-25 10:06:43</span>
</div>
<div class="review_description_right">
<input id="review_url_407" value="http://www.intosmile.com/review/product/addreply?id=407" type="hidden">
<span class="review_description_right_span"><b>good</b></span>
<div class="review_description_centen">
<div class="addsize"></div>
<br>
<div class="review-content">
i like this sweater
</div>
<br>
</div>
</div>
<div class="clear"></div>
</li>
</ul>
</div>
<div class="clear"></div>
<a class="submitbutton" href="<?= Yii::$service->url->getUrl('catalog/reviewproduct/add',['spu'=>$spu,'_id'=>$_id]); ?>" >
Add Review
</a>
<div class="clear"></div>
<div class="view_all_review">
<a href="<?= Yii::$service->url->getUrl('catalog/reviewproduct/lists',['spu'=>$spu,'_id'=>$_id]); ?>" >
View All Review(<?= $review_count; ?>)
</a>
</div>
</div>
</div>
</div>
\ No newline at end of file
<div class="main container one-column">
<div class="col-main">
<div class="std">
<div class="product-Reviews_top">
<div style="width:90px;float:left;">
<a href="<?= $url ?>">
<img src="<?= Yii::$service->product->image->getResize($main_img,[80,80],false) ?>">
</a>
</div>
<div style="width:700px;float:left;">
<div style="">
<a href="<?= $url ?>"><?= $name ?></a>
</div>
<div class="product_info review_add_price">
<div class="price_info">
<?php # 价格部分
$priceView = [
'view' => 'catalog/product/index/price.php'
];
$priceParam = [
'price_info' => $price_info,
];
?>
<?= Yii::$service->page->widget->render($priceView,$priceParam); ?>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="product-Reviews_bottom">
<form method="post" action="http://www.intosmile.com/review/product/add?id=112070">
<input class="thiscsrf" value="YVpVUWRacG4uLg1nFRkdHTICDzMeORYeAD8ZEi8TFDYAIB4nKwIgPQ==" name="_csrf" type="hidden"> <input name="product_id" value="112070" type="hidden">
<div class="h-30">
<div class="lh30_f">
<strong>Rate</strong><em class="product-description_em">*</em>&nbsp;&nbsp;&nbsp;&nbsp;
</div>
<div class="lh30_f">
<input name="reviews[rate]" value="5" id="review_price_field" type="hidden">
<ul class="star_ul">
<li><a class="star_1 full_star" title="1 stars" rel="1" alt="6" href="#" onclick="javascript:return false;"></a></li>
<li><a class="star_2 full_star" title="2 stars" rel="2" alt="7" href="#" onclick="javascript:return false;"></a></li>
<li><a class="star_3 full_star" title="3 stars" rel="3" alt="8" href="#" onclick="javascript:return false;"></a></li>
<li><a class="star_4 full_star" title="4 stars" rel="4" alt="9" href="#" onclick="javascript:return false;"></a></li>
<li><a class="star_5 full_star" title="5 stars" rel="5" alt="10" href="#" onclick="javascript:return false;"></a></li>
</ul>
<span class="review_span_error" id="review_price_span" style="display:inline;"></span>
</div>
</div>
<div id="review_create">
<ul id="reviews_form_list">
<li>
<label for="nickname_field" class="required">
<strong>Your Name</strong><em class="product-description_em">*</em></label>
<div class="input-box">
<input name="reviews[name]" id="review_email_field" class="input-text review-input-text required-entry" value="" type="text">
</div>
<span class="review_span_error" id="review_email_span"></span>
</li>
<li>
<label for="nickname_field" class="required">
<strong>Summary of Your Review</strong><em class="product-description_em">*</em></label>
<div class="input-box">
<input name="reviews[title]" id="review_title_field" class="input-text review-input-text required-entry" value="" type="text">
</div>
<span class="review_span_error" id="review_title_span"></span>
</li>
<li>
<label for="height_field" class="">
<strong>Your Height(Cm)</strong></label>
<div class="input-box">
<input name="reviews[height]" id="review_height_field" class="input-text review-input-text " value="" type="text">
</div>
<span class="review_span_error" id="review_height_span"></span>
</li>
<li>
<label for="weight_field" class="">
<strong>Your Weight(Kg)</strong></label>
<div class="input-box">
<input name="reviews[weight]" id="review_weight_field" class="input-text review-input-text " value="" type="text">
</div>
<span class="review_span_error" id="review_weight_span"></span>
</li>
<li>
<label for="height_field" class="">
<strong>The Size Your Buy</strong></label>
<div class="input-box">
<select class="product_size" name="size"><option value="L">L</option><option value="M">M</option><option value="S">S</option><option value="XL">XL</option><option value="XXL">XXL</option></select> </div>
<span class="review_span_error" id="review_height_span"></span>
</li>
<li>
<label for="height_field" class="">
<strong>Is It Fit For You ?</strong></label>
<div class="input-box">
<select name="is_it_fit">
<option value="It Fit">It Fit</option>
<option value="To Small For You">To Small For You</option>
<option value="To Lager For You">To Lager For You</option>
</select>
</div>
<span class="review_span_error" id="review_height_span"></span>
</li>
<li id="review_textarea" style="width: 722px;">
<label for="nickname_field" class="required"><strong>Review</strong><em class="product-description_em">*</em></label>
<div class="input-box">
<textarea name="reviews[review]" id="review_review_field"></textarea>
</div>
<span class="review_span_error" id="review_review_span"></span>
</li>
<li>
<label for="pass" class="required customertitle"><em>*</em>Verification code</label>
<div class="input-box login_box">
<input class="verification_code_input" maxlength="4" name="sercrity_code" value="" type="text">
<img class="verification_code" src="http://www.intosmile.com/help/verificate/code" onclick="this.src=this.src+'?'">
<br>
</div>
<button type="submit" title="Submit Review" class="button" id="m_top_10" onclick="return check_review()"><span><span>Submit Review</span></span></button>
</li>
</ul>
<div class="clear"></div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// add to cart js
<?php $this->beginBlock('product_review_rate') ?>
$(document).ready(function(){
$(".star_ul li a").click(function(){
$(".star_ul li a").removeClass('full_star');
$(this).addClass('full_star');
$num = $(this).attr('rel');
for($i=1;$i<=$num;$i++){
$('.star_'+$i).addClass('full_star');
}
$('#review_price_field').val($num);
});
});
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['product_review_rate'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>
\ No newline at end of file
......@@ -83,9 +83,12 @@ return [
],
'review' => [
'class' => 'fecshop\services\product\Review',
'filterByStore' => false, # 是否通过store的值进行评论过滤?
'filterByLang' => false, # 是否通过语言进行评论过滤?
],
'info' => [
'class' => 'fecshop\services\product\Info',
],
'coll' => [
'class' => 'fecshop\services\product\Coll',
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\models\mongodb\product;
use Yii;
use yii\mongodb\ActiveRecord;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Review extends ActiveRecord
{
public static $_customAttrs;
public static function collectionName()
{
return 'review';
}
# 动态增加字段。
public static function addCustomAttrs($attrs){
self::$_customAttrs = $attrs;
}
public function attributes($origin=false)
{
$origin = [
'_id',
'product_spu',
'product_id',
'rate_star',
'name',
'summary',
'review_content',
'review_date', #
'store', # store
'lang_code', # 语言
'status', # 审核状态
'audit_user', # 审核账号
'audit_date', # 审核时间
];
if($origin){ # 取原始的数据
return $origin;
}
if(is_array(self::$_customAttrs) && !empty(self::$_customAttrs)){
$origin = array_merge($origin,self::$_customAttrs);
}
return $origin;
}
}
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\services\product;
use Yii;
use fec\helpers\CDir;
use yii\base\InvalidValueException;
use yii\base\InvalidConfigException;
use fecshop\services\Service;
use fecshop\models\mongodb\product\Review as ReviewModel;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class Review extends Service
{
public $filterByStore;
public $filterByLang;
/**
* @property $arr | Array
* 初始化review model的属性,因为每一个产品的可能添加的评论字段不同。
*/
protected function actionInitReviewAttr($arr){
if(!empty($arr) && is_array($arr)){
$ReviewModel = new ReviewModel;
$attr_arr = $ReviewModel->attributes(true);
$arr_keys = array_keys($arr);
$attrs = array_diff($arr_keys,$attr_arr);
ReviewModel::addCustomAttrs($attrs);
}
}
/**
* @property $spu | String.
* 通过spu找到评论总数。
*/
protected function actionGetCountBySpu($spu){
$where = [
'product_spu' => $spu
];
if($this->filterByStore && ($currentStore = Yii::$service->store->currentStore)){
$where['store'] = $currentStore;
}
if($this->filterByLang && ($currentLangCode = Yii::$service->store->currentLangCode)){
$where['lang_code'] = $currentLangCode;
}
$count = ReviewModel::find()->asArray()->where($where)->count();
return $count ? $count : 0;
}
/**
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => ['review_date' => SORT_DESC],
* where' => [
* ['spu' => 'uk10001'],
* ],
* 'asArray' => true,
* ]
* 通过spu找到评论listing
*/
protected function actionGetListBySpu($filter){
if($this->filterByStore && ($currentStore = Yii::$service->store->currentStore)){
$filter['where'][] = ['store' => $currentStore ];
}
if($this->filterByLang && ($currentLangCode = Yii::$service->store->currentLangCode)){
$filter['where'][] = ['lang_code' => $currentLangCode ];
}
$query = ReviewModel::find();
$query = Yii::$service->helper->ar->getCollByFilter($query,$filter);
return [
'coll' => $query->all(),
'count'=> $query->count(),
];
}
/**
* @property $review_data | Array
*
* 增加评论
*/
protected function actionAddReview($review_data){
$this->initReviewAttr($review_data);
$model = new ReviewModel;
if(isset($review_data['_id'])){
unset($review_data['_id']);
}
$saveStatus = Yii::$service->helper->ar->save($model,$review_data);
return true;
}
/**
* @property $review_data | Array
* 保存评论
*/
protected function actionUpdateReview($review_data){
$this->initReviewAttr($review_data);
$model = ReviewModel::findOne(['_id'=> $review_data[$primaryKey]]);
unset($review_data[$primaryKey]);
$saveStatus = Yii::$service->helper->ar->save($model,$review_data);
return true;
}
/*
* example filter:
* [
* 'numPerPage' => 20,
* 'pageNum' => 1,
* 'orderBy' => ['_id' => SORT_DESC, 'sku' => SORT_ASC ],
* 'where' => [
['>','price',1],
['<=','price',10]
* ['sku' => 'uk10001'],
* ],
* 'asArray' => true,
* ]
* 查看review 的列表
*/
protected function actionList($filter){
$query = ReviewModel::find();
$query = Yii::$service->helper->ar->getCollByFilter($query,$filter);
return [
'coll' => $query->all(),
'count'=> $query->count(),
];
}
/**
* @property $_id | String
* 后台编辑 通过评论id找到评论
* 注意:因为每个产品的评论可能加入了新的字段,因此不能使用ActiveRecord的方式取出来,
* 使用下面的方式可以把字段都取出来。
*/
protected function actionGetByReviewId($_id){
return ReviewModel::getCollection()->findOne(['_id' => $_id]);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册