有关magento的一些备忘录

一、Dreamweaver中打开phtml代码颜色提示

magento的 .phtml文件就是php文件,使Dreamweaver打开.phtm时使用php的设置,

在Dreamweaver的安装文件夹中寻找配置文件mmdocumenttypes.xml

找到

<documenttype id=”PHP_MySQL” servermodel=”PHP MySQL” internaltype=”Dynamic” winfileextension=”php,php3,php4,php5,phtml ” macfileextension=”php,php3,php4,php5,phtml ” file=”Default.php” writebyteordermark=”false”>

红色部分为你要添加的内容,大家可以举一反三。

 

ps  转载:hellokeykey.com 右兜钥匙

 

二、magento中调用静态区块


1、在.phtml中调用静态Block  

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_id')->toHtml() ?>

其中block_id为静态Block的id

2、CMS文章页调用静态Block

{{block type=”cms/block”   block_id=”toplinkmenu” }}只要更改block_id即可,block_id是静态Block的ID。

3、在XML文件中添加Block,如要在某个页面的左边添加静态块

<reference name="left">
      <block type="cms/block" name="left.permanent.callout">
          <action method="setBlockId"><block_id>block_id</block_id></action>
      </block>
</reference>

在你要显示的那个页面对应的模块 对应的layout handle中做上面修改,就可以放到左边栏位上去。

三、magento中添加js和css

magento个别页面添加css和js文件,可以将其放在个别页面的xml中,或者放在CMS的layout update中,其代码和文件存放位置如下

 

<reference name="head">

<action method="addCss"><stylesheet>css/mystyles.css</stylesheet></action>

//添加css mystyles.css 文件在 /skin/frontend/主题包文件夹/主题文件夹/css

<action method="addItem"><type>skin_js</type><name>js/myjs.js</name></action>

//添加js  myjs.js 文件在 /skin/frontend/主题包文件夹/主题文件夹/js

<action method="removeItem"><type>js</type><name>prototype/prototype.js</name></action>

//删除js 此prototype.js文件在magento根目录的 js文件夹

</reference>

 

另外 你也可以在phtml页面通过magento自带的帮助函数来引用JS:

<?php echo $this->helper('core/js')->includeScript('varien/accordion.js') ?>




该方法主要用来在某些特定页面包含额外的js文件。而这些文件在其他页面中却不常使用。再方便点,下面的方法很眼熟吧

<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/opcheckout.js') ?>"></script>

四、给magento的左侧栏加上所有商品分类

如何在Magento页面左边增加分类菜单!

第一步:编辑layout/catalog.xml

在<default>标签下,加入如下代码

  • <reference name=”left”>
  •   <block type=”catalog/navigation” name=”catalog.vertnav” template=”catalog/navigation/vert_nav.phtml” />
  • </reference>

