public function getCategoryLang($lang, $create_it = false) { $model = !empty($this->id) ? CategoryLang::findOne(['category_id' => $this->id, 'lang' => $lang]) : null; if (is_null($model) && !empty($this->id) && $create_it) { $model = new CategoryLang(); $model->category_id = $this->id; $model->lang = $lang; } return $model; }
public function beforeDelete() { if (parent::beforeDelete()) { if (Product::find()->where(['provider_id' => $this->id])->exists()) { Yii::$app->session->setFlash('providers_error', Yii::t('app', 'Cannot delete provider <strong>{prov_name}</strong> because it has products assigned.', ['prov_name' => $this->name])); return false; } else { CategoryLang::deleteAll(['provider_id' => $this->id]); Yii::$app->session->setFlash('providers_info', Yii::t('app', 'Provider <strong>{prov_name}</strong> was successfully deleted.', ['prov_name' => $this->name])); return true; } } else { return false; } }