Question

I am trying to get a level 2 category list. I got all level 2 categories but I am also getting 2 unknown categories which are not in backend. This is weird. Here is my code

public function getShopCategories()
{
    $objectManagerr = \Magento\Framework\App\ObjectManager::getInstance();
    $categoryFactory = $objectManagerr->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');

    $categories = $categoryFactory->create()
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('is_active', 1) //only active categories
                    ->addAttributeToFilter('include_in_menu', 1)
                    ->addAttributeToFilter('level', array('eq'=>2));

    return $categories;
}

I reindexed and checked for different store views but not getting these categories.

Était-ce utile?

La solution

Check unknown category is present in the database? You can use below query to getcategories.

SELECT e.*, IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS name FROM catalog_category_entity AS e INNER JOIN catalog_category_entity_varchar AS at_name_default ON (at_name_default.entity_id = e.entity_id) AND (at_name_default.attribute_id = '41') LEFT JOIN catalog_category_entity_varchar AS at_name ON (at_name.entity_id = e.entity_id) AND (at_name.attribute_id = '41')

I hope it helps!

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top