Timeline for magento 2 category delete function programmatically
Current License: CC BY-SA 4.0
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 11, 2021 at 0:55 | comment | added | Shahzad Ahmed | My client added random categories as parent they were around 200+. I created this snippet to delete them. You may find it helpful. <?php $OM = \Magento\Framework\App\ObjectManager::getInstance(); $categoryCollection = $OM->get('\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');?> <?php $registry = $OM->get('Magento\Framework\Registry'); $registry->register("isSecureArea", true); $cats = $categoryCollection->create(); $cats = $categories->addAttributeToSelect('*'); foreach ($cats as $cat) { if ($cat->getId() > 3) { $cat->delete(); } } ?> | |
Dec 2, 2019 at 7:51 | comment | added | Munesh Jalwani | ok, i will let you know! | |
Dec 2, 2019 at 7:47 | comment | added | Manu | i am patiently waiting for this | |
Dec 2, 2019 at 7:46 | comment | added | Manu | Sir my question is i have two category Men and Kids.Men have another sub category watch and kids have another sub category toys.how to update watch to kids category | |
Dec 2, 2019 at 7:45 | comment | added | Munesh Jalwani | Yes sure u have to just post a new question for it, i will answer the question there, not here! | |
Dec 2, 2019 at 7:42 | comment | added | Manu | Ok sir i am waiting for you | |
Dec 2, 2019 at 7:41 | comment | added | Munesh Jalwani | you have to post a question for it, i will surely helps you! | |
Dec 2, 2019 at 7:37 | comment | added | Manu | eg: i have two category Men and Kids.Men have another sub category watch and kids have another sub category toys.how to update watch to kids category.can you help me | |
Dec 2, 2019 at 7:35 | comment | added | Manu | sir one more question.how to update my sub category to another category. | |
Dec 2, 2019 at 7:34 | comment | added | Manu | Thank you very much | |
Dec 2, 2019 at 7:33 | vote | accept | Manu | ||
Dec 2, 2019 at 7:23 | comment | added | Munesh Jalwani | i have updated above code for specific category, like id of the categoty is 2, that we want to delete! | |
Dec 2, 2019 at 7:22 | history | edited | Munesh Jalwani | CC BY-SA 4.0 |
looks good
|
Dec 2, 2019 at 7:14 | comment | added | Manu | sir i want to delete 001 category and sub category can you rearrange this code | |
Dec 2, 2019 at 7:07 | comment | added | Munesh Jalwani | yes, you have to select specific category for delete like above we select all category u have to select specific category for this, maybe it is subcategory or main category! approve, if it will help you! Thanks:) | |
Dec 2, 2019 at 7:05 | comment | added | Manu | sir now i have two category men and watch men is a main category and watch is sub category.men delete time automatically delete watch is it possible | |
Dec 2, 2019 at 7:03 | history | answered | Munesh Jalwani | CC BY-SA 4.0 |