/**
  * @param $data
  * @param null|StoreCategory $parent
  */
 public function importCategories($data, $parent = null)
 {
     foreach ($data->{"Группа"} as $category) {
         // Find category by external id
         $model = C1ExternalFinder::getObject(C1ExternalFinder::OBJECT_TYPE_CATEGORY, $category->{"Ид"});
         if (!$model) {
             $model = new StoreCategory();
             $model->name = $category->{"Наименование"};
             $model->appendTo($this->getRootCategory());
             $this->createExternalId(C1ExternalFinder::OBJECT_TYPE_CATEGORY, $model->id, $category->{"Ид"});
         }
         if ($parent === null) {
             $model->moveAsLast($this->getRootCategory());
         } else {
             $model->moveAsLast($parent);
         }
         $model->saveNode();
         // Process subcategories
         if (isset($category->{"Группы"})) {
             $this->importCategories($category->{"Группы"}, $model);
         }
     }
 }