第二步:. 在 template/catalog/navigation/目录下创建一个名为vert_nav.phtml 的文件,代码如下:

  • <div>
  •   <div id=”vertical-nav”>
  •    <div>
  •      <h4><?php echo $this->__(‘Categories’) ?></h4>
  •    </div>
  •    <ul id=”nav_vert”>
  •      <?php foreach ($this->getStoreCategories() as $_categoryNode): ?>
  •      <?php $open = $this->isCategoryActive($_categoryNode); ?>
  •      <?php $hasChildren = $_categoryNode->hasChildren(); ?>
  •       <li>
  •         <a href=”<?php echo $this->getCategoryUrl($_categoryNode); ?>”<?php if($open) { echo ”; } ?><?php if($hasChildren) { echo ”; } ?> >
  •          <?php if($hasChildren&&$open) { echo ‘- ‘; } elseif($hasChildren) { echo ‘+ ‘; }else{ echo ‘ ‘; }?><?php echo $_categoryNode->getName();?>
  •         </a>
  •         <?php if ($open && $hasChildren): ?>
  •         <ul>
  •          <?php foreach ($_categoryNode->getChildren() as $sonCategoryNode): ?>
  •          <?php $subCat = Mage::getModel(‘catalog/category’)->load($sonCategoryNode); ?>
  •          <?php $open = $this->isCategoryActive($subCat); ?>
  •          <?php $hasChildren = $subCat->hasChildren(); ?>
  •          <li>
  •            <a href=”<?php echo $this->getCategoryUrl($subCat); ?>”<?php if($open) { echo ”; } ?><?php if($hasChildren) { echo ”; } ?><?php if(!$hasChildren&&$open) { echo ”; } ?> >
  •             <?php if($hasChildren&&$open) { echo ‘- ‘; } elseif($hasChildren) { echo ‘+ ‘; }?><?php echo $subCat->getName(); ?>
  •            </a>
  •            <?php if ($open && $hasChildren): ?>
  •             <ul>
  •               <?php foreach ($sonCategoryNode->getChildren() as $grandsonCategoryNode): ?>
  •                <?php $subsubCat = Mage::getModel(‘catalog/category’)->load($grandsonCategoryNode); ?>
  •                <?php $open = $this->isCategoryActive($subsubCat) ?>
  •                <?php $hasChildren = $grandsonCategoryNode->hasChildren(); ?>
  •                <li>
  •                  <a href=”<?php echo $this->getCategoryUrl($subsubCat); ?>” <?php if($open) { echo ”; } ?>>
  •                   <?php if($hasChildren) { echo ‘+ ‘; }?><?php echo $subsubCat->getName(); ?>
  •                  </a>
  •                </li>
  •               <?php endforeach; ?>
  •             </ul>
  •            <?php endif; ?>
  •          </li>
  •          <?php endforeach; ?>
  •         </ul>
  •         <?php endif; ?>
  •       </li>
  •      <?php endforeach ?>
  •    </ul>
  •   </div>
  • </div>

注意上面的代码$this->getStoreCategories()得到的不是Mage_Catalog_Model_Category类的实例,而是Varien_Data_Tree_Node类的实例

第三步:. 在添加到 skin/[yourinterface]/[yourtheme]/css/menu.css 文件里增加下面的代码

  • #vertical-nav ul {
  •   list-style-type: none; /* get rid of the bullets */
  •   padding:0; /* no padding */
  •   margin:0; /* no margin for IE either */
  • }
  • #vertical-nav ul li {
  •   margin: 0;
  •   padding: 0;
  •   display:block;
  •   margin-top: 1px; /* lines */
  • }
  • #vertical-nav ul ul li a,#vertical-nav ul li{
  •   background-color: #FFFFFF;
  • }
  • #vertical-nav ul li a {
  •   display: block;
  •   padding: 3px 3px 3px 23px;
  •   margin:0;
  •   text-decoration: none;
  •   height:15px; /* hint for IE, alternatively remove whitespace from HTML */
  •   background-color: #CCCCCC;
  • }
  • #vertical-nav ul li .open, #vertical-nav .activesubsub, #vertical-nav .subopen {
  •   font-weight: bolder;
  •   text-decoration: underline;
  •   color:#000000
  • }
  • #vertical-nav .final{
  •   background-color:#ECECEC;
  • }
  • #vertical-nav ul ul li a {
  •   margin-left: 20px;
  • }
  • #vertical-nav ul ul ul li a {
  •   margin-left: 40px; /* indent level 2 */
  • }
  • #vertical-nav a {
  •   color:#999999;
  • }
  • #vertical-nav a:hover {
  •   color:#666666;
  • }
  • #vertical-nav ul li ul li a {
  •   border-top-width: thin;
  •   border-bottom-width: thin;
  •   border-top-style: dotted;
  •   border-bottom-style: dotted;
  •   border-top-color: #CCCCCC;
  •   border-bottom-color: #CCCCCC;
  •   margin-bottom:0px;
  •   margin-top:0px;
  • }
  • #vertical-nav ul li ul li {
  •   margin-bottom:0px;
  •   margin-top:0px;

}

五、magento首页显示某类商品

 

  1. 首先现在magento 后台创建一个新的分类,记下这个分类的 ID 号码。
  2. 在cms–>manage page–>home 适当位置添加如下代码(例如代码的最后)

{{block type="catalog/product_list" category_id ="43 " template="catalog/product/list.phtml "}}

代码解释如下:

