コード例 #1
0
 /**
  * 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.');
     }
 }
コード例 #2
0
ファイル: Bootstrap.php プロジェクト: xyxdasnjss/imshop
 /**
  * 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]]);
 }
コード例 #3
0
ファイル: ProductType.php プロジェクト: manyoubaby123/imshop
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductsRelation()
 {
     return $this->hasMany(Product::className(), ['type_id' => 'id']);
 }
コード例 #4
0
 /**
  * @inheritdoc
  */
 public function getEntityRelation()
 {
     return $this->hasOne(Product::className(), ['id' => 'entity_id']);
 }
コード例 #5
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [['entity_type', 'default', 'value' => Yii::$app->get('typesRegister')->getEntityType(Product::className())]]);
 }
コード例 #6
0
 /**
  * @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];
 }
コード例 #7
0
 /**
  * @inheritdoc
  */
 protected function getModelClass()
 {
     return Product::className();
 }
コード例 #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['id' => 'product_id'])->viaTable('{{%products_categories}}', ['category_id' => 'id']);
 }
コード例 #9
0
ファイル: Brand.php プロジェクト: manyoubaby123/imshop
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProducts()
 {
     return $this->hasMany(Product::className(), ['brand_id' => 'id']);
 }