当前位置: 首页>>代码示例>>PHP>>正文


PHP Category::className方法代码示例

本文整理汇总了PHP中app\modules\shop\models\Category::className方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::className方法的具体用法?PHP Category::className怎么用?PHP Category::className使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\modules\shop\models\Category的用法示例。


在下文中一共展示了Category::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: appendPart

 /**
  * @inheritdoc
  */
 public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
 {
     /*
         В parameters должен храниться last_category_id
         Если его нет - используем parameters.category_id
     */
     $category_id = null;
     if (isset($parameters['last_category_id'])) {
         $category_id = $parameters['last_category_id'];
     } elseif (isset($parameters['category_id'])) {
         $category_id = $parameters['category_id'];
     }
     $used_params[] = 'last_category_id';
     $used_params[] = 'category_id';
     if ($category_id === null) {
         return false;
     }
     $category = Category::findById($category_id);
     if (is_object($category) === true) {
         $parentIds = $category->getParentIds();
         foreach ($parentIds as $id) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
         }
         $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category_id);
         return $category->getUrlPath($this->include_root_category);
     } else {
         return false;
     }
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:32,代码来源:PartialCategoryPathPart.php

示例2: run

 public function run()
 {
     $query = Category::find();
     $query->andWhere([Category::tableName() . '.active' => 1]);
     if ($this->root_category_id !== null) {
         $query->andWhere([Category::tableName() . '.parent_id' => $this->root_category_id]);
     }
     if ($this->category_group_id !== null) {
         $query->andWhere([Category::tableName() . '.category_group_id' => $this->category_group_id]);
     }
     $query->groupBy(Category::tableName() . ".id");
     $query->orderBy($this->sort);
     if ($this->limit !== null) {
         $query->limit($this->limit);
     }
     $object = Object::getForClass(Category::className());
     \app\properties\PropertiesHelper::appendPropertiesFilters($object, $query, $this->values_by_property_id, []);
     $sql = $query->createCommand()->getRawSql();
     $cacheKey = "FilteredCategoriesWidget:" . md5($sql);
     $result = Yii::$app->cache->get($cacheKey);
     if ($result === false) {
         $categories = Category::findBySql($sql)->all();
         $result = $this->render($this->viewFile, ['categories' => $categories]);
         Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::tableName())]));
     }
     return $result;
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:27,代码来源:FilteredCategoriesWidget.php

示例3: run

 /**
  * @return string
  */
 public function run()
 {
     parent::run();
     if (null === $this->rootCategory) {
         return '';
     }
     $cacheKey = $this->className() . ':' . implode('_', [$this->viewFile, $this->rootCategory, null === $this->depth ? 'null' : intval($this->depth), intval($this->includeRoot), intval($this->fetchModels), intval($this->onlyNonEmpty), implode(',', $this->excludedCategories), \Yii::$app->request->url]) . ':' . json_encode($this->additional);
     if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
         return $cache;
     }
     /** @var array|Category[] $tree */
     $tree = Category::getMenuItems(intval($this->rootCategory), $this->depth, boolval($this->fetchModels));
     if (true === $this->includeRoot) {
         if (null !== ($_root = Category::findById(intval($this->rootCategory)))) {
             $tree = [['label' => $_root->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $_root->category_group_id, 'last_category_id' => $_root->id]), 'id' => $_root->id, 'model' => $this->fetchModels ? $_root : null, 'items' => $tree]];
         }
     }
     if (true === $this->onlyNonEmpty) {
         $_sq1 = (new Query())->select('main_category_id')->distinct()->from(Product::tableName());
         $_sq2 = (new Query())->select('category_id')->distinct()->from('{{%product_category}}');
         $_query = (new Query())->select('id')->from(Category::tableName())->andWhere(['not in', 'id', $_sq1])->andWhere(['not in', 'id', $_sq2])->all();
         $this->excludedCategories = array_merge($this->excludedCategories, array_column($_query, 'id'));
     }
     $tree = $this->filterTree($tree);
     $cache = $this->render($this->viewFile, ['tree' => $tree, 'fetchModels' => $this->fetchModels, 'additional' => $this->additional, 'activeClass' => $this->activeClass, 'activateParents' => $this->activateParents]);
     \Yii::$app->cache->set($cacheKey, $cache, 0, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Category::className()), ActiveRecordHelper::getCommonTag(Product::className())]]));
     return $cache;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:31,代码来源:CategoriesList.php

