Ejemplo n.º 1
0
 private function addGood($item, $verificationCode)
 {
     $group = ShopGroups::findOne(['verification_code' => strval($item->{'Группы'}->{'Ид'})]);
     $good = ShopGoods::findOne(['verification_code' => $verificationCode]);
     if ($good) {
         $link = Links::findOne($good->links_id);
     }
     if (!isset($link)) {
         $link = new Links();
     }
     $translit = new Translit();
     $link->categories_id = Yii::$app->params['shop']['categoriesId'];
     $link->parent = $group->links_id;
     $link->anchor = strval(isset($item->{'НаименованиеНаСайте'}) && $item->{'НаименованиеНаСайте'} ? $item->{'НаименованиеНаСайте'} : $item->{'Наименование'});
     $link->name = isset($link->id) ? $translit->slugify($link->anchor, $link->tableName(), 'name', '-', $link->id) : $translit->slugify($link->anchor, $link->tableName(), 'name', '-', null);
     $link->level = $group->link->level + 1;
     $link->url = (new Links())->getPrefixUrl(Yii::$app->params['shop']['goodUrlPrefix'], $link->level, $group->links_id) . '/' . $link->name;
     $link->child_exist = 0;
     $link->seq = isset($link->id) ? $link->seq : Links::findLastSequence(Yii::$app->params['shop']['categoriesId'], $link->parent) + 1;
     $link->title = isset($link->id) ? $link->title : $link->anchor;
     $link->created_at = isset($link->id) ? $link->created_at : time();
     $link->updated_at = time();
     $link->state = $item->{'НеПубликуетсяНаСайте'} == 'истина' ? 0 : 1;
     $link->layouts_id = Yii::$app->params['shop']['good_layouts_id'];
     $link->views_id = Yii::$app->params['shop']['good_views_id'];
     $link->save();
     $content = Contents::findOne(['links_id' => $link->id]);
     if (!$content) {
         $content = new Contents();
         $content->links_id = $link->id;
         $content->seq = 1;
     }
     $content->text = strval($item->{'Описание'});
     $content->save();
     if (!$good) {
         $good = new ShopGoods();
         $good->shop_groups_id = $group->id;
         $good->verification_code = $verificationCode;
     }
     $good->links_id = $link->id;
     $shopUnit = ShopUnits::findOne(['name' => $item->{'БазоваяЕдиница'}]);
     if (!$shopUnit) {
         $shopUnit = new ShopUnits();
         $shopUnit->name = strval($item->{'БазоваяЕдиница'});
         $shopUnit->save();
     }
     $good->shop_units_id = $shopUnit->id;
     $good->name = strval($item->{'Наименование'});
     $good->code = preg_replace('/^\\D+0*/', '', $item->{'КодНоменклатуры'});
     $good->state = 1;
     $good->save();
     if ($item->{'Картинки'} && $item->{'Картинки'}->{'Картинка'}) {
         $this->addImage($item->{'Картинки'}->{'Картинка'}, Yii::$app->params['shop']['gallery']['good'], $link->id, $good->id);
     }
     return ['id' => $good->id, 'links_id' => $link->id];
 }
Ejemplo n.º 2
0
 public function getShopUnit()
 {
     return $this->hasOne(ShopUnits::className(), ['id' => 'shop_units_id']);
 }