• Magento分类查看页显示同级分类

    catalog_category_default  当分类没有开启属性筛选,进入到底层分类的时候,左边就没有导航了

    很多情况下,尤其是子分类比较多时,需要在底层分类的左栏显示它的同级分类

    今天整理模板的时候,把以前的代码稍微整理了一下,比之前的解决方法要简洁一些,暂记备忘如下:

    修改 template/catalog/navigation/left.phtml 文件,参考如下代码

    …..

    <?php $_count = is_array($_categories)?count($_categories):$_categories->count();

    ///code added
    if(!$_count) {
    if($this->getCurrentCategory()->getParentCategory()->getId() != Mage::app()->getStore()->getRootCategoryId())
    $_categories = $this->getCurrentCategory()->getParentCategory()->getChildrenCategories();
    $_count = is_array($_categories)?count($_categories):$_categories->count();
    }

    ///code end
    ?>
    <?php if($_count): ?>……

     

    catalog_category_layered 显示模式 可以进行属性筛选,比较清晰,暂时就不对这个进行处理了

    待以后补充

  • (转)笑话一则

    一位吸尘器销售员敲响了街上第一户人家的门,一位老太打开了门。这位充满激情的销售员二话不说闯进了屋子,把一袋厨房的垃圾倒在地毯上,
    “老奶奶,如果我今天不能在十分钟内用这款吸尘器把这些垃圾清理掉,我就把它们都吃下去!”销售员兴奋的向老太解释。
    “那你需要辣酱或者番茄酱吗?它们在厨房的冰箱里。”老太询问道。
    “恩?什么意思?”销售员一脸困惑。
    “我家没电……”
    A “vacuum cleaner” salesman knocked on the door on the first house of
    the street. A tall lady opened the door.

    Before she could speak, the enthusiastic salesman barged into the living
    room and opened a big black plastic bag and poured all the cow droppings
    onto the carpet.

    “Madam, if I could not clean this up with the use of this new powerful
    vacuum cleaner in the next 10 minutes, I will EAT all this dung!”,
    exclaimed the eager salesman.

    “Do you need chilly sauce or ketchup with that?”, asked the lady.

    The bewildered salesman asked, “Why, madam??? ”

    “There’s no electricity in the house…”, said the lady.

     

    转自:酒精与尼古丁的博客

  • Magento数据表前缀问题笔记

    使用Magento旧版本数据库覆盖安装升级的过程中,往往新版不允许 数字或下划线开头的表前缀,如有异常则会出现以下提示

    The table prefix should contain only letters (a-z),numbers (0-9) or underscores (_), the first character should be a letter.

    出现问题但是我们又不能放弃就数据库中的数据资料,如何解决呢?

    这边贴出一个修改检测规则的方法

    修改文件

    app/code/core/Mage/Install/Model/Installer/Db.php

    修改默认
            //check table prefix
            if ($data['db_prefix'] != ”) {
                if ( !preg_match(‘/^[a-z]+[a-z0-9_]*$/’, $data['db_prefix'])) {
                    Mage::throwException(
                        Mage::helper(‘install’)->__(‘The table prefix should contain only letters (a-z), ‘
                            . ‘numbers (0-9) or underscores (_), the first character should be a letter.’));
                }
            }
    代码中检测规则为
      if ( !preg_match(‘/^[a-z0-9_]+[a-z0-9_]*$/’, $data['db_prefix'])) {
    使表前缀可以  以数字或下划线开头
    保存后,清理缓存等文件 重新安装即可。
    测试环境 Magento1.3.2.4  to  Magento1.6.1.0
  • Magento安装过程中数据表已存在解决笔记

    经常在使用旧版本的样本数据安装Magento的过程中会出现,数据表已存在的错误( Table ‘….’ already exists)

    这边以一个我在 从Magento1.3.2.4 向Magento1.6.1.0升级过程中遇到的一个类似问题来做个简单记录吧

    这边贴一段bug report
    ….Error in file: “/home/tester/public_html/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php” – SQLSTATE[42S01]: Base table or view already exists: 1050 Table ’1234_widget’ already exists”…..
    这边只截取了部分关键信息,提示表1234_widget 已存在(当然1234_ 为表前缀),但是由于原站表中可能已经有一些我们必要的数据,即使没有必须的数据,在删除表的时候可能还会引起其他的外键问题。这边暂时的折中解决方法就是再次修改检测规则。
    app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php
    查看编辑此文件,代码不长 就索性贴出来吧
    $installer = $this;
    $installer->startSetup();
    if ($installer->getTable(‘cms_widget’) ) {
    $installer->run(”
    ALTER TABLE `{$installer->getTable(‘cms_widget’)}` COMMENT ‘Preconfigured Widgets’;
    ALTER TABLE `{$installer->getTable(‘cms_widget’)}` RENAME TO `{$installer->getTable(‘widget/widget’)}`;
    “);
    }
    $installer->endSetup();
    这边具体的代码执行过程就不讲了,我也不是很清楚当中的细节
    单从if语句的判断条件来看 似乎并没有检测 widget 表是否存在 (至于表前缀当然是在执行安装数据库的时候添加的)
    于是乎修改限定条件,当表已经存在的时候就不用重新建立数据表了。(Magento版本间差异还是有一定的,但是单个数据表的结构不会有太大变化,所以这边也不用担心数据表由于版本问题导致其他异常了)
    修改判断,添加此判断条件  !($installer->getTable(‘widget/widget’))  完成后代码如下
    $installer = $this;
    $installer->startSetup();
    if ($installer->getTable(‘cms_widget’) && !($installer->getTable(‘widget/widget’))) {
    $installer->run(”
    ALTER TABLE `{$installer->getTable(‘cms_widget’)}` COMMENT ‘Preconfigured Widgets’;
    ALTER TABLE `{$installer->getTable(‘cms_widget’)}` RENAME TO `{$installer->getTable(‘widget/widget’)}`;
    “);
    }
    $installer->endSetup();
    保存后清除 cache  session  及local.xml 等废弃文件
    重新安装
    安装成功

    (当然这边的只是我遇到的一个提示异常的数据表,不过相信如果其他表也出现类似的异常,也可以用类似的方法来解决问题)

    记此以作备忘 :-)

  • 获取对象所包含的类方法及相关数据

    在Magento开发模板的时候,我们经常需要从产品或其他对象中取得一些可用方法

    当然基本的 print_r(get_class_method(get_class($temp_object)));  已经基本够用了,但是输出的格式 等等还是看起来有点让人头疼,这边稍微格式化了一下。

    多的不说了直接上代码:

    function objInfo($temp_obj){ //show object class methods data information
    $temp_class = get_class($temp_obj);
    if(!$temp_class) {
    echo “\$$temp_obj  is not an object ~!<br>”;
    print_r($temp_obj);
    echo “<hr>”;
    return 0;
    }
    $details = ”;
    $temp_methods = get_class_methods($temp_class);
    $details .= (‘The Object of Class: ‘.$temp_class.’ –totaly has ‘.count($temp_methods).’ Methods<hr>’);
    $temp_vars = get_class_vars($temp_class);
    foreach($temp_methods as $temp_method){
    $details .= (“\$object->”.$temp_method.”()<br>”);
    }
    $details .= ‘<hr>’;
    if(in_array(‘debug’,$temp_methods)) {
    $details .= ‘<h2>debug() method returns</h2><hr>’;
    $temp_data = $temp_obj->debug();
    foreach($temp_data as $_var => $_value){
    if(!is_array($_value))  $details .= ($_var.’ === ‘.$_value.”<hr>”);
    else {
    $details .= $_var .” === array (“;
    foreach($_value as $t_var => $t_value)
    $details .=  (‘ ['.$t_var.' = '.$t_value.'] ‘);
    $details .= ‘)’;
    }
    }
    }
    if(in_array(‘getData’,$temp_methods)) {
    $details .= ‘<h2>getData() method returns</h2><hr>’;
    $temp_data = $temp_obj->getData();
    foreach($temp_data as $_var => $_value){
    $details .= ($_var.’ === ‘.$_value.”<hr>”);
    }
    }
    print_r($details);
    return 1;
    }//objInfo end;
    objInfo($_product); //输出$_product 的相关信息

    开始是考虑用反射API来取得一些更详细的信息,发现有点太画蛇添足了。。。

    就简单点做个备忘吧…

click
©2010-2024 Jeen All Rights Reserved.Powered by emlog 京ICP备15058100号-1