如何为一个域名的主要和移动商店视图创建不同的 Magento 类别

How to create different Magento categories for main and mobile store view on one domain name

我正在寻找针对主要和移动 Magento 商店视图使用不同类别的解决方案。我已将移动商店视图配置为带有用户代理字符串和异常的新主题。

我怎样才能在主要商店视图中显示一个类别,而在移动商店视图中显示另一个类别。两个商店视图由一个域名使用。

我建议它创建一个带有下拉列表的类别属性。以下脚本将帮助您这样做:

SQL 安装文件:

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("catalog_category", "wheretoshow",  array(
    "type"     => "int",
    "backend"  => "",
    "frontend" => "",
    "label"    => "Where to Show",
    "input"    => "select",
    "class"    => "",
    "source"   => "modulename/eav_entity_attribute_source_categoryoptions",
    "global"   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    "visible"  => true,
    "required" => false,
    "user_defined"  => false,
    "default" => "Main Website",
    "searchable" => false,
    "filterable" => false,
    "comparable" => false,

    "visible_on_front"  => false,
    "unique"     => false,
    "note"       => ""

    ));
$installer->endSetup();

Model/Categoryoptions.php

<?php
class class Packagename_Modulename_Model_Eav_Entity_Attribute_Source_Categoryoptions  extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    /**
     * Retrieve all options array
     *
     * @return array
     */
    public function getAllOptions()
    {
        if (is_null($this->_options)) {
            $this->_options = array(

                array(
                    "label" => Mage::helper("eav")->__("Mobile Website"),
                    "value" =>  1
                ),

                array(
                    "label" => Mage::helper("eav")->__("Main Website"),
                    "value" =>  2
                ),

            );
        }
        return $this->_options;
    }

    /**
     * Retrieve option array
     *
     * @return array
     */
    public function getOptionArray()
    {
        $_options = array();
        foreach ($this->getAllOptions() as $option) {
            $_options[$option["value"]] = $option["label"];
        }
        return $_options;
    }

    /**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions();
        foreach ($options as $option) {
            if ($option["value"] == $value) {
                return $option["label"];
            }
        }
        return false;
    }

    /**
     * Retrieve Column(s) for Flat
     *
     * @return array
     */
    public function getFlatColums()
    {
        $columns = array();
        $columns[$this->getAttribute()->getAttributeCode()] = array(
            "type"      => "tinyint(1)",
            "unsigned"  => false,
            "is_null"   => true,
            "default"   => null,
            "extra"     => null
        );

        return $columns;
    }

    /**
     * Retrieve Indexes(s) for Flat
     *
     * @return array
     */
    public function getFlatIndexes()
    {
        $indexes = array();

        $index = "IDX_" . strtoupper($this->getAttribute()->getAttributeCode());
        $indexes[$index] = array(
            "type"      => "index",
            "fields"    => array($this->getAttribute()->getAttributeCode())
        );

        return $indexes;
    }

    /**
     * Retrieve Select For Flat Attribute update
     *
     * @param int $store
     * @return Varien_Db_Select|null
     */
    public function getFlatUpdateSelect($store)
    {
        return Mage::getResourceModel("eav/entity_attribute")
            ->getFlatUpdateSelect($this->getAttribute(), $store);
    }
}

在前端获取类别时,根据您的网站按此属性过滤类别。