在 Magento 中删除网站无法删除商店和商店视图

Delete website in Magento can't delete store and store view

我有一个从 Mage_Adminhtml_System_StoreController 扩展而来的控制器,下面是我覆盖的操作:

public function deleteWebsitePostAction()
    {
        $multiWebEnable = Mage::getStoreConfig('web/multi_web_general/multi_web');
        $itemId = $this->getRequest()->getParam('item_id');

        if (!$model = Mage::getModel('core/website')->load($itemId)) {
            $this->_getSession()->addError(Mage::helper('core')->__('Unable to proceed. Please, try again'));
            $this->_redirect('*/*/');
            return;
        }
        if (!$model->isCanDelete()) {
            $this->_getSession()->addError(Mage::helper('core')->__('This website cannot be deleted.'));
            $this->_redirect('*/*/editWebsite', array('website_id' => $model->getId()));
            return;
        }

        $this->_backupDatabase('*/*/editWebsite', array('website_id' => $itemId));

        try {
            $model->delete();

            if ($multiWebEnable) {
                $websiteCode = $model->getCode();
                $websiteDir = BP . DS . 'mpshop' . DS . $websiteCode;
                if (is_dir($websiteDir)) {
                    $objects = scandir($websiteDir);
                    foreach ($objects as $object) {
                        if ($object != "." && $object != "..") {
                            if (filetype($websiteDir . DS . $object) == "dir") {
                                rmdir($websiteDir . DS . $object);
                            } else {
                                unlink($websiteDir . DS . $object);
                            }
                        }
                    }
                    reset($objects);
                    rmdir($websiteDir);
                }
            }

            $this->_getSession()->addSuccess(Mage::helper('core')->__('The website has been deleted.'));
            $this->_redirect('*/*/');
            return;
        } catch (Mage_Core_Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        } catch (Exception $e) {
            $this->_getSession()->addException($e, Mage::helper('core')->__('Unable to delete website. Please, try again later.'));
        }
        $this->_redirect('*/*/editWebsite', array('website_id' => $itemId));
    }

我试图在我的控制器中注释掉这个功能,但问题仍然存在。

我对此感到困惑。我需要知道为什么会发生这种情况,请给我一些建议...谢谢

任何帮助将不胜感激。

从管理> 系统> 缓存管理禁用缓存 刷新缓存并再次检查。 您还可以从缓存管理或 [root]/var/cache

中删除缓存

请注意,删除网站只能从管理面板完成,这就是独立脚本具有该功能的原因。

(放置在 root/var 文件夹中) 这将从独立文件中删除您的网站:

require_once( 'app/Mage.php' );

umask(0);
Mage::app( 'admin' );
function deleteWebsitePostAction()
{
    try 
    {
        $sWebsiteId = 'a';
        $oWebsite = Mage::getModel( 'core/website' )->load( $sWebsiteId );
        if( !empty( $oWebsite->getId() ) )
        {
            $oWebsite->delete();
        }
    } 
    catch( Exception $oException ) 
    {
        Mage::logException( $oException );
    }
}
deleteWebsitePostAction();

要在管理面板中实现这一点,请确保您向控制器提交了正确的变量,在本例中我选择了名称 website_id,因此您的表单应该有一个地方。

public function deleteWebsitePostAction()
{
    try 
    {
        $sWebsiteId = $this->getRequest()->getParam( 'website_id' );
        $sWebsiteId = 'a';
        $oWebsite = Mage::getModel( 'core/website' )->load( $sWebsiteId );
        if( !empty( $oWebsite->getId() ) )
        {
            $oWebsite->delete();
        }
        else
        {
            $this->_getSession()->addError( 'Unable to proceed. Please, try again' );
            $this->_redirect( '*/*/' );
            return;
        }
    } 
    catch( Exception $oException ) 
    {
        Mage::logException( $oException );
        $this->_getSession()->addError( 'Unable to delete website. Please, try again' );
    }
}

嗯,

经过深入研究,我发现 core_website table 和 core_store, core_store_group.

之间缺少一个外键

这里的解决方案是下载 Magento 数据库修复工具,可在 Magento 主页下载。

希望对您有所帮助。