public function sCategoryPath($category) { $parts = $this->repository->getPathById($category, 'name'); $level = $this->baseCategory->getLevel() + 1; $parts = array_slice($parts, $level); return $parts; }
/** * Returns the category path for the given category id * * @param int|$id * @param int|null $parentId * @return array */ public function sGetCategoryPath($id, $parentId = null) { if ($parentId === null) { $parentId = $this->baseId; } $path = $this->repository->getPathById($id, 'id'); foreach ($path as $key => $value) { unset($path[$key]); if ($value == $parentId) { break; } } return $path; }
/** * Does the actual import */ public function import() { $parentId = Shopware()->Models()->find('Shopware\\Models\\Shop\\Shop', $this->shopId)->getCategory()->getId(); // Trigger to indicate an error while creating new category $addError = false; foreach ($this->plentyCategoryBranch as $plentyCategory) { $plentyCategoryId = $plentyCategory['branchId']; $plentyCategoryName = $plentyCategory['name']; if ($this->categoryNodeLang != $this->shopLang) { $plentyLocalCategoryName = $this->getLocalCategoryName($plentyCategoryId); if ($plentyLocalCategoryName) { $plentyCategoryName = $plentyLocalCategoryName; } } // Root category id (out of the shop) $CategoryFound = self::$CategoryRepository->findOneBy(array('name' => $plentyCategoryName, 'parentId' => $parentId)); if ($CategoryFound instanceof Shopware\Models\Category\Category) { // PlentymarketsMappingEntityCategory::addCategory($CategoryFound->getId(), $this->shopId, $plentyCategoryId, $this->storeId); $parentId = $CategoryFound->getId(); } else { $params = array(); $params['name'] = $plentyCategoryName; $params['parentId'] = $parentId; try { // Create $CategoryModel = self::$CategoryApi->create($params); // Add mapping and save into the object PlentymarketsMappingEntityCategory::addCategory($CategoryModel->getId(), $this->shopId, $plentyCategoryId, $this->storeId); // Parent $parentCategoryName = $CategoryModel->getParent()->getName(); // Log PlentymarketsLogger::getInstance()->message('Sync:Item:Category', 'The category »' . $plentyCategoryName . '« has been created beneath the category »' . $parentCategoryName . '«'); // Id to connect with the item $parentId = $CategoryModel->getId(); } catch (Exception $E) { // Log PlentymarketsLogger::getInstance()->error('Sync:Item:Category', 'The category »' . $plentyCategoryName . '« with the parentId »' . $parentId . '« could not be created (' . $E->getMessage() . ')', 3300); // Set the trigger - the category will not be connected with the item $addError = true; } } } if ($addError) { return false; } else { return $parentId; } }