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

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

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