skip to Main Content

I have category ID and need to get all custom attribute for example thumbnail image.

my code does not return all attributes

$category = $this->categoryRepository->get($childId, $this->_storeManager->getStore()->getId());
$category->getData();

2

Answers


  1. Try below code:

    $categoryId = 5;
    $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $object_manager = $_objectManager->create('MagentoCatalogModelCategory')->load($categoryId);
    echo "<pre>";
    print_r($object_manager->getData());
    die('shasha test');
    

    I hope it will help…!!!

    Login or Signup to reply.
  2. You can use Category’s CollectionFactory class and select all attributes by using a star (*) symbol in addAttributeToSelect method. You can use this code example below in your class.

    protected $_categoryFactory;
    
    public function __construct(
        // ...
        MagentoCatalogModelResourceModelCategoryCollectionFactory $collecionFactory,
        ) {
            // ...
            $this->_categoryFactory = $collecionFactory;
    }
    
    public function yourFunctionName()
    {
        $catId = 3; // your category id        
        $collection = $this->_categoryFactory
                        ->create()
                        ->addAttributeToSelect('*')
                        ->addAttributeToFilter('entity_id',['eq'=>$catId])
                        ->setPageSize(1);
    
        $catObj = $collection->getFirstItem();
        $thumbnail = $catObj->getThumbnail(); // it should return value if attribute name is thumbnail
        $catData = $catObj->getData(); // dump this line to check all data
    
        // ...
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search