Skip to content

Commit

Permalink
Merge pull request #834 from Nosto/feature/add-full-category-ids-brea…
Browse files Browse the repository at this point in the history
…dcrumb

Add full category ids breadcrumb to path
  • Loading branch information
supercid authored Mar 6, 2024
2 parents b57fe55 + 01a0bc0 commit e269128
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Model/Category/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public function build(Category $category, Store $store)
$nostoCategory->setId($category->getId());
$nostoCategory->setParentId($category->getParentId());
$nostoCategory->setTitle($this->getCategoryNameById($category->getId(), $store->getId()));
$path = $this->nostoCategoryService->getCategory($category, $store);
$nostoCategory->setPath($path ?? '');
$nostoCategory->setCategoryString($path ?? '');
$pathString = $this->nostoCategoryService->getCategory($category, $store);
$nostoCategory->setPath($category->getPath() ?? '');
$nostoCategory->setCategoryString($pathString ?? '');
$nostoCategory->setUrl($category->getUrl());
$nostoCategory->setAvailable($category->getIsActive() ?? false);
} catch (Exception $e) {
Expand Down
4 changes: 4 additions & 0 deletions Model/Product/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ public function build(
$nostoProduct->setAvailability($this->buildAvailability($product, $store));
$nostoProduct->setCategories($this->nostoCategoryService->getCategories($product, $store));
$nostoProduct->setCategoryIds($product->getCategoryIds());
$nostoProduct->setParentCategoryIds(
$this->nostoCategoryService->getCategoryParentIds($product, $store)
);

if ($this->nostoDataHelper->isInventoryTaggingEnabled($store)) {
$inventoryLevel = $this->stockService->getQuantity($product, $store);
$nostoProduct->setInventoryLevel($inventoryLevel);
Expand Down
8 changes: 8 additions & 0 deletions Model/Service/Product/Category/CachingCategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,12 @@ public function getCategories(Product $product, StoreInterface $store)
{
return $this->categoryService->getCategories($product, $store);
}

/**
* @inheritDoc
*/
public function getCategoryParentIds(Product $product, StoreInterface $store)
{
return $this->categoryService->getCategoryParentIds($product, $store);
}
}
7 changes: 7 additions & 0 deletions Model/Service/Product/Category/CategoryServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ public function getCategory(Category $category, StoreInterface $store);
* @return array
*/
public function getCategories(Product $product, StoreInterface $store);

/**
* @param Product $product
* @param StoreInterface $store
* @return array
*/
public function getCategoryParentIds(Product $product, StoreInterface $store);
}
17 changes: 17 additions & 0 deletions Model/Service/Product/Category/DefaultCategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,21 @@ public function getCategory(Category $category, StoreInterface $store)

return $nostoCategory;
}

/**
* @param Product $product
* @param StoreInterface $store
* @return array
*/
public function getCategoryParentIds(Product $product, StoreInterface $store)
{
$parentCategoriesIds = [];
/** @phan-suppress-next-line PhanUndeclaredMethod */
foreach ($product->getCategoryCollection()->setStore($store->getId()) as $category) {
foreach ($category->getParentIds() as $parentId) {
$parentCategoriesIds[] = $parentId;
}
}
return array_values(array_unique($parentCategoriesIds)); // Sequential keys to avoid serialization issues
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"php": ">=7.4.0",
"magento/framework": ">=101.0.6|~104.0",
"ext-json": "*",
"nosto/php-sdk": "^7.1",
"nosto/php-sdk": "^7.3",
"laminas/laminas-uri": "*"
},
"repositories": [
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e269128

Please sign in to comment.