/** * 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.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); // if (!$this->validate()) { // // uncomment the following line if you do not want to return any records when validation fails // // $query->where('0=1'); // return $dataProvider; // } $query->andFilterWhere(['id' => $this->id, 'price' => $this->price, 'status' => $this->status, 'brand_id' => $this->brand_id, 'type_id' => $this->type_id, 'available_on' => $this->available_on, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'sku', $this->sku])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'quantity', $this->quantity]); return $dataProvider; }
/** * 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']); }