コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find()->joinWith('translations')->orderBy(['parent_id' => SORT_ASC, 'position' => SORT_ASC]);
     $this->load($params);
     // grid filtering conditions
     $query->andFilterWhere(['shop_category.parent_id' => $this->parent_id])->andFilterWhere(['like', 'shop_category_translation.title', $this->title])->andFilterWhere(['shop_category.show' => $this->show]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     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;
     }
     return $dataProvider;
 }
コード例 #2
0
 public function safeUp()
 {
     $this->addColumn('shop_product', 'position', 'INT(5) AFTER id');
     $categories = Category::find()->all();
     foreach ($categories as $category) {
         $products = Product::find()->where(['category_id' => $category->id])->all();
         for ($i = 0; $i < count($products); $i++) {
             $this->execute('UPDATE shop_product SET position=' . ($i + 1) . ' WHERE id=' . $products[$i]->id . ' AND category_id=' . $category->id);
         }
     }
     $this->addColumn('shop_category', 'position', $this->integer());
     for ($i = 0; $i < count($categories); $i++) {
         $this->execute('UPDATE shop_category SET position=' . ($i + 1) . ' WHERE id=' . $categories[$i]->id);
     }
 }
コード例 #3
0
ファイル: index.php プロジェクト: black-lamp/blcms-shop
    <!--CONTENT-->
    <div class="panel-body">
        <?php 
Pjax::begin(['linkSelector' => '.pjax', 'enablePushState' => true, 'timeout' => 10000]);
?>
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'filterRowOptions' => ['class' => 'm-b-sm m-t-sm'], 'options' => ['class' => 'project-list'], 'tableOptions' => ['id' => 'my-grid', 'class' => 'table table-hover'], 'summary' => "", 'columns' => [['headerOptions' => ['class' => 'text-center col-md-1'], 'format' => 'html', 'label' => Yii::t('shop', 'Position'), 'value' => function ($model) {
    $buttonUp = Html::a('', Url::toRoute(['up', 'id' => $model->id]), ['class' => 'pjax product-nav glyphicon glyphicon-arrow-up text-primary pull-left']);
    $buttonDown = Html::a('', Url::toRoute(['down', 'id' => $model->id]), ['class' => 'pjax product-nav glyphicon glyphicon-arrow-down text-primary pull-left']);
    return $buttonUp . $model->position . $buttonDown;
}, 'contentOptions' => ['class' => 'vote-actions col-md-1']], ['headerOptions' => ['class' => 'text-center col-md-4'], 'attribute' => 'title', 'value' => function ($model) {
    $content = Html::a($model->translation->title, Url::toRoute(['save', 'id' => $model->id, 'languageId' => Language::getCurrent()->id]));
    $content .= '<br><small>' . Yii::t('shop', 'Created') . ' ' . $model->creation_time . '</small>';
    return $content;
}, 'label' => Yii::t('shop', 'Title'), 'format' => 'html', 'contentOptions' => ['class' => 'project-title col-md-4']], ['headerOptions' => ['class' => 'text-center col-md-2'], 'attribute' => 'category', 'value' => 'category.translation.title', 'label' => Yii::t('shop', 'Category'), 'format' => 'text', 'filter' => ArrayHelper::map(Category::find()->all(), 'id', 'translation.title'), 'contentOptions' => ['class' => 'project-title col-md-2']], ['headerOptions' => ['class' => 'text-center col-md-1'], 'value' => 'price', 'label' => Yii::t('shop', 'Price'), 'format' => 'text', 'contentOptions' => ['class' => 'col-md-1 text-center']], ['headerOptions' => ['class' => 'text-center col-md-1'], 'attribute' => 'images', 'value' => function ($model) {
    $content = '';
    $number = 3;
    $i = 0;
    foreach ($model->images as $image) {
        if (!empty($image)) {
            if ($i < $number) {
                $content .= Html::img($image->small, ['class' => 'img-circle']);
                $i++;
            }
        }
    }
    return Html::a($content, Url::toRoute(['add-image', 'id' => $model->id, 'languageId' => Language::getCurrent()->id]));
}, 'label' => Yii::t('shop', 'Images'), 'format' => 'html', 'contentOptions' => ['class' => 'col-md-1 project-people']], ['headerOptions' => ['class' => 'text-center col-md-1'], 'attribute' => \Yii::t('shop', 'Status'), 'value' => function ($model) {
    switch ($model->status) {
        case Product::STATUS_ON_MODERATION:
コード例 #4
0
ファイル: UrlRule.php プロジェクト: black-lamp/blcms-shop
 private function findCategoryBySeoUrl($seoUrl, $parentId, $options = [])
 {
     $categoriesSeoData = SeoData::find()->where(['entity_name' => CategoryTranslation::className(), 'seo_url' => $seoUrl])->all();
     if ($categoriesSeoData) {
         foreach ($categoriesSeoData as $categorySeoData) {
             if ($category = Category::find()->joinWith('translations translation')->where(array_merge(['translation.id' => $categorySeoData->entity_id, 'parent_id' => $parentId, 'translation.language_id' => $this->currentLanguage->id], $options))->one()) {
                 return $category;
             }
         }
     }
     return null;
 }
コード例 #5
0
 /**
  * Basic category settings
  *
  * @param integer $languageId
  * @param integer $id
  * @return mixed
  * @throws ForbiddenHttpException
  */
 public function actionAddBasic($id = null, $languageId = null)
 {
     if (!empty($id)) {
         $category = Category::findOne($id);
         $category_translation = CategoryTranslation::find()->where(['category_id' => $id, 'language_id' => $languageId])->one();
         if (empty($category_translation)) {
             $category_translation = new CategoryTranslation();
         }
     } else {
         $category = new Category();
         $category_translation = new CategoryTranslation();
     }
     if (Yii::$app->request->isPost) {
         $category->load(Yii::$app->request->post());
         $category_translation->load(Yii::$app->request->post());
         if ($category->validate() && $category_translation->validate()) {
             $category->save();
             $category_translation->category_id = $category->id;
             $category_translation->language_id = $languageId;
             $category_translation->save();
             Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
         }
     }
     $maxPositionCategory = Category::find()->where(['parent_id' => $category->parent_id])->orderBy(['position' => SORT_DESC])->one();
     $maxPosition = !empty($maxPositionCategory) ? $maxPositionCategory->position : 0;
     $minPositionCategory = Category::find()->where(['parent_id' => $category->parent_id])->orderBy(['position' => SORT_ASC])->one();
     $minPosition = !empty($minPositionCategory) ? $minPositionCategory->position : 0;
     return $this->render('save', ['category' => $category, 'languageId' => $languageId, 'languages' => Language::findAll(['active' => true]), 'viewName' => 'add-basic', 'selectedLanguage' => Language::findOne($languageId), 'params' => ['category' => $category, 'category_translation' => $category_translation, 'languageId' => $languageId, 'selectedLanguage' => Language::findOne($languageId), 'maxPosition' => $maxPosition, 'minPosition' => $minPosition]]);
 }