Set “List / Grid” default view mode in catalog.xml for category view

前端 未结 3 2030
轻奢々
轻奢々 2021-01-05 20:24

I\'m trying to do my category view display products in list or grid mode as default.


        

        
3条回答
  •  失恋的感觉
    2021-01-05 21:01

    If you choose to use the method described by @rengaw83, you will not be able to switch between modes in that category anymore. For instance, if you click on "Grid", the mode will not change to grid mode.

    To be able to switch modes and just set the default view mode in a category via a custom layout, you need to override the core Toolbar block, and add the following method to it:

    /**
     * Sets the current View modes (grid, list, etc.)
     *
     * @param array $modes
     */
    public function setCurrentModes($modes)
    {
        $this->_availableMode = $modes;
        $modes = array_keys($this->_availableMode);
        $defaultMode = current($modes);
        $mode = $this->getRequest()->getParam($this->getModeVarName());
        if ($mode) {
            if ($mode == $defaultMode) {
                Mage::getSingleton('catalog/session')->unsDisplayMode();
            }
        } else {
            $mode = Mage::getSingleton('catalog/session')->getDisplayMode();
        }
    
        if (!$mode || !isset($this->_availableMode[$mode])) {
            $mode = $defaultMode;
        }
        $this->setData('_current_grid_mode', $mode);
    }
    

    Then you will be able to set modes in custom layout tab like that:

    
        
            
                List
                Grid
            
        
    
    

    for default list mode, or

    
        
            
                Grid
                List
            
        
    
    

    for default grid mode. Or you even can pass only one mode to set only grid or list mode available.

提交回复
热议问题