Open
Description
Preconditions and environment
- Magento version : 2.4.7
Steps to reproduce
Simplified version:
<?php
declare(strict_types=1);
namespace Foo;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\ResourceModel\Category\Collection;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class Bar
{
public function __construct(
private CollectionFactory $collectionFactory,
private CategoryRepositoryInterface $categoryRepository
) {}
/**
* @throws LocalizedException
*/
public function apply(): void
{
/** @var Collection $collection */
$collection = $this->collectionFactory->create();
/** @var Category $category */
$category = $collection->getNewEmptyItem();
$category->setName($name);
$category->setIsActive(true);
$category->setParentId(Category::TREE_ROOT_ID);
// If we use the repository, the path is not correctly setup on
$this->categoryRepository->save($category);
// If we use the save method of the model, the path is correctly set
//$category->save();
}
}
Expected result
Path is like : 1/256
(where 256 is the freshly created category ID)
Actual result
Path is: 1
Additional information
It seems that
is never reached. $object->setPath($object->getPath() . '/');
So the following is called
/**
* Add identifier for new category
*/
if (substr((string)$object->getPath(), -1) == '/') {
$object->setPath($object->getPath() . $object->getId());
$this->_savePath($object);
}
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Needs Update