I have a category where is_active = 0, include_in_menu = 0 and url = test. But the category has Url Rewrite Rule and final url = test_new.
If I get category data from observer (event – after save category in admin panel) using Category Factory, I get incorrect url (url = test, but needs url = test_new).
If I get category data in other place, I get incorrect is_active and include_in_menu, but url – correct.
I use this code in both places:
use MagentoCatalogModelResourceModelCategoryCollectionFactory as CategoryCollectionFactory;
...
protected $categoryCollectionFactory;
public function __construct(
CategoryCollectionFactory $categoryCollectionFactory
) {
$this->categoryCollectionFactory = $categoryCollectionFactory;
}
public function test () {
$collection = $this->categoryCollectionFactory->create();
$collection
->addFieldToFilter('entity_id', ['eq' => $object->getEntityId()])
->addAttributeToSelect('*')
->addUrlRewriteToResult();
$items = [];
if (!empty($collection->getItems())) {
foreach ($collection->getItems() as $category) {
$items[] = $category;
}
}
}
How can I get correct all data and url with all Url Rewrites Rule for my category?