Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
newitem.php
1<?php
2
4
8use \Bitrix\Location\Service;
9
14final class NewItem extends Save
15{
20 public function save(Location $location): Result
21 {
22 if($existedLocation = $this->findLocalSavedLocation($location))
23 {
24 $location->setId($existedLocation->getId());
25 $location->setCode($existedLocation->getCode());
26 }
27
28 $result = new Result();
29
30 foreach($this->locationRepositories as $repository)
31 {
32 $res = $repository->save($location);
33
34 if(!$res->isSuccess())
35 {
36 $result->addErrors($res->getErrors());
37 }
38 }
39
40 if($parents = $location->getParents())
41 {
42 $res = $this->saveParents($parents);
43
44 if (!$res->isSuccess())
45 {
46 $result->addErrors($res->getErrors());
47 }
48 }
49
50 return $result;
51 }
52
58 protected function findLocalSavedLocation(Location $location)
59 {
60 return Service\LocationService::getInstance()->findByExternalId(
61 $location->getExternalId(),
62 $location->getSourceCode(),
63 $location->getLanguageId(),
64 LOCATION_SEARCH_SCOPE_INTERNAL
65 );
66 }
67}
saveParents(Location\Parents $parents)
Definition save.php:105