示例4: getLinks

 protected function getLinks()
 {
     if (!is_null($this->frontendLink) || !is_null($this->backendLink)) {
         return true;
     }
     /** @var Image $image */
     $image = Image::findById($this->img_id);
     if (is_null($image) || is_null($object = Object::findById($image->object_id))) {
         return false;
     }
     /** @var \app\models\Object $object */
     switch ($object->object_class) {
         case Page::className():
             $this->getPageLinks($image->object_model_id);
             break;
         case Category::className():
             $this->getCategoryLinks($image->object_model_id);
             break;
         case Product::className():
             $this->getProductLinks($image->object_model_id);
             break;
         default:
             return false;
     }
     return true;
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:26,代码来源:ErrorImage.php

示例5: run

 /**
  * @inheritdoc
  * @return string
  */
 public function run()
 {
     $cacheKey = "PlainCategoriesWidget:" . $this->root_category_id . ":" . $this->viewFile;
     $result = Yii::$app->cache->get($cacheKey);
     if ($result === false) {
         $categories = Category::getByParentId($this->root_category_id);
         $result = $this->render($this->viewFile, ['categories' => $categories]);
         Yii::$app->cache->set($cacheKey, $result, 86400, new \yii\caching\TagDependency(['tags' => ActiveRecordHelper::getCommonTag(Category::className())]));
     }
     return $result;
 }
开发者ID:Razzwan,项目名称:dotplant2,代码行数:15,代码来源:PlainCategoriesWidget.php

示例6: getNextPart

 /**
  * @inheritdoc
  */
 public function getNextPart($full_url, $next_part, &$previous_parts)
 {
     if (mb_strpos($next_part, $this->static_part) === 0) {
         if (count($this->parameters) === 0) {
             $this->parameters = ['static_part' => $this->static_part];
         }
         $cacheTags = [];
         if (isset($this->parameters['last_category_id']) && $this->parameters['last_category_id'] !== null) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $this->parameters['last_category_id']);
         }
         $part = new self(['gathered_part' => $this->static_part, 'rest_part' => mb_substr($next_part, mb_strlen($this->static_part)), 'parameters' => $this->parameters, 'cacheTags' => $cacheTags]);
         return $part;
     } else {
         return false;
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:19,代码来源:StaticPart.php

示例7: up

 public function up()
 {
     $this->addColumn('{{%theme_active_widgets}}', 'configuration_json', Schema::TYPE_TEXT);
     $this->insert('{{%theme_widgets}}', ['name' => Yii::t('app', 'Categories list'), 'widget' => 'app\\extensions\\DefaultTheme\\widgets\\CategoriesList\\Widget', 'configuration_model' => 'app\\extensions\\DefaultTheme\\widgets\\CategoriesList\\ConfigurationModel', 'configuration_view' => '@app/extensions/DefaultTheme/widgets/CategoriesList/views/_config.php', 'configuration_json' => '{}', 'is_cacheable' => 0, 'cache_tags' => \app\modules\shop\models\Category::className()]);
     $categoriesListWidgetId = $this->db->lastInsertID;
     $this->insert('{{%theme_widgets}}', ['name' => Yii::t('app', 'Filter widget'), 'widget' => 'app\\extensions\\DefaultTheme\\widgets\\FilterSets\\Widget', 'configuration_model' => 'app\\extensions\\DefaultTheme\\widgets\\FilterSets\\ConfigurationModel', 'configuration_view' => '@app/extensions/DefaultTheme/widgets/FilterSets/views/_config.php', 'configuration_json' => '{}', 'is_cacheable' => 0, 'cache_tags' => '']);
     $filterSetsWidget = $this->db->lastInsertID;
     $this->insert('{{%theme_widgets}}', ['name' => Yii::t('app', 'Pages list'), 'widget' => 'app\\extensions\\DefaultTheme\\widgets\\PagesList\\Widget', 'configuration_model' => 'app\\extensions\\DefaultTheme\\widgets\\PagesList\\ConfigurationModel', 'configuration_view' => '@app/extensions/DefaultTheme/widgets/PagesList/views/_config.php', 'configuration_json' => '{}', 'is_cacheable' => 1, 'cache_lifetime' => 86400, 'cache_tags' => \app\modules\page\models\Page::className()]);
     $pagesList = $this->db->lastInsertID;
     $this->insert('{{%theme_widgets}}', ['name' => Yii::t('app', 'Content block'), 'widget' => 'app\\extensions\\DefaultTheme\\widgets\\ContentBlock\\Widget', 'configuration_model' => 'app\\extensions\\DefaultTheme\\widgets\\ContentBlock\\ConfigurationModel', 'configuration_view' => '@app/extensions/DefaultTheme/widgets/ContentBlock/views/_config.php', 'configuration_json' => '{}', 'is_cacheable' => 1, 'cache_lifetime' => 86400, 'cache_tags' => \app\modules\page\models\Page::className()]);
     $contentBlock = $this->db->lastInsertID;
     $allBlocks = [$categoriesListWidgetId, $filterSetsWidget, $pagesList, $contentBlock];
     foreach ($allBlocks as $widget_id) {
         // left sidebar
         $this->insert('{{%theme_widget_applying}}', ['widget_id' => $widget_id, 'part_id' => 5]);
         // right sidebar
         $this->insert('{{%theme_widget_applying}}', ['widget_id' => $widget_id, 'part_id' => 8]);
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:19,代码来源:m150531_134103_theme_part_improvements.php

示例8: appendPart

 public function appendPart($route, $parameters = [], &$used_params = [], &$cacheTags = [])
 {
     $used_params[] = 'categories';
     $used_params[] = 'category_group_id';
     $used_params[] = $this->model_category_attribute;
     $attribute_name = $this->model_category_attribute;
     $category_id = $this->model->{$attribute_name};
     /** @var Category $category */
     $category = Category::findById($category_id);
     if (is_object($category) === true) {
         $parentIds = $category->getParentIds();
         foreach ($parentIds as $id) {
             $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
         }
         $cacheTags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category_id);
         return $category->getUrlPath($this->include_root_category);
     } else {
         return false;
     }
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:20,代码来源:FullCategoryPathPart.php

示例9: actions

 /**
  * @inheritdoc
  * @return array
  */
 public function actions()
 {
     return ['getTree' => ['class' => AdjacencyFullTreeDataAction::className(), 'class_name' => Category::className(), 'model_label_attribute' => 'name'], 'getCatTree' => ['class' => 'app\\backend\\actions\\JSSelectableTreeGetTree', 'modelName' => 'app\\modules\\shop\\models\\Category', 'label_attribute' => 'name', 'vary_by_type_attribute' => null], 'addImage' => ['class' => AddImageAction::className()], 'upload' => ['class' => UploadAction::className(), 'upload' => 'theme/resources/product-images'], 'remove' => ['class' => RemoveAction::className(), 'uploadDir' => 'theme/resources/product-images'], 'save-info' => ['class' => SaveInfoAction::className()], 'update-editable' => ['class' => UpdateEditable::className(), 'modelName' => Product::className(), 'allowedAttributes' => ['currency_id' => function (Product $model, $attribute) {
         if ($model === null || $model->currency === null || $model->currency_id === 0) {
             return null;
         }
         return \yii\helpers\Html::tag('div', $model->currency->name, ['class' => $model->currency->name]);
     }, 'price', 'old_price', 'active' => function (Product $model) {
         if ($model === null || $model->active === null) {
             return null;
         }
         if ($model->active === 1) {
             $label_class = 'label-success';
             $value = 'Active';
         } else {
             $value = 'Inactive';
             $label_class = 'label-default';
         }
         return \yii\helpers\Html::tag('span', Yii::t('app', $value), ['class' => "label {$label_class}"]);
     }]], 'property-handler' => ['class' => PropertyHandler::className(), 'modelName' => Product::className()]];
 }
开发者ID:pramana08,项目名称:dotplant2,代码行数:25,代码来源:BackendProductController.php

示例10: getPossibleSelections

 public function getPossibleSelections()
 {
     $allowed_category_ids = [];
     if ($this->onlyAvailableProducts) {
         $object = Object::getForClass(Product::className());
         if (!is_null($object) && isset($this->current_selections['last_category_id'])) {
             $cacheKey = 'CategoriesFilterWidget: ' . $object->id . ':' . $this->current_selections['last_category_id'] . ':' . Json::encode($this->current_selections['properties']);
             $allowed_category_ids = Yii::$app->cache->get($cacheKey);
             if ($allowed_category_ids === false) {
                 $query = new Query();
                 $query = $query->select($object->categories_table_name . '.category_id')->distinct()->from($object->categories_table_name);
                 if (count($this->current_selections['properties']) > 0) {
                     foreach ($this->current_selections['properties'] as $property_id => $values) {
                         $joinTableName = 'OSVJoinTable' . $property_id;
                         $query->join('JOIN', ObjectStaticValues::tableName() . ' ' . $joinTableName, $joinTableName . '.object_id = :objectId AND ' . $joinTableName . '.object_model_id = ' . $object->categories_table_name . '.object_model_id  ', [':objectId' => $object->id]);
                         $imploded_values = implode(', ', array_map('intval', $values));
                         $query->andWhere(new Expression('`' . $joinTableName . '`.`property_static_value_id`' . ' in (' . $imploded_values . ')'));
                     }
                 }
                 $allowed_category_ids = $query->column();
                 Yii::$app->cache->set($cacheKey, $allowed_category_ids, 86400, new \yii\caching\TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag($object->object_class), \devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(Category::className())]]));
                 $object = null;
             }
         }
     }
     $this->possible_selections = [];
     $models = Category::getByLevel($this->category_group_id);
     if (isset($models[0]) && $this->omit_root == true) {
         $models = Category::getByParentId($models[0]->id);
     }
     $this->possible_selections = [];
     foreach ($models as $model) {
         if ($this->onlyAvailableProducts === true && !in_array($model->id, $allowed_category_ids)) {
             continue;
         }
         $this->possible_selections[] = $this->recursiveGetTree($model, $allowed_category_ids);
     }
     return $this->possible_selections;
 }
