/** * Finds the 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 Product the loaded model */ protected function findModel($path) { /** @var Product $model */ $model = Yii::createObject(Product::className()); if (($model = $model::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]]); }
/** * @return \yii\db\ActiveQuery */ public function getProductsRelation() { return $this->hasMany(Product::className(), ['type_id' => 'id']); }
/** * @inheritdoc */ public function getEntityRelation() { return $this->hasOne(Product::className(), ['id' => 'entity_id']); }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [['entity_type', 'default', 'value' => Yii::$app->get('typesRegister')->getEntityType(Product::className())]]); }
/** * @param ProductCategory $model * @return FieldQueryInterface[] */ protected function getSearchQueries(ProductCategory $model) { $categoryQuery = null; $categoryParentsQuery = null; $searchableType = $this->getSearchManager()->getSearchableTypeByClass(Product::className()); if ($searchableType instanceof IndexableInterface) { $mapping = $searchableType->getIndexMapping(); foreach ($mapping as $name => $attribute) { if ($name == 'all_categories') { $categoryParentsQuery = new Term($attribute->name, $model->id); } else { $nameParts = explode('.', $name); if (count($nameParts) == 2 && $nameParts[0] == 'categories') { $categoryQuery = new Term($attribute->name, $model->{$nameParts[1]}); } } } } else { $categoryQuery = new Term('categoriesRelation.id', $model->id); } return [$categoryQuery, $categoryParentsQuery]; }
/** * @inheritdoc */ protected function getModelClass() { return Product::className(); }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('{{%products_categories}}', ['category_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['brand_id' => 'id']); }