OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
866 stars 435 forks source link

Configuration > Default Page - should not list disabled CMS pages #382

Open tomekjordan opened 6 years ago

tomekjordan commented 6 years ago

Hi. even disabled CMS pages are listed to choose for home page. It should not list disabled CMS pages, and list current available per certain website/storeview or global scope Screenshot: http://prntscr.com/hceyjv

Thanks

colinmollenhour commented 6 years ago

If you remove them from the list and it was already configured then you can unintentionally change the configuration..

  1. Create CMS page.
  2. Select CMS page in config and save.
  3. Disable created CMS page.
  4. Reload config page and click save.

Correct behavior: configuration is not changed since user did not intentionally make any changes.

Behavior with your proposal: some other CMS page will be selected since the previously selected page will not be in the list and configuration can thus be changed completely unintentionally.

My proposal would be to list the pages but denote them somehow as disabled. E.g. use two groups, Active and Inactive and group the pages accordingly, or add an "(inactive)" suffix to the inactive pages. Or just leave it as-is.

tmotyl commented 6 years ago

I'm also in favor of marking disabled or unavailable pages visually.

sreichel commented 6 years ago

I think this should be changed - somehow. At the moment you can also select pages that are not assigned to specfic storeview ....

Another idea ....

config.xml

<cms_page_save_before>
    <observers>
        <prevent_disable_default_cms_page>
            <class>sr_debug/observer</class>
            <method>preventDiableDefaultCmsPage</method>
        </prevent_disable_default_cms_page>
    </observers>
</cms_page_save_before>
<cms_page_delete_before>
    <observers>
        <prevent_delete_default_cms_page>
            <class>sr_debug/observer</class>
            <method>preventDiableDefaultCmsPage</method>
        </prevent_delete_default_cms_page>
    </observers>
</cms_page_delete_before>

Oberver.php

public function preventDiableDefaultCmsPage(Varien_Event_Observer $observer)
{
    /* @var Mage_Cms_Model_Page $page */
    $page = $observer->getObject();

    if ($page->isObjectNew()) {
        return;
    }

    $isDeleteAction = $observer->getEvent()->getName() === 'cms_page_delete_before';

    if (!$page->getIsActive() || $isDeleteAction) {
        /* @ref #415 */
        $storeIds = $isDeleteAction ? $page->getStoreId() : $page->getStores();
        $storeIds[] = '0';
        $config = Mage::getModel('core/config_data')->getCollection()
            ->addFieldToFilter('value', $page->getIdentifier())
            ->addFieldToFilter('scope_id', array('in' => $storeIds))
            ->addFieldToFilter('path', array(
                Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE,
                Mage_Cms_Helper_Page::XML_PATH_NO_COOKIES_PAGE,
                Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE,
            ));

        if ($config->getSize()) {
            if (!$isDeleteAction) {
                $page->setIsActive(true);
                Mage::getSingleton('adminhtml/session')->addWarning('Cannot disable default CMS page.');
            } else {
                // prevent delete
                $page->setId(null);
                Mage::throwException(Mage::helper('core')->__('Cannot delete default CMS page.'));
            }
        }
    }
}

system.xml

<?xml version="1.0"?>

[module]/system_config_source_cms_page [module]/system_config_source_cms_page [module]/system_config_source_cms_page

system config source

class [Some_Module]_Model_System_Config_Source_Cms_Page
{
    protected $_options;

    public function toOptionArray()
    {
        if (!$this->_options) {
            $store = Mage::app()->getRequest()->getParam('store', 0);
            if ($store) {
                $store = Mage::getModel('core/store')->load($store, 'code');
            }

            $this->_options = Mage::getModel('cms/page')->getCollection()
                ->addStoreFilter($store)
                ->addFieldToFilter('is_active', true)
                ->load()->toOptionIdArray();
        }
        return $this->_options;
    }
}
ADDISON74 commented 1 year ago

I guess we have the same issue with static blocks. In Magento Sample Pack there is a static block called Couponing having as status Disabled. However, if you go to the Categories page and then to the "Display Setting" tab and display the "CMS Block" list, Couponing appears in the list.

Would it be good to have a disabled static block in the list?