public function init() { $this->name = \Yii::t('v3toys/skeeks', 'Города доставки'); $this->modelShowAttribute = "id"; $this->modelClassName = V3toysShippingCity::className(); parent::init(); }
/** * Загрузка данных по городам доставки */ public function actionSippingCity() { $shippingData = [['name' => 'Москва', 'shipping_type' => V3toysOrder::SHIPPING_METHOD_PICKUP, 'price' => '99'], ['name' => 'Санкт-Петербург', 'shipping_type' => V3toysOrder::SHIPPING_METHOD_PICKUP, 'price' => '99'], ['name' => 'Ленинградская область', 'shipping_type' => V3toysOrder::SHIPPING_METHOD_COURIER, 'price' => '299'], ['name' => 'Московская область', 'shipping_type' => V3toysOrder::SHIPPING_METHOD_COURIER, 'price' => '199'], ['name' => 'Санкт-Петербург до КАД', 'shipping_type' => V3toysOrder::SHIPPING_METHOD_COURIER, 'price' => '299'], ['name' => 'Москва до МКАД', 'shipping_type' => V3toysOrder::SHIPPING_METHOD_COURIER, 'price' => '199']]; foreach ($shippingData as $data) { if (!($city = V3toysShippingCity::find()->where(['name' => ArrayHelper::getValue($data, 'name')])->one())) { $city = new V3toysShippingCity(); } $city->setAttributes($data); if ($city->save()) { $this->stdout("{$city->name}\n", Console::FG_GREEN); } else { $json = Json::encode($city->firstErrors); $this->stdout("{$city->name} — error: {$json}\n", Console::FG_RED); } } }