我们在magento 后台新建一个分类,向这个分类中添加的产品会在首页显示。在 magneto成功添加一个分类后,会给这个分类分配一个ID。红色部分“category_id” 的 值“43”既是此分类ID。“ list.phtml”既是此产品列表的模板样式文件。

 

 

六、将注册也和登录页放在一起

为了简单的讲解步骤,本文修改了magento的核心代码,这当然是不好的,但是今天的重点是将如何实现的。大家有空了,可以自己使用模块重写自己 再去重写下这几个文件就行了。关于模板的美观修饰,大家自己弄吧,毕竟每个模板都不一样,还是有大量的css工作需要你们自己完成的。

进入正题,本文使用magento1.4版本,使用default模板,大家使用其它的版本注意文件路径的细微变化。

magento的登陆页面的模板文件路径是:app/design/frontend/base/default/template/customer/form/login.phtml

magento注册页面的模板文件路径是:app/design/frontend/base/default/template/customer/form/register.phtml

magento登陆页的block文件路径是:app/code/core/Mage/Customer/Block/Form/Login.php

magento注册页的block文件路径是:app/code/core/Mage/Customer/Block/Form/Register.php

这些文件是要涉及到的,步骤如下

 

1.我们直接将 register.phtml 文件中的代码贴到 login.phtml 中(先都贴到login.phtml文件的最后吧,布局以后再弄),这样在内容上他们就是在一个页面了。

 

 

2.我们有选择的将Register.php中的函数贴到Login.php中,Login.php的内容就如下了。
class Mage_Customer_Block_Form_Login extends Mage_Core_Block_Template
{
    private $_username = -1;

    protected function _prepareLayout()
    {
        $this->getLayout()->getBlock('head')->setTitle(Mage::helper('customer')->__('Customer Login'));
        return parent::_prepareLayout();
    }

    /**
     * Retrieve form posting url
     *
     * @return string
     */
    public function getPostActionUrl()
    {
        return $this->helper('customer')->getLoginPostUrl();
    }

    /**
     * Retrieve create new account url
     *
     * @return string
     */
    public function getCreateAccountUrl()
    {
        $url = $this->getData('create_account_url');
        if (is_null($url)) {
            $url = $this->helper('customer')->getRegisterUrl();
        }
        return $url;
    }

    /**
     * Retrieve password forgotten url
     *
     * @return string
     */
    public function getForgotPasswordUrl()
    {
        return $this->helper('customer')->getForgotPasswordUrl();
    }

    /**
     * Retrieve username for form field
     *
     * @return string
     */
    public function getUsername()
    {
        if (-1 === $this->_username) {
            $this->_username = Mage::getSingleton('customer/session')->getUsername(true);
        }
        return $this->_username;
    }
   
    /*from register.php*/
   
     public function getregisterPostActionUrl()
    {
        return $this->helper('customer')->getRegisterPostUrl();
    }
   
    public function getFormData()
    {
        $data = $this->getData('form_data');
        if (is_null($data)) {
            $data = new Varien_Object(Mage::getSingleton('customer/session')->getCustomerFormData(true));
            $this->setData('form_data', $data);
        }
        return $data;
    }

    /**
     * Retrieve customer country identifier
     *
     * @return int
     */
    public function getCountryId()
    {
        if ($countryId = $this->getFormData()->getCountryId()) {
            return $countryId;
        }
        return parent::getCountryId();
    }

    /**
     * Retrieve customer region identifier
     *
     * @return int
     */
    public function getRegion()
    {
        if ($region = $this->getFormData()->getRegion()) {
            return $region;
        }
        elseif ($region = $this->getFormData()->getRegionId()) {
            return $region;
        }
        return null;
    }

    /**
     *  Newsletter module availability
     *
     *  @return      boolean
     */
    public function isNewsletterEnabled()
    {
        return !Mage::getStoreConfigFlag('advanced/modules_disable_output/Mage_Newsletter');
    }

}

3.我们可以注意到,我将register.phtml与register.php中的getPostActionUrl()函数的名字改成了getregisterPostActionUrl(),这个就是重点。

4.然后大家改改login.phtml,该删的删,该修改css的修改css,最后弄的美观些,就大功告成了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值