How to Move Category Position Programmatically in Magento 2
<?php
use Magento\Framework\AppInterface;
try
{
require_once __DIR__ . '/app/bootstrap.php';
}
catch (\Exception $e)
{
echo 'Autoload error: ' . $e->getMessage();
exit(1);
}
try
{
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$appState = $objectManager->get('\Magento\Framework\App\State');
$appState->setAreaCode('frontend');
$category = $objectManager->get('\Magento\Catalog\Api\CategoryManagementInterface');
$categoryId = 5; //id of The category to be moved
$parentId = 6; //id of parent category where the new category to move
$afterId = 7; //id of category after which you want to move
$CategoryMoveSuccess = $category->move($categoryId, $parentId, $afterId);
if($CategoryMoveSuccess)
{
echo "Successfully Move Category Position";
}
else
{
echo "Not Move Category Position";
}
}
catch(\Exception $e)
{
echo "Error : ".$e->getMessage();
}
?>
Comments
Post a Comment