Skip to content

Commit

Permalink
#104362 add admin snowmenu/node/productName controller
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwaclawczyk committed Jul 8, 2024
1 parent 0e69b14 commit 4f5bf91
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Controller/Adminhtml/Node/ProductName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

namespace Snowdog\Menu\Controller\Adminhtml\Node;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Exception\InputException;

class ProductName extends Action implements HttpGetActionInterface
{
/**
* @inheritDoc
*/
const ADMIN_RESOURCE = 'Snowdog_Menu::menus';

/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
private $productRepository;

public function __construct(
Context $context,
ProductRepositoryInterface $productRepository
) {
parent::__construct($context);
$this->productRepository = $productRepository;
}

/**
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\InputException
*/
public function execute()
{
$storeId = (int) $this->_request->getParam('store_id', 0);
$productId = $this->_request->getParam('product_id');
if (empty($productId)) {
throw new InputException(__("Missing required product_id param"));
}
$product = $this->productRepository->getById($productId, false, $storeId);
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);

return $result->setData(['product_name' => $product->getName()]);
}
}

0 comments on commit 4f5bf91

Please sign in to comment.