Skip to content

Commit

Permalink
添加分类是否在菜单中显示选项
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Jul 19, 2017
1 parent a6e149f commit 5891faa
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 13 deletions.
14 changes: 14 additions & 0 deletions app/appadmin/modules/Catalog/block/category/Index.php
Expand Up @@ -252,6 +252,20 @@ public function getBaseInfo()
'require' => 1,
'default' => 1,
],

[
'label'=>'Menu是否显示',
'name'=>'menu_show',
'display'=>[
'type' => 'select',
'data' => [
1 => '菜单中显示',
2 => '菜单中不显示',
],
],
'require' => 1,
'default' => 1,
],

[
'label'=>'Url Key',
Expand Down
18 changes: 16 additions & 2 deletions app/appfront/modules/Catalog/block/category/Index.php
Expand Up @@ -53,8 +53,11 @@ public function getLastData()
// 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。
$this->getNumPerPage();
//echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']);
$this->initCategory();

if(!$this->initCategory()){
Yii::$service->url->redirect404();
return;
}

// change current layout File.
//Yii::$service->page->theme->layoutFile = 'home.php';

Expand Down Expand Up @@ -471,6 +474,16 @@ protected function initCategory()
$primaryVal = Yii::$app->request->get($primaryKey);
$this->_primaryVal = $primaryVal;
$category = Yii::$service->category->getByPrimaryKey($primaryVal);
if ($category) {
$enableStatus = Yii::$service->category->getCategoryEnableStatus();
if ($category['status'] != $enableStatus){

return false;
}
} else {

return false;
}
$this->_category = $category;
Yii::$app->view->registerMetaTag([
'name' => 'keywords',
Expand All @@ -486,6 +499,7 @@ protected function initCategory()
$this->_title = $this->_title ? $this->_title : $name;
Yii::$app->view->title = $this->_title;
$this->_where = $this->initWhere();
return true;
}

// 面包屑导航
Expand Down
Expand Up @@ -24,12 +24,13 @@ public function init()
Yii::$service->page->theme->layoutFile = 'category_view.php';
}

// 网站信息管理
// 分类页面。
public function actionIndex()
{
$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
Expand Down
16 changes: 15 additions & 1 deletion app/apphtml5/modules/Catalog/block/category/Index.php
Expand Up @@ -54,7 +54,10 @@ public function getLastData()
// 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。
$this->getNumPerPage();
//echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']);
$this->initCategory();
if(!$this->initCategory()){
Yii::$service->url->redirect404();
return;
}

// change current layout File.
//Yii::$service->page->theme->layoutFile = 'home.php';
Expand Down Expand Up @@ -483,6 +486,16 @@ protected function initCategory()
$primaryVal = Yii::$app->request->get($primaryKey);
$this->_primaryVal = $primaryVal;
$category = Yii::$service->category->getByPrimaryKey($primaryVal);
if ($category) {
$enableStatus = Yii::$service->category->getCategoryEnableStatus();
if ($category['status'] != $enableStatus){

return false;
}
} else {

return false;
}
$this->_category = $category;
Yii::$app->view->registerMetaTag([
'name' => 'keywords',
Expand All @@ -498,6 +511,7 @@ protected function initCategory()
$this->_title = $this->_title ? $this->_title : $name;
Yii::$app->view->title = $this->_title;
$this->_where = $this->initWhere();
return true;
}

// 面包屑导航
Expand Down
Expand Up @@ -24,12 +24,13 @@ public function init()
Yii::$service->page->theme->layoutFile = 'category_view.php';
}

// 网站信息管理
// 分类页面。
public function actionIndex()
{
$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()
Expand Down
9 changes: 9 additions & 0 deletions models/mongodb/Category.php
Expand Up @@ -17,6 +17,14 @@
*/
class Category extends ActiveRecord
{


const MENU_SHOW = 1;
const MENU_NOT_SHOW = 2;
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;


/**
* mongodb collection 的名字,相当于mysql的table name
*/
Expand All @@ -35,6 +43,7 @@ public function attributes()
'parent_id',
'name',
'status',
'menu_show',
'url_key',
'level',
'thumbnail_image',
Expand Down
12 changes: 12 additions & 0 deletions services/Category.php
Expand Up @@ -35,6 +35,18 @@ public function init()
//$this->_category = new CategoryMysqldb;
}
}



protected function actionGetCategoryEnableStatus()
{
return $this->_category->getCategoryEnableStatus();
}

protected function actionGetCategoryMenuShowStatus()
{
return $this->_category->getCategoryMenuShowStatus();
}

/**
* 得到当前的category service 对应的主键名称,譬如如果是mongo,返回的是 _id.
Expand Down
9 changes: 9 additions & 0 deletions services/Url.php
Expand Up @@ -423,4 +423,13 @@ protected function actionRedirectHome()
//header("Location: $homeUrl");
}
}

protected function actionRedirect404()
{
$error404UrlKey = Yii::$app->errorHandler->errorAction;
$error404Url = $this->getUrl($error404UrlKey);
if ($error404Url) {
Yii::$app->getResponse()->redirect($error404Url)->send();
}
}
}
16 changes: 14 additions & 2 deletions services/category/CategoryMongodb.php
Expand Up @@ -27,7 +27,18 @@ public function getPrimaryKey()
{
return '_id';
}

/**
* 得到分类激活状态的值
*/
public function getCategoryEnableStatus(){
return Category::STATUS_ENABLE;
}
/**
* 得到分类在menu中显示的状态值
*/
public function getCategoryMenuShowStatus(){
return Category::MENU_SHOW;
}
/**
* 通过主键,得到Category对象。
*/
Expand Down Expand Up @@ -112,7 +123,8 @@ public function save($one, $originUrlKey = 'catalog/category/index')
}
$model->updated_at = time();
unset($one['_id']);

$one['status'] = (int)$one['status'];
$one['menu_show'] = (int)$one['menu_show'];
$saveStatus = Yii::$service->helper->ar->save($model, $one);
$originUrl = $originUrlKey.'?'.$this->getPrimaryKey() .'='. $primaryVal;
$originUrlKey = isset($one['url_key']) ? $one['url_key'] : '';
Expand Down
3 changes: 3 additions & 0 deletions services/category/Menu.php
Expand Up @@ -26,6 +26,7 @@ class Menu extends Service
*/
protected function actionGetCategoryMenuArr($parentId = '')
{

$arr = [];
if (!$parentId) {
$parentId = $this->rootCategoryId;
Expand All @@ -34,6 +35,8 @@ protected function actionGetCategoryMenuArr($parentId = '')
'_id', 'parent_id', 'name', 'url_key', 'menu_custom',
])->where([
'parent_id' => $parentId,
'status' => Category::STATUS_ENABLE,
'menu_show' => Category::MENU_SHOW,
])->all();
if (is_array($data) && !empty($data)) {
foreach ($data as $category) {
Expand Down
2 changes: 1 addition & 1 deletion services/email/views/order/create/guest/body_en.php
Expand Up @@ -55,7 +55,7 @@

<td>&nbsp;</td>
<td valign="top" style="padding:7px 9px 9px;font-size:12px;border-right-color:rgb(234,234,234);border-bottom-color:rgb(234,234,234);border-left-color:rgb(234,234,234);border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-style:solid;border-bottom-style:solid;border-left-style:solid">
<p><b>PayPal - <?= $order['payment_method']; ?></b></p>
<p><b><?= ucfirst(str_replace('_',' ',$order['payment_method'])); ?></b></p>

</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion services/email/views/order/create/logined/body_en.php
Expand Up @@ -55,7 +55,7 @@

<td>&nbsp;</td>
<td valign="top" style="padding:7px 9px 9px;font-size:12px;border-right-color:rgb(234,234,234);border-bottom-color:rgb(234,234,234);border-left-color:rgb(234,234,234);border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-right-style:solid;border-bottom-style:solid;border-left-style:solid">
<p><b>PayPal - <?= $order['payment_method']; ?></b></p>
<p><b><?= ucfirst(str_replace('_',' ',$order['payment_method'])); ?></b></p>

</td>
</tr>
Expand Down

0 comments on commit 5891faa

Please sign in to comment.