Вопрос

I have made a custom button on category edit page in admin. The button redirects to custom admin controller. I need to fetch the current category id in the controller.

Это было полезно?

Решение

You can get this by following code

$this->getRequest()->getParams();

Другие советы

You can get by using Magento\Framework\Registry in the constructor of your block file.

class Testblock extends \Magento\Framework\View\Element\Template
{
    protected $_registry;

    public function __construct(\Magento\Framework\Registry $registry) 
    {
        $this->_registry = $registry;
    }

    public function getCurrentCategory()
    {        
        return $this->_registry->('current_category');
    }
}

Then you can get current category ID as below:

$this->getCurrentCategory->getId();

You have to pass the category id to the button .

Let assume that you have added the button using block class files like the https://magento.stackexchange.com/a/260643/4564

$categoryId = (int)$category->getId();

add

onclick="window.location.href='<?php $this->getUrl('frontentId/Controllername/ActioName',['category_id'=> $categoryId])?>';"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top