Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New category saved from the repository has an invalid path #39738

Open
1 of 5 tasks
thomas-kl1 opened this issue Mar 13, 2025 · 1 comment
Open
1 of 5 tasks

New category saved from the repository has an invalid path #39738

thomas-kl1 opened this issue Mar 13, 2025 · 1 comment
Labels
Reported on 2.4.7 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@thomas-kl1
Copy link
Member

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

$object->setPath($object->getPath() . '/');
is never reached.

$object->setPath($object->getPath() . '/');

So the following is called

if (substr((string)$object->getPath(), -1) == '/') {

        /**
         * 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”.
Copy link

m2-assistant bot commented Mar 13, 2025

Hi @thomas-kl1. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@engcom-Bravo engcom-Bravo added Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Reported on 2.4.7 Indicates original Magento version for the Issue report. labels Mar 14, 2025
@github-project-automation github-project-automation bot moved this to Ready for Confirmation in Issue Confirmation and Triage Board Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reported on 2.4.7 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Ready for Confirmation
Development

No branches or pull requests

2 participants