Commit 4a447a249a69b9f9f2db47dc2ba93f41b6c5db18
1 parent
9fd505a3
Catalog begin
Showing
9 changed files
with
960 additions
and
8 deletions
Show diff stats
CatalogUrlManager.php
models/ProductFrontendSearch.php
| ... | ... | @@ -53,7 +53,7 @@ class ProductFrontendSearch extends Product { |
| 53 | 53 | * |
| 54 | 54 | * @param array $params |
| 55 | 55 | * |
| 56 | - * @return ActiveDataProvider | |
| 56 | + * @return ArrayDataProvider | |
| 57 | 57 | */ |
| 58 | 58 | public function search($category = null, $params = [], $in_stock = true) { |
| 59 | 59 | |
| ... | ... | @@ -61,7 +61,6 @@ class ProductFrontendSearch extends Product { |
| 61 | 61 | $dataProvider = new ArrayDataProvider([ |
| 62 | 62 | 'allModels' => $this->getSearchQuery($category, $params, $in_stock)->with([ |
| 63 | 63 | 'images', |
| 64 | -// 'events', | |
| 65 | 64 | 'variant', |
| 66 | 65 | 'variant.image', |
| 67 | 66 | 'comments', |
| ... | ... | @@ -72,11 +71,17 @@ class ProductFrontendSearch extends Product { |
| 72 | 71 | ], |
| 73 | 72 | 'sort' => [ |
| 74 | 73 | 'attributes' => [ |
| 75 | - 'name' => [ | |
| 74 | + 'name_asc' => [ | |
| 76 | 75 | 'asc' => ['name' => SORT_ASC], |
| 76 | + 'desc' => ['name' => SORT_ASC], | |
| 77 | + 'default' => SORT_ASC, | |
| 78 | + 'label' => 'имени от А до Я', | |
| 79 | + ], | |
| 80 | + 'name_desc' => [ | |
| 81 | + 'asc' => ['name' => SORT_DESC], | |
| 77 | 82 | 'desc' => ['name' => SORT_DESC], |
| 78 | 83 | 'default' => SORT_DESC, |
| 79 | - 'label' => 'имени', | |
| 84 | + 'label' => 'имени от Я до А', | |
| 80 | 85 | ], |
| 81 | 86 | 'price' => [ |
| 82 | 87 | 'asc' => ['price' => SORT_ASC], |
| ... | ... | @@ -87,10 +92,7 @@ class ProductFrontendSearch extends Product { |
| 87 | 92 | ], |
| 88 | 93 | ] |
| 89 | 94 | ]); |
| 90 | - | |
| 91 | - | |
| 92 | - | |
| 93 | - | |
| 95 | + | |
| 94 | 96 | |
| 95 | 97 | return $dataProvider; |
| 96 | 98 | } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; | |
| 6 | + use artweb\artbox\language\models\Language; | |
| 7 | + use yii\base\InvalidValueException; | |
| 8 | + use yii\db\ActiveQuery; | |
| 9 | + use yii\db\ActiveRecord; | |
| 10 | + use yii\web\Request; | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * This is the model class for table "{{%tax_group}}". | |
| 14 | + * | |
| 15 | + * @property integer $id | |
| 16 | + * @property boolean $is_filter | |
| 17 | + * @property integer $sort | |
| 18 | + * @property boolean $display | |
| 19 | + * @property boolean $is_menu | |
| 20 | + * @property string $remote_id | |
| 21 | + * @property TaxVariantOption[] $taxOptions | |
| 22 | + * @property TaxVariantOption[] $taxVariantOptions | |
| 23 | + * @property Category[] $categories | |
| 24 | + * @property TaxVariantOption[] $options | |
| 25 | + * @property TaxVariantOption[] $customOptions | |
| 26 | + * @property string $alias | |
| 27 | + * * From language behavior * | |
| 28 | + * @property TaxVariantGroupLang $lang | |
| 29 | + * @property TaxVariantGroupLang[] $langs | |
| 30 | + * @property TaxVariantGroupLang $objectLang | |
| 31 | + * @property string $ownerKey | |
| 32 | + * @property string $langKey | |
| 33 | + * @property TaxVariantGroupLang[] $modelLangs | |
| 34 | + * @property bool $transactionStatus | |
| 35 | + * @method string getOwnerKey() | |
| 36 | + * @method void setOwnerKey( string $value ) | |
| 37 | + * @method string getLangKey() | |
| 38 | + * @method void setLangKey( string $value ) | |
| 39 | + * @method ActiveQuery getLangs() | |
| 40 | + * @method ActiveQuery getLang( integer $language_id ) | |
| 41 | + * @method TaxGroupLang[] generateLangs() | |
| 42 | + * @method void loadLangs( Request $request ) | |
| 43 | + * @method bool linkLangs() | |
| 44 | + * @method bool saveLangs() | |
| 45 | + * @method bool getTransactionStatus() | |
| 46 | + * * End language behavior * | |
| 47 | + */ | |
| 48 | + class TaxVariantGroup extends ActiveRecord | |
| 49 | + { | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var TaxVariantOption[] $options | |
| 53 | + */ | |
| 54 | + protected $customOptions = []; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @inheritdoc | |
| 58 | + */ | |
| 59 | + public function behaviors() | |
| 60 | + { | |
| 61 | + return [ | |
| 62 | + 'language' => [ | |
| 63 | + 'class' => LanguageBehavior::className(), | |
| 64 | + ], | |
| 65 | + ]; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @inheritdoc | |
| 70 | + */ | |
| 71 | + public static function tableName() | |
| 72 | + { | |
| 73 | + return 'tax_variant_group'; | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * @inheritdoc | |
| 78 | + */ | |
| 79 | + public function rules() | |
| 80 | + { | |
| 81 | + return [ | |
| 82 | + [ | |
| 83 | + [ | |
| 84 | + 'is_filter', | |
| 85 | + 'display', | |
| 86 | + 'is_menu', | |
| 87 | + ], | |
| 88 | + 'boolean', | |
| 89 | + ], | |
| 90 | + [ | |
| 91 | + [ | |
| 92 | + 'sort', | |
| 93 | + ], | |
| 94 | + 'integer', | |
| 95 | + ], | |
| 96 | + [ | |
| 97 | + [ 'categories' ], | |
| 98 | + 'safe', | |
| 99 | + ], | |
| 100 | + ]; | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * @inheritdoc | |
| 105 | + */ | |
| 106 | + public function attributeLabels() | |
| 107 | + { | |
| 108 | + return [ | |
| 109 | + 'id' => 'Tax Group ID', | |
| 110 | + 'is_filter' => 'Use in filter', | |
| 111 | + 'sort' => 'Sort', | |
| 112 | + 'display' => 'Display', | |
| 113 | + 'is_menu' => 'Отображать в меню', | |
| 114 | + ]; | |
| 115 | + } | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * @return ActiveQuery | |
| 119 | + */ | |
| 120 | + public function getCategories() | |
| 121 | + { | |
| 122 | + return $this->hasMany(Category::className(), [ 'id' => 'category_id' ]) | |
| 123 | + ->viaTable('tax_variant_group_to_category', [ 'tax_variant_group_id' => 'id' ]); | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Set categories to override tax_variant_group_to_category table data | |
| 128 | + * | |
| 129 | + * @param int[] $values | |
| 130 | + */ | |
| 131 | + public function setCategories(array $values) | |
| 132 | + { | |
| 133 | + $this->categories = $values; | |
| 134 | + } | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * @inheritdoc | |
| 138 | + */ | |
| 139 | + public function afterSave($insert, $changedAttributes) | |
| 140 | + { | |
| 141 | + parent::afterSave($insert, $changedAttributes); | |
| 142 | + $this->unlinkAll('categories', true); | |
| 143 | + $categories = []; | |
| 144 | + if (!empty( $this->categories )) { | |
| 145 | + $categories = Category::findAll($this->categories); | |
| 146 | + } | |
| 147 | + foreach ($categories as $category) { | |
| 148 | + $this->link('categories', $category); | |
| 149 | + } | |
| 150 | + } | |
| 151 | + | |
| 152 | + public function getTaxVariantOptions() | |
| 153 | + { | |
| 154 | + return $this->hasMany(TaxVariantOption::className(), [ 'tax_variant_group_id' => 'id' ]) | |
| 155 | + ->inverseOf('taxVariantGroup'); | |
| 156 | + } | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * @return ActiveQuery | |
| 160 | + */ | |
| 161 | + public function getTaxOptions() | |
| 162 | + { | |
| 163 | + return $this->getTaxVariantOptions(); | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Synonim for getTaxOptions() | |
| 168 | + * | |
| 169 | + * @see TaxGroup::getTaxOptions() | |
| 170 | + * @return \yii\db\ActiveQuery | |
| 171 | + */ | |
| 172 | + public function getOptions() | |
| 173 | + { | |
| 174 | + return $this->getTaxOptions(); | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * Get customOptins that were filled dynamically. | |
| 179 | + * If $fillDefault is true then fill $customOptions with TaxOptions for current TaxGroup | |
| 180 | + * | |
| 181 | + * @param bool $fillDefault | |
| 182 | + * | |
| 183 | + * @return TaxOption[] | |
| 184 | + */ | |
| 185 | + public function getCustomOptions(bool $fillDefault = false): array | |
| 186 | + { | |
| 187 | + if ($fillDefault && empty( $this->custom_options )) { | |
| 188 | + $this->customOptions = $this->getTaxVariantOptions() | |
| 189 | + ->with('lang') | |
| 190 | + ->all(); | |
| 191 | + } | |
| 192 | + return $this->customOptions; | |
| 193 | + } | |
| 194 | + | |
| 195 | + /** | |
| 196 | + * Set customOptions | |
| 197 | + * | |
| 198 | + * @param TaxOption[] $value | |
| 199 | + */ | |
| 200 | + public function setCustomOptions(array $value) | |
| 201 | + { | |
| 202 | + foreach ($value as $item) { | |
| 203 | + if (!( $item instanceof TaxVariantOption )) { | |
| 204 | + throw new InvalidValueException( | |
| 205 | + 'All elements must be instances of ' . TaxVariantOption::className() | |
| 206 | + ); | |
| 207 | + } | |
| 208 | + } | |
| 209 | + $this->customOptions = $value; | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * Get default lang alias | |
| 214 | + * | |
| 215 | + * @return string | |
| 216 | + */ | |
| 217 | + public function getAlias() | |
| 218 | + { | |
| 219 | + $default_lang = Language::getDefaultLanguage(); | |
| 220 | + /** | |
| 221 | + * @var TaxVariantGroupLang $lang | |
| 222 | + */ | |
| 223 | + $lang = $this->getLang($default_lang->id) | |
| 224 | + ->one(); | |
| 225 | + return $lang->alias; | |
| 226 | + } | |
| 227 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\models\Language; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveRecord; | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * This is the model class for table "tax_variant_group_lang". | |
| 11 | + * | |
| 12 | + * @property integer $tax_variant_group_id | |
| 13 | + * @property integer $language_id | |
| 14 | + * @property string $title | |
| 15 | + * @property string $alias | |
| 16 | + * @property string $description | |
| 17 | + * @property Language $language | |
| 18 | + * @property TaxVariantGroup $taxGroup | |
| 19 | + */ | |
| 20 | + class TaxVariantGroupLang extends ActiveRecord | |
| 21 | + { | |
| 22 | + | |
| 23 | + public static function primaryKey() | |
| 24 | + { | |
| 25 | + return [ | |
| 26 | + 'tax_variant_group_id', | |
| 27 | + 'language_id', | |
| 28 | + ]; | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @inheritdoc | |
| 33 | + */ | |
| 34 | + public static function tableName() | |
| 35 | + { | |
| 36 | + return 'tax_variant_group_lang'; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public function behaviors() | |
| 40 | + { | |
| 41 | + return [ | |
| 42 | + 'slug' => [ | |
| 43 | + 'class' => 'artweb\artbox\behaviors\Slug', | |
| 44 | + ], | |
| 45 | + ]; | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @inheritdoc | |
| 50 | + */ | |
| 51 | + public function rules() | |
| 52 | + { | |
| 53 | + return [ | |
| 54 | + [ | |
| 55 | + [ 'title' ], | |
| 56 | + 'required', | |
| 57 | + ], | |
| 58 | + [ | |
| 59 | + [ 'description' ], | |
| 60 | + 'string', | |
| 61 | + ], | |
| 62 | + [ | |
| 63 | + [ | |
| 64 | + 'title', | |
| 65 | + 'alias', | |
| 66 | + ], | |
| 67 | + 'string', | |
| 68 | + 'max' => 255, | |
| 69 | + ], | |
| 70 | + [ | |
| 71 | + [ | |
| 72 | + 'tax_variant_group_id', | |
| 73 | + 'language_id', | |
| 74 | + ], | |
| 75 | + 'unique', | |
| 76 | + 'targetAttribute' => [ | |
| 77 | + 'tax_variant_group_id', | |
| 78 | + 'language_id', | |
| 79 | + ], | |
| 80 | + 'message' => 'The combination of Tax Variant Group ID and Language ID has already been taken.', | |
| 81 | + ], | |
| 82 | + [ | |
| 83 | + [ 'language_id' ], | |
| 84 | + 'exist', | |
| 85 | + 'skipOnError' => true, | |
| 86 | + 'targetClass' => Language::className(), | |
| 87 | + 'targetAttribute' => [ 'language_id' => 'id' ], | |
| 88 | + ], | |
| 89 | + [ | |
| 90 | + [ 'tax_variant_group_id' ], | |
| 91 | + 'exist', | |
| 92 | + 'skipOnError' => true, | |
| 93 | + 'targetClass' => TaxVariantGroup::className(), | |
| 94 | + 'targetAttribute' => [ 'tax_variant_group_id' => 'id' ], | |
| 95 | + ], | |
| 96 | + ]; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * @inheritdoc | |
| 101 | + */ | |
| 102 | + public function attributeLabels() | |
| 103 | + { | |
| 104 | + return [ | |
| 105 | + 'tax_variant_group_id' => Yii::t('app', 'Tax Variant Group ID'), | |
| 106 | + 'language_id' => Yii::t('app', 'Language ID'), | |
| 107 | + 'title' => Yii::t('app', 'Name'), | |
| 108 | + 'description' => Yii::t('app', 'Description'), | |
| 109 | + 'alias' => Yii::t('app', 'Alias'), | |
| 110 | + ]; | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * @return \yii\db\ActiveQuery | |
| 115 | + */ | |
| 116 | + public function getLanguage() | |
| 117 | + { | |
| 118 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * @return \yii\db\ActiveQuery | |
| 123 | + */ | |
| 124 | + public function getTaxVariantGroup() | |
| 125 | + { | |
| 126 | + return $this->hasOne(TaxVariantGroup::className(), [ 'id' => 'tax_variant_group_id' ]); | |
| 127 | + } | |
| 128 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use yii\base\Model; | |
| 6 | + use yii\data\ActiveDataProvider; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * TaxVariantGroupSearch represents the model behind the search form about | |
| 10 | + * `artweb\artbox\ecommerce\models\TaxVariantGroup`. | |
| 11 | + */ | |
| 12 | + class TaxVariantGroupSearch extends TaxVariantGroup | |
| 13 | + { | |
| 14 | + | |
| 15 | + public $groupName; | |
| 16 | + | |
| 17 | + public function behaviors() | |
| 18 | + { | |
| 19 | + $behaviors = parent::behaviors(); | |
| 20 | + if (isset( $behaviors[ 'language' ] )) { | |
| 21 | + unset( $behaviors[ 'language' ] ); | |
| 22 | + } | |
| 23 | + return $behaviors; | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public function rules() | |
| 30 | + { | |
| 31 | + return [ | |
| 32 | + [ | |
| 33 | + [ | |
| 34 | + 'id', | |
| 35 | + ], | |
| 36 | + 'integer', | |
| 37 | + ], | |
| 38 | + [ | |
| 39 | + [ | |
| 40 | + 'is_filter', | |
| 41 | + ], | |
| 42 | + 'boolean', | |
| 43 | + ], | |
| 44 | + [ | |
| 45 | + [ | |
| 46 | + 'groupName', | |
| 47 | + ], | |
| 48 | + 'safe', | |
| 49 | + ], | |
| 50 | + ]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @inheritdoc | |
| 55 | + */ | |
| 56 | + public function scenarios() | |
| 57 | + { | |
| 58 | + // bypass scenarios() implementation in the parent class | |
| 59 | + return Model::scenarios(); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Creates data provider instance with search query applied | |
| 64 | + * | |
| 65 | + * @param array $params | |
| 66 | + * | |
| 67 | + * @return ActiveDataProvider | |
| 68 | + */ | |
| 69 | + public function search($params) | |
| 70 | + { | |
| 71 | + $query = TaxVariantGroup::find() | |
| 72 | + ->joinWith('lang'); | |
| 73 | + | |
| 74 | + $dataProvider = new ActiveDataProvider( | |
| 75 | + [ | |
| 76 | + 'query' => $query, | |
| 77 | + 'sort' => [ | |
| 78 | + 'attributes' => [ | |
| 79 | + 'id', | |
| 80 | + 'is_filter', | |
| 81 | + 'groupName' => [ | |
| 82 | + 'asc' => [ 'tax_variant_group_lang.title' => SORT_ASC ], | |
| 83 | + 'desc' => [ 'tax_variant_group_lang.title' => SORT_DESC ], | |
| 84 | + ], | |
| 85 | + ], | |
| 86 | + ], | |
| 87 | + ] | |
| 88 | + ); | |
| 89 | + | |
| 90 | + $this->load($params); | |
| 91 | + | |
| 92 | + if (!$this->validate()) { | |
| 93 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 94 | + // $query->where('0=1'); | |
| 95 | + return $dataProvider; | |
| 96 | + } | |
| 97 | + | |
| 98 | + $query->andFilterWhere( | |
| 99 | + [ | |
| 100 | + 'id' => $this->id, | |
| 101 | + 'is_filter' => $this->is_filter, | |
| 102 | + ] | |
| 103 | + ) | |
| 104 | + ->andFilterWhere( | |
| 105 | + [ | |
| 106 | + 'ilike', | |
| 107 | + 'tax_variant_group_lang.title', | |
| 108 | + $this->groupName, | |
| 109 | + ] | |
| 110 | + ); | |
| 111 | + | |
| 112 | + return $dataProvider; | |
| 113 | + } | |
| 114 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use yii\db\ActiveRecord; | |
| 6 | + | |
| 7 | + /** | |
| 8 | + * This is the model class for table "tax_variant_group_to_category". | |
| 9 | + * | |
| 10 | + * @property integer $tax_group_to_category_id | |
| 11 | + * @property integer $tax_group_id | |
| 12 | + * @property integer $category_id | |
| 13 | + * @property Category $category | |
| 14 | + * @property TaxVariantGroup $taxGroup | |
| 15 | + * @property TaxVariantGroup $taxVariantGroup | |
| 16 | + */ | |
| 17 | + class TaxVariantGroupToCategory extends ActiveRecord | |
| 18 | + { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * @inheritdoc | |
| 22 | + */ | |
| 23 | + public static function tableName() | |
| 24 | + { | |
| 25 | + return 'tax_variant_group_to_category'; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @inheritdoc | |
| 30 | + */ | |
| 31 | + public function rules() | |
| 32 | + { | |
| 33 | + return [ | |
| 34 | + [ | |
| 35 | + [ | |
| 36 | + 'tax_variant_group_id', | |
| 37 | + 'category_id', | |
| 38 | + ], | |
| 39 | + 'required', | |
| 40 | + ], | |
| 41 | + [ | |
| 42 | + [ | |
| 43 | + 'tax_variant_group_id', | |
| 44 | + 'category_id', | |
| 45 | + ], | |
| 46 | + 'integer', | |
| 47 | + ], | |
| 48 | + [ | |
| 49 | + [ 'category_id' ], | |
| 50 | + 'exist', | |
| 51 | + 'skipOnError' => true, | |
| 52 | + 'targetClass' => Category::className(), | |
| 53 | + 'targetAttribute' => [ 'category_id' => 'id' ], | |
| 54 | + ], | |
| 55 | + [ | |
| 56 | + [ 'tax_variant_group_id' ], | |
| 57 | + 'exist', | |
| 58 | + 'skipOnError' => true, | |
| 59 | + 'targetClass' => TaxVariantGroup::className(), | |
| 60 | + 'targetAttribute' => [ 'tax_variant_group_id' => 'id' ], | |
| 61 | + ], | |
| 62 | + ]; | |
| 63 | + } | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * @inheritdoc | |
| 67 | + */ | |
| 68 | + public function attributeLabels() | |
| 69 | + { | |
| 70 | + return [ | |
| 71 | + 'id' => 'Tax Variant Group To Category ID', | |
| 72 | + 'tax_variant_group_id' => 'Tax Variant Group ID', | |
| 73 | + 'category_id' => 'Category ID', | |
| 74 | + ]; | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * @return \yii\db\ActiveQuery | |
| 79 | + */ | |
| 80 | + public function getCategory() | |
| 81 | + { | |
| 82 | + return $this->hasOne(Category::className(), [ 'id' => 'category_id' ]); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * @return \yii\db\ActiveQuery | |
| 87 | + */ | |
| 88 | + public function getVariantTaxGroup() | |
| 89 | + { | |
| 90 | + return $this->hasOne(TaxVariantGroup::className(), [ 'id' => 'tax_variant_group_id' ]); | |
| 91 | + } | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * @return \yii\db\ActiveQuery | |
| 95 | + */ | |
| 96 | + public function getTaxGroup() | |
| 97 | + { | |
| 98 | + return $this->getVariantTaxGroup(); | |
| 99 | + } | |
| 100 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\behaviors\SaveImgBehavior; | |
| 6 | + use artweb\artbox\language\behaviors\LanguageBehavior; | |
| 7 | + use Yii; | |
| 8 | + use yii\db\ActiveQuery; | |
| 9 | + use yii\db\ActiveRecord; | |
| 10 | + use yii\web\Request; | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * This is the model class for table "{{%tax_variant_option}}". | |
| 14 | + * | |
| 15 | + * @property string $id | |
| 16 | + * @property integer $tax_variant_group_id | |
| 17 | + * @property integer $sort | |
| 18 | + * @property string $image | |
| 19 | + * @property TaxGroup $taxGroup | |
| 20 | + * @property TaxGroup $group | |
| 21 | + * @property Product[] $products | |
| 22 | + * @property ProductVariant[] $productVariants | |
| 23 | + * * From language behavior * | |
| 24 | + * @property TaxVariantOptionLang $lang | |
| 25 | + * @property TaxVariantOptionLang[] $langs | |
| 26 | + * @property TaxVariantOptionLang $objectLang | |
| 27 | + * @property string $ownerKey | |
| 28 | + * @property string $langKey | |
| 29 | + * @property TaxVariantOptionLang[] $modelLangs | |
| 30 | + * @property bool $transactionStatus | |
| 31 | + * @method string getOwnerKey() | |
| 32 | + * @method void setOwnerKey( string $value ) | |
| 33 | + * @method string getLangKey() | |
| 34 | + * @method void setLangKey( string $value ) | |
| 35 | + * @method ActiveQuery getLangs() | |
| 36 | + * @method ActiveQuery getLang( integer $language_id ) | |
| 37 | + * @method TaxVariantOptionLang[] generateLangs() | |
| 38 | + * @method void loadLangs( Request $request ) | |
| 39 | + * @method bool linkLangs() | |
| 40 | + * @method bool saveLangs() | |
| 41 | + * @method bool getTransactionStatus() | |
| 42 | + * * End language behavior * | |
| 43 | + * * From SaveImgBehavior | |
| 44 | + * @property string|null $imageFile | |
| 45 | + * @property string|null $imageUrl | |
| 46 | + * @method string|null getImageFile( int $field ) | |
| 47 | + * @method string|null getImageUrl( int $field ) | |
| 48 | + * * End SaveImgBehavior | |
| 49 | + */ | |
| 50 | + class TaxVariantOption extends ActiveRecord | |
| 51 | + { | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @inheritdoc | |
| 55 | + */ | |
| 56 | + public function behaviors() | |
| 57 | + { | |
| 58 | + return [ | |
| 59 | + [ | |
| 60 | + 'class' => SaveImgBehavior::className(), | |
| 61 | + 'fields' => [ | |
| 62 | + [ | |
| 63 | + 'name' => 'image', | |
| 64 | + 'directory' => 'tax_option', | |
| 65 | + ], | |
| 66 | + ], | |
| 67 | + ], | |
| 68 | + 'language' => [ | |
| 69 | + 'class' => LanguageBehavior::className(), | |
| 70 | + ], | |
| 71 | + ]; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * @inheritdoc | |
| 76 | + */ | |
| 77 | + public static function tableName() | |
| 78 | + { | |
| 79 | + return '{{%tax_variant_option}}'; | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * @inheritdoc | |
| 84 | + */ | |
| 85 | + public function rules() | |
| 86 | + { | |
| 87 | + return [ | |
| 88 | + [ | |
| 89 | + [ | |
| 90 | + 'tax_variant_group_id', | |
| 91 | + 'sort', | |
| 92 | + ], | |
| 93 | + 'integer', | |
| 94 | + ], | |
| 95 | + [ | |
| 96 | + [ 'tax_variant_group_id' ], | |
| 97 | + 'exist', | |
| 98 | + 'skipOnError' => true, | |
| 99 | + 'targetClass' => TaxVariantGroup::className(), | |
| 100 | + 'targetAttribute' => [ 'tax_variant_group_id' => 'id' ], | |
| 101 | + ], | |
| 102 | + ]; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * @inheritdoc | |
| 107 | + */ | |
| 108 | + public function attributeLabels() | |
| 109 | + { | |
| 110 | + return [ | |
| 111 | + 'id' => Yii::t('app', 'Tax Variant Option ID'), | |
| 112 | + 'tax_variant_group_id' => Yii::t('app', 'Tax Variant Group ID'), | |
| 113 | + 'sort' => Yii::t('app', 'Sort'), | |
| 114 | + 'image' => Yii::t('product', 'Image'), | |
| 115 | + ]; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * @return \yii\db\ActiveQuery | |
| 120 | + */ | |
| 121 | + public function getTaxVariantGroup() | |
| 122 | + { | |
| 123 | + return $this->hasOne(TaxVariantGroup::className(), [ 'id' => 'tax_variant_group_id' ]) | |
| 124 | + ->inverseOf('taxVariantOptions'); | |
| 125 | + } | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * @return \yii\db\ActiveQuery | |
| 129 | + */ | |
| 130 | + public function getTaxGroup() | |
| 131 | + { | |
| 132 | + return $this->getTaxVariantGroup(); | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Synonim for TaxOption::getTaxGroup() | |
| 137 | + * | |
| 138 | + * @see TaxOption::getTaxGroup() | |
| 139 | + * @return \yii\db\ActiveQuery | |
| 140 | + */ | |
| 141 | + public function getGroup() | |
| 142 | + { | |
| 143 | + return $this->getTaxGroup(); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * @return ActiveQuery | |
| 148 | + */ | |
| 149 | + public function getProductVariants() | |
| 150 | + { | |
| 151 | + return $this->hasMany(ProductVariant::className(), [ 'id' => 'product_variant_id' ]) | |
| 152 | + ->viaTable('product_variant_option', [ 'option_id' => 'id' ]); | |
| 153 | + } | |
| 154 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use artweb\artbox\language\models\Language; | |
| 6 | + use Yii; | |
| 7 | + use yii\db\ActiveRecord; | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * This is the model class for table "tax_variant_option_lang". | |
| 11 | + * | |
| 12 | + * @property integer $tax_variant_option_id | |
| 13 | + * @property integer $language_id | |
| 14 | + * @property string $value | |
| 15 | + * @property string $alias | |
| 16 | + * @property Language $language | |
| 17 | + * @property TaxVariantOption $taxVariantOption | |
| 18 | + */ | |
| 19 | + class TaxVariantOptionLang extends ActiveRecord | |
| 20 | + { | |
| 21 | + | |
| 22 | + public static function primaryKey() | |
| 23 | + { | |
| 24 | + return [ | |
| 25 | + 'tax_variant_option_id', | |
| 26 | + 'language_id', | |
| 27 | + ]; | |
| 28 | + } | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @inheritdoc | |
| 32 | + */ | |
| 33 | + public static function tableName() | |
| 34 | + { | |
| 35 | + return 'tax_variant_option_lang'; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public function behaviors() | |
| 39 | + { | |
| 40 | + return [ | |
| 41 | + 'slug' => [ | |
| 42 | + 'class' => 'artweb\artbox\behaviors\Slug', | |
| 43 | + 'inAttribute' => 'value', | |
| 44 | + ], | |
| 45 | + ]; | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @inheritdoc | |
| 50 | + */ | |
| 51 | + public function rules() | |
| 52 | + { | |
| 53 | + return [ | |
| 54 | + [ | |
| 55 | + [ 'value' ], | |
| 56 | + 'required', | |
| 57 | + ], | |
| 58 | + [ | |
| 59 | + [ | |
| 60 | + 'value', | |
| 61 | + 'alias', | |
| 62 | + ], | |
| 63 | + 'string', | |
| 64 | + 'max' => 255, | |
| 65 | + ], | |
| 66 | + [ | |
| 67 | + [ | |
| 68 | + 'tax_variant_option_id', | |
| 69 | + 'language_id', | |
| 70 | + ], | |
| 71 | + 'unique', | |
| 72 | + 'targetAttribute' => [ | |
| 73 | + 'tax_variant_option_id', | |
| 74 | + 'language_id', | |
| 75 | + ], | |
| 76 | + 'message' => 'The combination of Tax Variant Option ID and Language ID has already been taken.', | |
| 77 | + ], | |
| 78 | + [ | |
| 79 | + [ 'language_id' ], | |
| 80 | + 'exist', | |
| 81 | + 'skipOnError' => true, | |
| 82 | + 'targetClass' => Language::className(), | |
| 83 | + 'targetAttribute' => [ 'language_id' => 'id' ], | |
| 84 | + ], | |
| 85 | + [ | |
| 86 | + [ 'tax_variant_option_id' ], | |
| 87 | + 'exist', | |
| 88 | + 'skipOnError' => true, | |
| 89 | + 'targetClass' => TaxVariantOption::className(), | |
| 90 | + 'targetAttribute' => [ 'tax_variant_option_id' => 'id' ], | |
| 91 | + ], | |
| 92 | + ]; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @inheritdoc | |
| 97 | + */ | |
| 98 | + public function attributeLabels() | |
| 99 | + { | |
| 100 | + return [ | |
| 101 | + 'tax_variant_option_id' => Yii::t('app', 'Tax Variant Option ID'), | |
| 102 | + 'language_id' => Yii::t('app', 'Language ID'), | |
| 103 | + 'value' => Yii::t('app', 'Value'), | |
| 104 | + 'alias' => Yii::t('app', 'Alias'), | |
| 105 | + ]; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * @return \yii\db\ActiveQuery | |
| 110 | + */ | |
| 111 | + public function getLanguage() | |
| 112 | + { | |
| 113 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * @return \yii\db\ActiveQuery | |
| 118 | + */ | |
| 119 | + public function getTaxVariantOption() | |
| 120 | + { | |
| 121 | + return $this->hasOne(TaxVariantOption::className(), [ 'id' => 'tax_variant_option_id' ]); | |
| 122 | + } | |
| 123 | + } | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + namespace artweb\artbox\ecommerce\models; | |
| 4 | + | |
| 5 | + use yii\base\Model; | |
| 6 | + use yii\data\ActiveDataProvider; | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * TaxVariantOptionSearch represents the model behind the search form about | |
| 10 | + * `artweb\artbox\ecommerce\models\TaxVariantOption`. | |
| 11 | + */ | |
| 12 | + class TaxVariantOptionSearch extends TaxVariantOption | |
| 13 | + { | |
| 14 | + | |
| 15 | + public $value; | |
| 16 | + | |
| 17 | + public function behaviors() | |
| 18 | + { | |
| 19 | + $behaviors = parent::behaviors(); | |
| 20 | + if (isset( $behaviors[ 'language' ] )) { | |
| 21 | + unset( $behaviors[ 'language' ] ); | |
| 22 | + } | |
| 23 | + return $behaviors; | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public function rules() | |
| 30 | + { | |
| 31 | + return [ | |
| 32 | + [ | |
| 33 | + [ 'value' ], | |
| 34 | + 'safe', | |
| 35 | + ], | |
| 36 | + [ | |
| 37 | + [ 'id' ], | |
| 38 | + 'integer', | |
| 39 | + ], | |
| 40 | + ]; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @inheritdoc | |
| 45 | + */ | |
| 46 | + public function scenarios() | |
| 47 | + { | |
| 48 | + // bypass scenarios() implementation in the parent class | |
| 49 | + return Model::scenarios(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Creates data provider instance with search query applied | |
| 54 | + * | |
| 55 | + * @param array $params | |
| 56 | + * | |
| 57 | + * @return ActiveDataProvider | |
| 58 | + */ | |
| 59 | + public function search($params) | |
| 60 | + { | |
| 61 | + $query = TaxVariantOption::find() | |
| 62 | + ->joinWith('lang'); | |
| 63 | + | |
| 64 | + $dataProvider = new ActiveDataProvider( | |
| 65 | + [ | |
| 66 | + 'query' => $query, | |
| 67 | + 'sort' => [ | |
| 68 | + 'attributes' => [ | |
| 69 | + 'id', | |
| 70 | + 'value' => [ | |
| 71 | + 'asc' => [ 'tax_variant_option_lang.value' => SORT_ASC ], | |
| 72 | + 'desc' => [ 'tax_variant_option_lang.value' => SORT_DESC ], | |
| 73 | + ], | |
| 74 | + ], | |
| 75 | + ], | |
| 76 | + ] | |
| 77 | + ); | |
| 78 | + | |
| 79 | + $this->load($params); | |
| 80 | + | |
| 81 | + // if (!$this->validate()) { | |
| 82 | + // return $dataProvider; | |
| 83 | + // } | |
| 84 | + | |
| 85 | + // grid filtering conditions | |
| 86 | + $query->andFilterWhere( | |
| 87 | + [ | |
| 88 | + 'id' => $this->id, | |
| 89 | + ] | |
| 90 | + ) | |
| 91 | + ->andFilterWhere( | |
| 92 | + [ | |
| 93 | + 'like', | |
| 94 | + 'tax_variant_option_lang.value', | |
| 95 | + $this->value, | |
| 96 | + ] | |
| 97 | + ); | |
| 98 | + | |
| 99 | + return $dataProvider; | |
| 100 | + } | |
| 101 | + } | ... | ... |