-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#104362 add admin snowmenu/node/productName controller
- Loading branch information
1 parent
0e69b14
commit 4f5bf91
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()]); | ||
} | ||
} |