【问题标题】:How to create different Magento categories for main and mobile store view on one domain name如何在一个域名上为主要和移动商店视图创建不同的 Magento 类别
【发布时间】:2015-01-27 07:20:20
【问题描述】:

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

如何在主商店视图上显示一个类别,在移动商店视图上显示另一个类别。两个商店视图都由一个域名使用。

【问题讨论】:

    标签: magento


    【解决方案1】:

    我建议它使用下拉菜单创建一个类别属性。以下脚本将帮助您这样做:

    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();
    

    型号/类别选项.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);
        }
    }
    

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

    【讨论】:

      猜你喜欢
      • 2016-09-27
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 2015-07-04
      • 1970-01-01
      相关资源
      最近更新 更多