public function parserProperties($properties_sxe) { foreach ($properties_sxe as $item) { $shop_property = ShopProperties::findOne(['verification_code' => $item->{'Ид'}]); if (!$shop_property) { $shop_property = new ShopProperties(); $shop_property->seq = $shop_property->findLastSequence() + 1; $currentId = null; } else { $currentId = $shop_property->id; } $shop_property->verification_code = strval($item->{'Ид'}); $shop_property->name = strval($item->{'Наименование'}); $shop_property->anchor = strval($item->{'Наименование'}); $shop_property->url = (new Translit())->slugify($item->{'Наименование'}, $shop_property->tableName(), 'url', '_', $currentId); $shop_property->save(); $this->shop_properties[] = $shop_property; } /** @var $shop_group ShopGroups */ foreach ($this->shop_groups as $shop_group) { /** @var $shop_property ShopProperties */ foreach ($this->shop_properties as $shop_property) { if (!ShopGroupProperties::findOne(['shop_groups_id' => $shop_group->id, 'shop_properties_id' => $shop_property->id])) { $shop_group_property = new ShopGroupProperties(); $shop_group_property->shop_groups_id = $shop_group->id; $shop_group_property->shop_properties_id = $shop_property->id; $shop_group_property->save(); } } } return true; }
/** * @inheritdoc */ public function rules() { return [[['shop_properties_id'], 'integer'], [['name', 'anchor', 'url'], 'string', 'max' => 255], [['shop_properties_id'], 'exist', 'skipOnError' => true, 'targetClass' => ShopProperties::className(), 'targetAttribute' => ['shop_properties_id' => 'id']]]; }
/** * @return \yii\db\ActiveQuery */ public function getShopProperty() { return $this->hasOne(ShopProperties::className(), ['id' => 'shop_properties_id']); }