I want to delete all custom attribute sets, I'm facing an issue when I'm deleting attribute set manually then 404 error is showing in Magento 2.3
and can i delete all categories with 1 database query and start it from id 1 ?
Sumit
5,0482 gold badges22 silver badges36 bronze badges
asked Sep 12, 2019 at 12:40
Wajahat Bashir
4121 gold badge5 silver badges25 bronze badges
1 Answer 1
You can use execute below script on your website to remove the attribute sets programmatically.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
//require __DIR__ . '/../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
$attributeSetIds = [1,2,3,4]; //add attribute set ids here to delete
$attributeSetRepository = $objectManager->create('\Magento\Catalog\Api\AttributeSetRepositoryInterface');
foreach ($attributeSetIds as $attributeSetId) {
$attributeSetRepository->deleteById($attributeSetId);
}
And you can use below SQL query to remove categories from ID 1 on your website.
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE catalog_category_entity;
TRUNCATE TABLE catalog_category_entity_datetime;
TRUNCATE TABLE catalog_category_entity_decimal;
TRUNCATE TABLE catalog_category_entity_int;
TRUNCATE TABLE catalog_category_entity_text;
TRUNCATE TABLE catalog_category_entity_varchar;
TRUNCATE TABLE catalog_category_product;
TRUNCATE TABLE catalog_category_product_index;
INSERT INTO `catalog_category_entity` (`entity_id`, `attribute_set_id`, `parent_id`, `created_at`, `updated_at`, `path`, `position`, `level`, `children_count`) VALUES ('1', '0', '0', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '1', '0', '0', '1'),
('2', '3', '1', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '1/2', '1', '1', '0');
INSERT INTO `catalog_category_entity_int` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
('1', '69', '0', '1', '1'),
('2', '46', '0', '2', '1'),
('3', '69', '0', '2', '1');
INSERT INTO `catalog_category_entity_varchar` (`value_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES
('1', '45', '0', '1', 'Root Catalog'),
('2', '45', '0', '2', 'Default Category');
SET FOREIGN_KEY_CHECKS = 1;
DELETE FROM url_rewrite WHERE entity_type = 'category';
Hope it helps!!!
answered Sep 12, 2019 at 12:48
Sumit
5,0482 gold badges22 silver badges36 bronze badges
-
both solutions are not working.Wajahat Bashir– Wajahat Bashir2019年09月12日 13:37:08 +00:00Commented Sep 12, 2019 at 13:37
-
-
Yes, after running of both categories queries in database, now in admin when i click on category then website is going out site cannot reached. and also attribute i'm getting Fatal error: Uncaught ReflectionException: Class MagentoFrameworkAppState does not exist inWajahat Bashir– Wajahat Bashir2019年09月12日 13:40:58 +00:00Commented Sep 12, 2019 at 13:40
-
1updated my code for the script, please check.Sumit– Sumit2019年09月12日 13:49:59 +00:00Commented Sep 12, 2019 at 13:49
-
1Yes, i update your code little bit about directory of bootstrap file. and now it's working fine. ThanksWajahat Bashir– Wajahat Bashir2019年09月12日 13:57:37 +00:00Commented Sep 12, 2019 at 13:57
default