コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductType::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['parentName'] = ['asc' => ['parent.name' => SORT_ASC], 'desc' => ['parent.name' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         $dataProvider->getSort() !== false ? $query->joinWith(['parentRelation']) : $query->with('parentRelation');
         return $dataProvider;
     } else {
         $query->joinWith(['parentRelation']);
     }
     $query->andFilterWhere(['like', '{{%product_types}}.name', $this->name]);
     $query->andFilterWhere(['like', 'parent.name', $this->parentName]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: _attributes.php プロジェクト: manyoubaby123/imshop
<?php

use im\catalog\models\ProductType;
use im\eav\widgets\EAVEditor;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model im\catalog\models\Product */
/* @var $form yii\widgets\ActiveForm */
$attributes = $model->getEAttributes();
if (!$attributes) {
    $attributes = $model->getAvailableEAttributes();
}
?>

<?php 
echo $form->field($model, 'type_id')->dropDownList(ArrayHelper::map(ProductType::find()->asArray()->orderBy('name')->all(), 'id', 'name'), ['prompt' => '']);
?>

<?php 
echo EAVEditor::widget(['attributes' => $attributes, 'form' => $form, 'model' => $model, 'options' => ['id' => 'eav-editor']]);
?>

<?php 
$script = <<<JS
    var type = \$('[name="Product[type_id]"]');
    var editor = \$('#eav-editor').eavEditor();
    type.on('change', function() {
        \$.ajax({
            url: '/api/v1/product-types/' + \$(this).val() + '/attributes',
            dataType: 'json'
        })