I am trying to delete multiple store views using a php script that includes app/Mage.php in the root of my installation.

I am able to get the list of websites and store views but I need to somehow parse them into the delete() method as an array the loop over each store_id in order to delete the ones I no longer need.

Also, I need to find a way to filter the store_id so that I don't remove the default store view or admin.

Here is what I have so far:

/** Load Magento **/
require_once 'app/Mage.php';

/** Load webstes and stores */
echo "Website ID: " . Mage::app()->getWebsite()->getId() . "<br/>";
echo "Website Name: " . Mage::app()->getWebsite()->getName() . "<br/>";
echo "Store ID: " . Mage::app()->getStore()->getId() . "<br/>";
echo "Store Name: ".Mage::app()->getStore()->getName(). "<br/>";
echo "Store code: ". Mage::app()->getStore()->getCode()."<br/>";

/** @var ** $website loop */
foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            echo $store->getId() ." ".$store->getName()."<br/>";
/** ** End of script */

I'm haven't been able to find a way to call the delete() method foreach store_id using:

$model = Mage::getModel('core/store')->load($stores);

Can anyone help?


use storeId instead of $stores


$model = Mage::getModel('core/store')->load($store->getId());

load function will load current store in for loop with $store->getId()

this is just pseudocode use should have to follow just checkout with detail code in mage library

hope this will work for you.

| improve this answer | |

If you get following error Cannot complete this operation from non-admin area which will prevent deletion of stores. Add below code in script.

Mage::register('isSecureArea', true);


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.