/**
  * Sets the categories. Non-existing categories will be created immediately.
  */
 protected function setCategories()
 {
     // No categories
     if (is_null($this->ItemBase->Categories)) {
         return;
     }
     if (is_null(self::$CategoryApi)) {
         self::$CategoryApi = Shopware\Components\Api\Manager::getResource('Category');
     }
     if (is_null(self::$CategoryRepository)) {
         self::$CategoryRepository = Shopware()->Models()->getRepository('Shopware\\Models\\Category\\Category');
     }
     // Categories
     /** @var PlentySoapObject_ItemCategory $Category */
     foreach ($this->ItemBase->Categories->item as $Category) {
         // FIX: corrupt category within plenty
         if ((int) $Category->ItemCategoryID <= 0 || empty($Category->ItemCategoryPathNames)) {
             continue;
         }
         try {
             $categoryId = PlentymarketsMappingEntityCategory::getCategoryByPlentyID($Category->ItemCategoryID, $this->storeId);
             $this->categories[] = array('id' => $categoryId);
         } catch (PlentymarketsMappingExceptionNotExistant $E) {
             $importEntityItemCategoryTree = new PlentymarketsImportEntityItemCategoryTree($Category, $this->storeId);
             $categoryId = $importEntityItemCategoryTree->import();
             // Only create a mapping and connect the category to the item,
             // of nothing went wrong during creation
             if ($categoryId) {
                 $this->categories[] = array('id' => $categoryId);
             }
         }
     }
 }