/**
  * Returns the root category id
  *
  * @param \Shopware\Models\Category\Category $category
  * @return integer
  */
 public static function getRootIdByCategory(Shopware\Models\Category\Category $category)
 {
     while ($category->getParentId()) {
         $parent = $category->getParent();
         if ($parent->getLevel() == 0) {
             break;
         }
         $category = $parent;
     }
     return $category->getId();
 }
 /**
  * Creates the category in plentymarkets
  *
  * @param \Shopware\Models\Category\Category $category
  * @param $storeId
  * @param $shopId
  * @param null $categoryId
  * @return int|null
  * @throws PlentymarketsExportException
  */
 private function exportCategory(Shopware\Models\Category\Category $category, $storeId, $shopId, $categoryId = null)
 {
     $level = $category->getLevel() - 1;
     if ($level == 1) {
         $parentId = null;
     } else {
         $parentId = PlentymarketsMappingEntityCategory::getCategoryByShopwareID($category->getParentId(), $shopId);
     }
     $Request_SetCategories = new PlentySoapRequest_SetCategories();
     $Request_SetCategories->SetCategories = array();
     $RequestObject_SetCategories = new PlentySoapRequestObject_SetCategories();
     $RequestObject_SetCategories->CategoryID = $categoryId;
     $RequestObject_CreateCategory = new PlentySoapRequestObject_CreateCategory();
     $RequestObject_CreateCategory->Description = null;
     // string
     $RequestObject_CreateCategory->Description2 = null;
     // string
     $RequestObject_CreateCategory->FulltextActive = null;
     // string
     $RequestObject_CreateCategory->Image = null;
     // string
     $RequestObject_CreateCategory->Image1Path = null;
     // string
     $RequestObject_CreateCategory->Image2 = null;
     // string
     $RequestObject_CreateCategory->Image2Path = null;
     // string
     $RequestObject_CreateCategory->ItemListView = null;
     // string
     $RequestObject_CreateCategory->Lang = 'de';
     // string
     $RequestObject_CreateCategory->Level = $level;
     // int
     $RequestObject_CreateCategory->MetaDescription = $category->getMetaDescription();
     // string
     $RequestObject_CreateCategory->MetaKeywords = $category->getMetaKeywords();
     // string
     $RequestObject_CreateCategory->MetaTitle = $category->getName();
     // string
     $RequestObject_CreateCategory->Name = $category->getName() ?: 'Category ' . $category->getId();
     // string
     $RequestObject_CreateCategory->NameURL = null;
     // string
     $RequestObject_CreateCategory->PageView = null;
     // string
     $RequestObject_CreateCategory->PlaceholderTranslation = null;
     // string
     $RequestObject_CreateCategory->Position = $category->getPosition();
     // int
     $RequestObject_CreateCategory->PreviewPath = null;
     // string
     $RequestObject_CreateCategory->RootPath = null;
     // string
     $RequestObject_CreateCategory->ShortDescription = null;
     // string
     $RequestObject_CreateCategory->SingleItemView = null;
     // string
     $RequestObject_CreateCategory->WebTemplateExist = null;
     // string
     $RequestObject_CreateCategory->WebstoreID = $storeId;
     // int
     $RequestObject_CreateCategory->ParentCategoryID = $parentId;
     //int
     $RequestObject_SetCategories->CreateCategory = $RequestObject_CreateCategory;
     $Request_SetCategories->SetCategories[] = $RequestObject_SetCategories;
     $Response_SetCategories = PlentymarketsSoapClient::getInstance()->SetCategories($Request_SetCategories);
     if (!$Response_SetCategories->Success) {
         throw new PlentymarketsExportException('The category could not be saved! ', 2920);
     } else {
         $categoryId = (int) $Response_SetCategories->Categories->item[0]->CategoryID;
         $shopId = PlentymarketsMappingController::getShopByPlentyID($storeId);
         PlentymarketsMappingEntityCategory::addCategory($category->getId(), $shopId, $categoryId, $storeId);
         return $categoryId;
     }
 }