/** * @inheritdoc */ public function run() { if ($this->context instanceof ModelContextInterface && ($model = $this->context->getModel()) && $model instanceof ProductCategory) { $root = $model; } else { $root = ProductCategory::find()->roots()->active()->one(); } $items = ProductCategory::buildNodeTree($root, $root->children()->active()->all()); return $this->render('product_categories_list', ['widget' => $this, 'items' => $items]); }
public function getCategoriesRelation() { return $this->hasMany(ProductCategory::className(), ['id' => 'category_id'])->viaTable('{{%products_categories}}', ['product_id' => 'id']); }
/** * FiCategory ategory model based on its path. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $path * @throws \yii\web\NotFoundHttpException * @return ProductCategory the loaded model */ protected function findModel($path) { if (($model = ProductCategory::findByPath($path)->active()->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Registers a class definitions in container. */ public function registerDefinitions() { Yii::$container->set(ProductCategory::className(), ['as seo' => ['class' => 'im\\seo\\components\\SeoBehavior', 'metaClass' => 'im\\catalog\\models\\ProductCategoryMeta', 'ownerType' => false], 'as template' => ['class' => 'im\\cms\\components\\TemplateBehavior']]); Yii::$container->set(Product::className(), ['as seo' => ['class' => 'im\\seo\\components\\SeoBehavior', 'metaClass' => 'im\\catalog\\models\\ProductMeta', 'ownerType' => false]]); }
/** * @inheritdoc */ protected function getModelClass() { return ProductCategory::className(); }