提交 1971354a 编写于 作者: T Terry

产品status设置成关闭,则访问该产品跳转404页面

上级 5891faab
...@@ -37,7 +37,10 @@ class Index ...@@ -37,7 +37,10 @@ class Index
{ {
$productImgSize = Yii::$app->controller->module->params['productImgSize']; $productImgSize = Yii::$app->controller->module->params['productImgSize'];
$productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier']; $productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier'];
$this->initProduct(); if(!$this->initProduct()){
Yii::$service->url->redirect404();
return;
}
ReviewHelper::initReviewConfig(); ReviewHelper::initReviewConfig();
$ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product); $ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product);
list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount; list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount;
...@@ -391,6 +394,16 @@ class Index ...@@ -391,6 +394,16 @@ class Index
$primaryVal = Yii::$app->request->get($primaryKey); $primaryVal = Yii::$app->request->get($primaryKey);
$this->_primaryVal = $primaryVal; $this->_primaryVal = $primaryVal;
$product = Yii::$service->product->getByPrimaryKey($primaryVal); $product = Yii::$service->product->getByPrimaryKey($primaryVal);
if ($product) {
$enableStatus = Yii::$service->product->getEnableStatus();
if ($product['status'] != $enableStatus){
return false;
}
} else {
return false;
}
$this->_product = $product; $this->_product = $product;
Yii::$app->view->registerMetaTag([ Yii::$app->view->registerMetaTag([
'name' => 'keywords', 'name' => 'keywords',
...@@ -416,6 +429,7 @@ class Index ...@@ -416,6 +429,7 @@ class Index
// 重新查询产品信息。 // 重新查询产品信息。
$product = Yii::$service->product->getByPrimaryKey($primaryVal); $product = Yii::$service->product->getByPrimaryKey($primaryVal);
$this->_product = $product; $this->_product = $product;
return true;
} }
// 面包屑导航 // 面包屑导航
......
...@@ -27,12 +27,10 @@ class ProductController extends AppfrontController ...@@ -27,12 +27,10 @@ class ProductController extends AppfrontController
// 产品详细页面 // 产品详细页面
public function actionIndex() public function actionIndex()
{ {
//$data = Yii::$service->product->apicoll();
//var_dump($data);
//echo 1;exit;
$data = $this->getBlock()->getLastData(); $data = $this->getBlock()->getLastData();
if(is_array($data)){
return $this->render($this->action->id, $data); return $this->render($this->action->id, $data);
}
} }
/** /**
* Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors * Yii2 behaviors 可以参看地址:http://www.yiichina.com/doc/guide/2.0/concept-behaviors
......
...@@ -37,7 +37,10 @@ class Index ...@@ -37,7 +37,10 @@ class Index
{ {
$productImgSize = Yii::$app->controller->module->params['productImgSize']; $productImgSize = Yii::$app->controller->module->params['productImgSize'];
$productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier']; $productImgMagnifier = Yii::$app->controller->module->params['productImgMagnifier'];
$this->initProduct(); if(!$this->initProduct()){
Yii::$service->url->redirect404();
return;
}
ReviewHelper::initReviewConfig(); ReviewHelper::initReviewConfig();
$ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product); $ReviewAndStarCount = ReviewHelper::getReviewAndStarCount($this->_product);
list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount; list($review_count, $reviw_rate_star_average) = $ReviewAndStarCount;
...@@ -391,6 +394,16 @@ class Index ...@@ -391,6 +394,16 @@ class Index
$primaryVal = Yii::$app->request->get($primaryKey); $primaryVal = Yii::$app->request->get($primaryKey);
$this->_primaryVal = $primaryVal; $this->_primaryVal = $primaryVal;
$product = Yii::$service->product->getByPrimaryKey($primaryVal); $product = Yii::$service->product->getByPrimaryKey($primaryVal);
if ($product) {
$enableStatus = Yii::$service->product->getEnableStatus();
if ($product['status'] != $enableStatus){
return false;
}
} else {
return false;
}
$this->_product = $product; $this->_product = $product;
Yii::$app->view->registerMetaTag([ Yii::$app->view->registerMetaTag([
'name' => 'keywords', 'name' => 'keywords',
...@@ -416,6 +429,7 @@ class Index ...@@ -416,6 +429,7 @@ class Index
// 重新查询产品信息。 // 重新查询产品信息。
$product = Yii::$service->product->getByPrimaryKey($primaryVal); $product = Yii::$service->product->getByPrimaryKey($primaryVal);
$this->_product = $product; $this->_product = $product;
return true;
} }
// 面包屑导航 // 面包屑导航
......
...@@ -27,12 +27,10 @@ class ProductController extends AppfrontController ...@@ -27,12 +27,10 @@ class ProductController extends AppfrontController
// 网站信息管理 // 网站信息管理
public function actionIndex() public function actionIndex()
{ {
//$data = Yii::$service->product->apicoll();
//var_dump($data);
//echo 1;exit;
$data = $this->getBlock()->getLastData(); $data = $this->getBlock()->getLastData();
if(is_array($data)){
return $this->render($this->action->id, $data); return $this->render($this->action->id, $data);
}
} }
public function behaviors() public function behaviors()
......
...@@ -18,7 +18,10 @@ use yii\mongodb\ActiveRecord; ...@@ -18,7 +18,10 @@ use yii\mongodb\ActiveRecord;
class Product extends ActiveRecord class Product extends ActiveRecord
{ {
public static $_customProductAttrs; public static $_customProductAttrs;
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
/** /**
* mongodb collection 的名字,相当于mysql的table name * mongodb collection 的名字,相当于mysql的table name
*/ */
......
...@@ -33,7 +33,13 @@ class Product extends Service ...@@ -33,7 +33,13 @@ class Product extends Service
//$this->_category = new CategoryMysqldb; //$this->_category = new CategoryMysqldb;
} }
} }
protected function actionGetEnableStatus()
{
return $this->_product->getEnableStatus();
}
/** /**
* 得到产品的所有的属性组。 * 得到产品的所有的属性组。
*/ */
......
...@@ -25,7 +25,13 @@ class ProductMongodb implements ProductInterface ...@@ -25,7 +25,13 @@ class ProductMongodb implements ProductInterface
{ {
return '_id'; return '_id';
} }
/**
* 得到分类激活状态的值
*/
public function getEnableStatus(){
return Product::STATUS_ENABLE;
}
public function getByPrimaryKey($primaryKey) public function getByPrimaryKey($primaryKey)
{ {
if ($primaryKey) { if ($primaryKey) {
...@@ -80,6 +86,8 @@ class ProductMongodb implements ProductInterface ...@@ -80,6 +86,8 @@ class ProductMongodb implements ProductInterface
} }
} }
} }
/* /*
* example filter: * example filter:
...@@ -478,6 +486,7 @@ class ProductMongodb implements ProductInterface ...@@ -478,6 +486,7 @@ class ProductMongodb implements ProductInterface
$select = $filter['select']; $select = $filter['select'];
$query = Product::find()->asArray(); $query = Product::find()->asArray();
$query->where($where); $query->where($where);
$query->andWhere(['status' => $this->getEnableStatus()]);
if (is_array($select) && !empty($select)) { if (is_array($select) && !empty($select)) {
$query->select($select); $query->select($select);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册