开发者ID:heartshare,项目名称:dotplant2,代码行数:39,代码来源:CategoriesWidget.php

示例11: getCacheTags

 public function getCacheTags()
 {
     $tags = [ActiveRecordHelper::getObjectTag(self::className(), $this->id)];
     $category = $this->getMainCategory();
     $tags[] = ActiveRecordHelper::getObjectTag(Category::className(), $category->id);
     $categoryParentsIds = $category->getParentIds();
     foreach ($categoryParentsIds as $id) {
         $tags[] = ActiveRecordHelper::getObjectTag(Category::className(), $id);
     }
     return $tags;
 }
开发者ID:Razzwan,项目名称:dotplant2,代码行数:11,代码来源:Product.php

示例12: actionEdit

 public function actionEdit($parent_id = null, $id = null)
 {
     if (null === $parent_id) {
         throw new NotFoundHttpException();
     }
     if (null === ($object = Object::getForClass(Category::className()))) {
         throw new ServerErrorHttpException();
     }
     /** @var null|Category|HasProperties $model */
     $model = null;
     if (null !== $id) {
         $model = Category::findById($id, null, null);
     } else {
         $parent = Category::findById($parent_id, null, null);
         if ($parent_id === '0' || !is_null($parent)) {
             $model = new Category();
             $model->loadDefaultValues();
             $model->parent_id = $parent_id;
             if ($parent_id !== '0') {
                 $model->category_group_id = $parent->category_group_id;
             }
         } else {
             throw new ServerErrorHttpException();
         }
     }
     if (null === $model) {
         throw new ServerErrorHttpException();
     }
     $event = new BackendEntityEditEvent($model);
     $this->trigger(self::BACKEND_CATEGORY_EDIT, $event);
     $post = \Yii::$app->request->post();
     if ($event->isValid && $model->load($post) && $model->validate()) {
         $saveStateEvent = new BackendEntityEditEvent($model);
         $this->trigger(self::BACKEND_CATEGORY_EDIT_SAVE, $saveStateEvent);
         $save_result = $model->save();
         $model->saveProperties($post);
         if (null !== ($view_object = ViewObject::getByModel($model, true))) {
             if ($view_object->load($post, 'ViewObject')) {
                 if ($view_object->view_id <= 0) {
                     $view_object->delete();
                 } else {
                     $view_object->save();
                 }
             }
         }
         if ($save_result) {
             $modelAfterSaveEvent = new BackendEntityEditEvent($model);
             $this->trigger(self::BACKEND_CATEGORY_AFTER_SAVE, $modelAfterSaveEvent);
             $this->runAction('save-info', ['model_id' => $model->id]);
             Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['index']);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['edit', 'returnUrl' => $returnUrl, 'parent_id' => Yii::$app->request->get('parent_id', null)]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl, 'parent_id' => $model->parent_id]));
             }
         } else {
             throw new ServerErrorHttpException();
         }
     }
     return $this->render('category-form', ['model' => $model, 'object' => $object]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:65,代码来源:BackendCategoryController.php

示例13: parseRequest

 public function parseRequest($manager, $request)
 {
     Yii::beginProfile("ObjectRule::parseRequest");
     $url = $request->getPathInfo();
     if (empty($url)) {
         Yii::endProfile("ObjectRule::parseRequest");
         return false;
     }
     $cacheKey = 'ObjectRule:' . $url . ':' . Json::encode($request->getQueryParams());
     $result = Yii::$app->cache->get($cacheKey);
     if ($result !== false) {
         Yii::endProfile("ObjectRule::parseRequest");
         $this->defineBlocksTitleAndView($result);
         return $result['result'];
     }
     $prefilteredPage = PrefilteredPages::getActiveByUrl($url);
     if ($prefilteredPage !== null) {
         $params = ['properties' => Json::decode($prefilteredPage['params'])];
         $category = Category::findById($prefilteredPage['last_category_id']);
         if ($category === null) {
             throw new NotFoundHttpException();
         }
         $params['category_group_id'] = $category->category_group_id;
         $params['last_category_id'] = $category->id;
         $data = ['blocks' => []];
         if (!empty($prefilteredPage['title'])) {
             $data['title'] = $prefilteredPage['title'];
         }
         if (!empty($prefilteredPage['meta_description'])) {
             $data['meta_description'] = $prefilteredPage['meta_description'];
         }
         $blocks = ['content', 'announce', 'breadcrumbs_label', 'h1'];
         foreach ($blocks as $block_name) {
             if (!empty($prefilteredPage[$block_name])) {
                 $data['blocks'][$block_name] = $prefilteredPage[$block_name];
             }
         }
         $data['is_prefiltered_page'] = true;
         if ($prefilteredPage['view_id'] > 0) {
             $data['viewId'] = $prefilteredPage['view_id'];
         }
         $data['result'] = ['shop/product/list', $params];
         $this->defineBlocksTitleAndView($data);
         Yii::$app->cache->set($cacheKey, $data, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(PrefilteredPages::className(), $prefilteredPage['id']), ActiveRecordHelper::getObjectTag(Category::className(), $category->id)]]));
         return $data['result'];
     }
     $routes = ObjectRule::getRoutes();
     $cacheTags = [];
     foreach ($routes as $model) {
         /** @var UrlPart[] $handlers */
         $handlers = [];
         $object = Object::findById($model->object_id);
         foreach ($model->template as $t) {
             $handler = Yii::createObject($t);
             $handler->object = $object;
             $handlers[] = $handler;
         }
         $url_parts = [];
         $parameters = [];
         $next_part = $url;
         foreach ($handlers as $handler) {
             if (empty($next_part)) {
                 //break;
             }
             $result = $handler->getNextPart($url, $next_part, $url_parts);
             if ($result !== false && is_object($result) === true) {
                 $parameters = ArrayHelper::merge($parameters, $result->parameters);
                 $cacheTags = ArrayHelper::merge($cacheTags, $result->cacheTags);
                 // удалим leading slash
                 $next_part = ltrim($result->rest_part, '/');
                 $url_parts[] = $result;
             } elseif ($result === false && $handler->optional === false) {
                 continue;
             }
         }
         if (count($url_parts) == 0) {
             continue;
         }
         // в конце удачного парсинга next_part должен остаться пустым
         if (empty($next_part)) {
             $resultForCache = ['result' => [$model->route, $parameters]];
             if (isset($_POST['properties'], $parameters['properties'])) {
                 foreach ($_POST['properties'] as $key => $value) {
                     if (isset($parameters['properties'][$key])) {
                         $parameters['properties'][$key] = array_unique(ArrayHelper::merge($parameters['properties'][$key], $value));
                     } else {
                         $parameters['properties'][$key] = array_unique($value);
                     }
                 }
             } elseif (isset($_POST['properties'])) {
                 $parameters['properties'] = $_POST['properties'];
             }
             Yii::endProfile("ObjectRule::parseRequest");
             if (isset($parameters['properties'])) {
                 foreach ($parameters['properties'] as $key => $values) {
                     foreach ($parameters['properties'][$key] as $index => $value) {
                         if ($value === '') {
                             unset($parameters['properties'][$key][$index]);
                         }
                     }
//.........这里部分代码省略.........
开发者ID:flarmn,项目名称:dotplant2,代码行数:101,代码来源:ObjectRule.php

示例14: actionList

 /**
  * Products listing by category with filtration support.
  *
  * @return string
  * @throws \Exception
  * @throws NotFoundHttpException
  * @throws ServerErrorHttpException
  */
 public function actionList()
 {
     $request = Yii::$app->request;
     if (null === $request->get('category_group_id')) {
         throw new NotFoundHttpException();
     }
     if (null === ($object = Object::getForClass(Product::className()))) {
         throw new ServerErrorHttpException('Object not found.');
     }
     $category_group_id = intval($request->get('category_group_id', 0));
     $title_append = $request->get('title_append', '');
     if (!empty($title_append)) {
         $title_append = is_array($title_append) ? implode(' ', $title_append) : $title_append;
         unset($_GET['title_append']);
     }
     $title_prepend = $request->get("title_prepend", "");
     if (!empty($title_prepend)) {
         $title_prepend = is_array($title_prepend) ? implode(" ", $title_prepend) : $title_prepend;
         unset($_GET["title_prepend"]);
     }
     $values_by_property_id = $request->get('properties', []);
     if (!is_array($values_by_property_id)) {
         $values_by_property_id = [$values_by_property_id];
     }
     if (Yii::$app->request->isPost && isset($_POST['properties'])) {
         if (is_array($_POST['properties'])) {
             foreach ($_POST['properties'] as $key => $value) {
                 if (isset($values_by_property_id[$key])) {
                     $values_by_property_id[$key] = array_unique(ArrayHelper::merge($values_by_property_id[$key], $value));
                 } else {
                     $values_by_property_id[$key] = array_unique($value);
                 }
             }
         }
     }
     $selected_category_ids = $request->get('categories', []);
     if (!is_array($selected_category_ids)) {
         $selected_category_ids = [$selected_category_ids];
     }
     if (null !== ($selected_category_id = $request->get('last_category_id'))) {
         $selected_category_id = intval($selected_category_id);
     }
     $result = Product::filteredProducts($category_group_id, $values_by_property_id, $selected_category_id, false, null, true, false);
     /** @var Pagination $pages */
     $pages = $result['pages'];
     if (Yii::$app->response->is_prefiltered_page) {
         $pages->route = '/' . Yii::$app->request->pathInfo;
         $pages->params = [];
     }
     $allSorts = $result['allSorts'];
     $products = $result['products'];
     // throw 404 if we are at filtered page without any products
     if (!Yii::$app->request->isAjax && !empty($values_by_property_id) && empty($products)) {
         throw new EmptyFilterHttpException();
     }
     if (null !== ($selected_category = $selected_category_id)) {
         if ($selected_category_id > 0) {
             if (null !== ($selected_category = Category::findById($selected_category_id, null))) {
                 if (!empty($selected_category->meta_description)) {
                     $this->view->registerMetaTag(['name' => 'description', 'content' => ContentBlockHelper::compileContentString($selected_category->meta_description, Product::className() . ":{$selected_category->id}:meta_description", new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ContentBlock::className()), ActiveRecordHelper::getCommonTag(Category::className())]]))], 'meta_description');
                 }
                 $this->view->title = $selected_category->title;
             }
         }
     }
     if (is_null($selected_category) || !$selected_category->active) {
         throw new NotFoundHttpException();
     }
     if (!empty($title_append)) {
         $this->view->title .= " " . $title_append;
     }
     if (!empty($title_prepend)) {
         $this->view->title = "{$title_prepend} {$this->view->title}";
     }
     $this->view->blocks['h1'] = $selected_category->h1;
     $this->view->blocks['announce'] = $selected_category->announce;
     $this->view->blocks['content'] = $selected_category->content;
     $this->loadDynamicContent($object->id, 'shop/product/list', $request->get());
     $params = ['model' => $selected_category, 'selected_category' => $selected_category, 'selected_category_id' => $selected_category_id, 'selected_category_ids' => $selected_category_ids, 'values_by_property_id' => $values_by_property_id, 'products' => $products, 'object' => $object, 'category_group_id' => $category_group_id, 'pages' => $pages, 'title_append' => $title_append, 'selections' => $request->get(), 'breadcrumbs' => $this->buildBreadcrumbsArray($selected_category, null, $values_by_property_id), 'allSorts' => $allSorts];
     $viewFile = $this->computeViewFile($selected_category, 'list');
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $content = $this->renderAjax($viewFile, $params);
         $filters = '';
         $activeWidgets = ThemeActiveWidgets::getActiveWidgets();
         foreach ($activeWidgets as $activeWidget) {
             if ($activeWidget->widget->widget == Widget::className()) {
                 /** @var ThemeWidgets $widgetModel */
                 $widgetModel = $activeWidget->widget;
                 /** @var BaseWidget $widgetClassName */
                 $widgetClassName = $widgetModel->widget;
                 $widgetConfiguration = Json::decode($widgetModel->configuration_json, true);
//.........这里部分代码省略.........
开发者ID:lzpfmh,项目名称:dotplant2,代码行数:101,代码来源:ProductController.php

示例15: actions

 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ['getTree' => ['class' => AdjacencyFullTreeDataAction::className(), 'class_name' => Category::className(), 'model_label_attribute' => 'name']];
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:7,代码来源:FilterSetsController.php


注:本文中的app\modules\shop\models\Category::className方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。