Magento CMS页面添加Contact Us表单 /常用知识

  • 登录管理后台
  • CMS -> Pages
  • 新建或选择需要添加联系表单的CMS页面
  • 赋值如下代码到编辑器中(注意,此时需要将编辑器的WYSIWYG功能关闭)

{{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}
 
到此,在CMS页面中添加表单的步骤完成~~很简单吧~~


Magento模板及布局文件中引用静态块Static Block的方

Static Block是Magento提供的非常实用的一种Block类型。通过Static Block,可以让不懂代码的店铺管理员轻易修改网站中的一些动态内容,而不需要修改Magento的核心代码。Magento Static Block的创建相当简单,通过后台CMS->Static Block即可查看或新建Static Block。建立完毕之后,可以在任意的Magento页面添加该段代码。

本文从创建Static Block开始讲起,然后包括在布局文件,模板文件及CMS页面中添加创建的Static Block。最后,通过这些知识,运用到实际的Magento模版开发当中,我们讲述如何在Magento的首页添加一个幻灯片。

创建Static Block

在后台菜单cms–>static block位置,新建立一个static block,如下图,并根据如下提示,了解每个域的大致作用。

Block Title:随便填写,方便识别位置与作用
Identifier:全局唯一,用于在模板或布局文件中调用
Store View:可见、可调用范围
Content:这里只需要填写HTML代码即可,没有太特殊的东西。值得注意的是这里引用图片,添加链接的方式。
添加图片方式,

<img src=”{{media url=”home_banner.jpg”}}” alt=”" width=”950″ height=”280″ />

添加链接方式,

<a href=”{{store url=’customer/account/login/’}}”>Login</a>

在布局文件中添加Static Block

Static Block在CMS菜单下,其统一的Block类型是type=”cms/block”,在布局文件中看到的此类Block一律是在CMS下的Static Block中定义的。Static Block在布局文件中的添加方式如下。

<block type="cms/block" name="block_name">
    <action method="setBlockId">
        <id>block_id</id>
    <action>
</block>

标签内的值即在创建Static Block时填写的Identifier。另外这里定义了block的name属性,用于在模板文件中通过getChildHtml()方法引用该Static Block。

在模板文件中调用Static Block

在模板文件中调用Static Block有两种方法。
a)第一种是通过getChildHtml()方法调用,使用该方法的前提是在布局文件中,需要调用的Static Block已经在某一个Block内形成了父子关系,然后可以在父Block中使用getChildHtml()方法。

echo $this->getChildHtml('block_name')

b)第二种方法是在模板文件中使用createBlock()创建一个Block,然后再将Static Block赋予新创建的Block,然后toHtml()输出。使用该种方法不需要在布局文件中提前引用该Static Block。

echo $this->getLayout()->createBlock('cms/block')->setBlockId('foot_links')->toHtml()

在CMS页面添加Static Block

在CMS页面中添加Static Block同样非常简单,上面提到过所有的Static Block都属于cms/block类型,name属性可以随便取,建议保持一定的相关性,并且全局唯一,block_id属性即建立Static Block时填写的identifier。

{{block type=”cms/block” name=”cms_test_block” block_id=”order_form”}}


magento判断当前页是否首页

修改/app/code/core/Mage/相对应的php代码

1
2
3
4
public function getIsHomePage()
{
     return $this ->getUrl( '' ) == $this ->getUrl( '*/*/*' , array ( '_current' =>true, '_use_rewrite' =>true));
}

修改模板文件

1
2
3
4
<? php if ($this->getIsHomePage()):?>
          <? php echo $this->getChildHtml('breadcrumbs') ?>              //是首页执行此命令
<? php else:?>
<? php endif?>
 

magento最近浏览记录 Recently Viewed Product更改为图片显示

<?php if ( $_products = $this ->getRecentlyViewedProducts()): ?>
<div class = "category-products home-page-listing" >
<div class = "home-category-title" >
<h1>Recently Viewed Products</h1>
</div>
         <div id= "mygallery" class = "stepcarousel" >
         <div class = "belt products-grid" >       
 
         <?php $j =100;  foreach ( $_products as $_product ): $j ++;?>
 
             <div class = "panel" >
                                 <div class = "product-topbg" >
                                 <div class = "product-bottombg" >
                                 <div class = "product-midbg" >
                                          <div class = "overlay" id= "overlay-<?php echo $j;?>" >
                                                 <a href= "<?php echo $_product->getProductUrl() ?>" title= "<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class = "product-image" ><img src= "<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(160,180); ?>" width= "160" height= "180" alt= "<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>                               
                                         </div>
 
                                         <h2 class = "product-name" ><a href= "<?php echo $this->getProductUrl($_product) ?>" ><?php echo $this ->helper( 'catalog/output' )->productAttribute( $_product , $_product ->getName() , 'name' ) ?></a></h2>                                                                                      
 
                                         <div class = "overlay-show" id= "overlay-show-<?php echo $j;?>" >
                                                 <div class = "product-price" >
                                                         <?php echo $this ->getPriceHtml( $_product , true) ?>
                                                 </div>
                                                 <div class = "price-bottombg" ></div>
                                         </div>                                                                                                       
                                 </div>
                                 </div>       
                                 </div>
                                 <script type= "text/javascript" >
                                         var $i = jQuery.noConflict();
                                         $i ( "#overlay-<?php echo $j;?>" ).hover( function () {
                                                 if ( $i ( "#overlay-show-<?php echo $j;?>" ).is( ":hidden" )) {
                                                         $i ( "#overlay-show-<?php echo $j;?>" ).slideDown( "fast" );
                                                 } else {
                                                         $i ( "#overlay-show-<?php echo $j;?>" ).slideUp( "fast" );
                                                 }
                                         });
                                 </script>
                         </div>
         <?php endforeach ; ?>
         </div>
     </div>
</div>
<?php endif ; ?>



Magento在page cms中添加contact form联系我们表单

1.在magento后台CMS> 管理页面界面

2.在content位置,加入如下代码

1
2
3
<!– CONTACT FORM –>
{{block type= "core/template" name= "contactForm" form_action= "/contacts/index/post" template= "contacts/form.phtml" }}
<!– END OF CONTACT FORM –>

 

contact_form_full1




magento边栏调用热门搜索关键字 自动生成

在magento边栏调用热门搜索关键字 有助于Seo 别小看这个功能 通过搜索次数 自定变大
emso
编辑app/design/frontend/default/Your_Theme/layout/catalog.xml
添加到left中

1
< block type = "catalogsearch/term" name = "catalogsearch.term" template = "catalogsearch/sidebar.phtml" />

引用的文件不存在,我们需要新建这个文件
app/design/frontend/default/Your_Theme/template/catalogsearch/sidebar.phtml
内容应该是:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
<div class = "block block-commercial-quotes" >
     <div class = "block-title" >
         <strong><span><?php echo $this ->__( 'Popular Search Terms' ) ?></span></strong>
     </div>
     <div class = "block-content" >
         <?php if ( sizeof( $this ->getTerms()) > 0 ): ?>
             <ul class = "tags-list" >
                     <?php foreach ( $this ->getTerms() as $_term ): ?>
                     <?php if ( $_term ->getRatio()>=0.2): ?>
                             <li><a href= "<?php echo $this->getSearchUrl($_term) ?>" style= "font-size:<?php echo $_term->getRatio()*70+75 ?>%" ><?php echo $this ->htmlEscape( $_term ->getName()) ?></a></li>
                     <?php endif ; ?>
                     <?php endforeach ; ?>
             </ul>
         <div class = "actions" >
             <a href= "/catalogsearch/term/popular/" ><?php echo $this ->__( 'View All Popular Searches' ) ?></a>
         </div>
         <?php else : ?>
             <p class = "note-msg" ><?php echo $this ->__( 'There are no search terms available.' ); ?></p>
         <?php endif ; ?>
     </div>
</div>

 

 
 
 
 

 
 

MAGETNO 最低运费,在详细页加载代码:

<!-- SHOW SHIPPING RATES-->
         <?php $quote = Mage::getModel( 'sales/quote' );
         $quote ->getShippingAddress()->setCountryId( 'ES' ); // Set your default shipping country here
         $_product ->getStockItem()->setUseConfigManageStock(false);
         $_product ->getStockItem()->setManageStock(false);
         $quote ->addProduct( $_product );
         $quote ->getShippingAddress()->setCollectShippingRates(true);
         $quote ->getShippingAddress()->collectTotals();
         $rates = $quote ->getShippingAddress()->getShippingRatesCollection();
         // Find cheapest rate
         $cheapestrate = null;
         foreach ( $rates as $rate ) {
             if ( is_null ( $cheapestrate ) || $rate ->getPrice() < $cheapestrate ) {
                 $cheapestrate = $rate ->getPrice();
             }
         }
         $corehelper = Mage::helper( 'core' );
         if ( $cheapestrate ) {
             echo '<p><strong>Shipping costs:</strong> ' . $corehelper ->currency( $cheapestrate );?></p>
             <?php
             } else {
             echo "<strong>Free shipping</strong> for this product." ;
         }?>
<!-- END SHOW SHIPPING RATES-->




magento product Labels-手动创建产品优惠标签

magento product Labels-手动创建产品优惠标签
Furniture

编辑/app/design/frontend/you-template/default/template/catalog/product/list.phtml
最好是讲代码插入到产品图片的下面

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
<?php       
          $savingsdollarvalue = ( $_product ->getPrice()- $_product ->getFinalPrice()) ;
          $original_price = $_product ->getPrice() ;
          $discount_price = $_product ->getFinalPrice() ;
          $savings = $original_price - $discount_price ;
          $savings_percentage = round ( ( $savings / $original_price )*100, 0 );
          ?>
 
          <?php if ( $discount_price < $original_price ):  ?>
 
          <div class = "odida" >
          <dd><?php echo '' , $savings_percentage , '% OFF' ;  ?></dd>
          </div> 
          <?php else : ?>
 
          <?php endif ; ?>

以上代码建立了一个 div 只要给div附加背景 css 和浮动 信息 例如:

1
2
3
4
5
6
7
8
9
.odida {
     background : url ( "http://l.mengento.com/skin/frontend/fortis/default/images/mic/odadi.png" ) repeat-x scroll center 0 transparent ;
     font-weight : bold ;
     height : 36px ;
     position : relative ;
     right : -166px ;
     top : -291px ;
     width : 52px ;
}



magento欢迎信息中只显示first name或last name

magento欢迎信息中只显示first name或last name

magento-snippet

如果你想改变一下magent的默认欢迎消息在从欢迎,如 “Welcome, Paul Donnelly”变成 “Hi Paul” 或者 “Hello Mr Donnelly”,在app\design\frontend\default\default\template\page\html\header.phtml

Firstname

1
<?php echo $this ->__( 'Hi %s' , Mage::getSingleton( 'customer/session' )->getCustomer()->getFirstname()); ?>

Lastname

1
<?php echo $this ->__( 'Hello Mr %s' , Mage::getSingleton( 'customer/session' )->getCustomer()->getLastname()); ?>


magento所有分类产品 随机展示 简单实现

最近发现了个更简单的办法来调用magento的随机产品

1
&lt;span&gt;{{block type= "catalog/product_list_random" <span style= "color: #000000;" ><del>category_id= "25" </del></span> template= "catalog/product/list.phtml" }}&lt;/span&gt;

其中category_id=”25″,25为分类的ID

这里不能指定分类产品,这里展示的是所有产品随机显示
这样我们就可以输入随机产品了。


Magento调用多个分类id的产品



$productCollection = Mage::getResourceModel( 'reports/product_collection' )
  ->addAttributeToSelect( '*' )
  ->addAttributeToFilter( 'category_ids' , array ( 'finset' => '4,5,6' ))


magento在产品详细页里显示产品的销售数量

产品详细页显示的是view.phtml,在对应的app/code/core/Mage/Catalog/Block/Product/view.php加入

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
function   getQuantityOrderedBySku( $sku )
  {
     try {
     $_product = Mage::getResourceModel( 'reports/product_collection' )
     ->addOrderedQty()
     ->addAttributeToFilter( 'sku' , $sku )
     ->setOrder( 'ordered_qty' , 'desc' )
     ->getFirstItem();
     if (! $_product ) {
     throw new Exception( 'No product matches the given SKU' );
     }
     return (int) $_product ->getOrderedQty();
     }
     catch (Exception $e ) {
     return 0;
     }
  }

要获取某个时间段的某产品销量

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function  getQuantityOrderedBySku( $sku )
    {
    try {
    $_product = Mage::getResourceModel( 'reports/product_collection' );
    if ( $this ->getTimeLimit()) {
    //给查询时间,查询规定时间销售量
    $product = Mage::getModel( 'catalog/product' );
    $todayDate = $product ->getResource()->formatDate(time());
    $startDate = $product ->getResource()->formatDate(time() - 60 * 60 * 24 * $this ->getTimeLimit());
    $_product = $_product ->addOrderedQty( $startDate , $todayDate );
    } else {
    //不给查询时间,查询销售总量
    $_product = $_product ->addOrderedQty();
    }
    $_product = $_product ->addAttributeToFilter( 'sku' , $sku );
    $_product = $_product ->setOrder( 'ordered_qty' , 'desc' );
    $_product = $_product ->getFirstItem();
    if (! $_product ) {
    throw new Exception( 'No product matches the given SKU' );
    }
    return (int) $_product ->getOrderedQty();
    }
    catch (Exception $e ) {
    return 0;
    }
    }

PS: getTimeLimit方法是获取自己设置的天数。

view.phtml合适位置加入

1
<?php echo '最近30天已售出<span class="ordernum">' . $this ->getQuantityOrderedBySku( $_product ->getSku()). '件</span>' ;?>


magento newsletter checkbox自动选中

magento newsletter checkbox

magento newsletter checkbox

修改路径

/app/design/frontend/base/default/template/persistent/customer/form

查找:

01
02
03
04
05
06
07
08
09
10
11
12
13
<?php if ( $this ->isNewsletterEnabled()): ?>
         <li class = "control" >
             <div class = "input-box" >
                  <li>
              <input type= "checkbox" name= "is_subscribed" title= "<?php echo $this->__('Sign Up for Newsletter') ?>" value= "1" id= "is_subscribed" <?php if ( $this ->getFormData()->getIsSubscribed()){ ?> checked= "checked" <?php } elseif ( $this ->getFormData()->getIsSubscribed == NULL){ ?> checked= "checked" <?php }?> />
             <label for = "is_subscribed" ><?php echo $this ->__( 'Sign Up for Newsletter' ) ?></label>
         </li>
     </div>
     <label for = "is_subscribed" ><?php echo $this ->__( 'Sign Up for Newsletter' ) ?></label>
     <?php /* Extensions placeholder */ ?>
     <?php echo $this ->getChildHtml( 'customer.form.register.newsletter' )?>
</li>
<?php endif ?>

替换:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
<?php if ( $this ->isNewsletterEnabled()): ?>
<?php
$checked = true;
if ( $this ->getFormData()->getEmail()) {
     if (! $this ->getFormData()->getIsSubscribed()) {
         $checked = false;
     }
}  
  ?>
<li class = "control" >
<div class = "input-box" >
     <input type= "checkbox" name= "is_subscribed" title= "<?php echo $this->__('Sign Up for Newsletter') ?>" value= "1" id= "is_subscribed" <?php if ( $checked ): ?> checked= "checked" <?php endif ; ?> class = "checkbox" />
</div>
<label for = "is_subscribed" ><?php echo $this ->__( 'Sign Up for Newsletter' ) ?></label>
<?php /* Extensions placeholder */ ?>
<?php echo $this ->getChildHtml( 'customer.form.register.newsletter' )?>
</li>
<?php endif ?>



Magento 登陆之后返回登录之前的页面

Magento 在登陆后一般会自动跳转到 My Account 页面 但是经常会有需求 就是登陆自动跳转到 之前的页面里面 只要加代码

Mage::getSingleton(‘customer/session’)->setBeforeAuthUrl(Mage::getUrl(‘*/*/*’, array(‘_secure’=>true))); 或者

Mage::getSingleton(‘customer/session’)->setBeforeAuthUrl(Mage::helper(“core /url”)->getCurrentUrl());

在之前的页面 就可以实现这个功能





magento在产品详细页通过ajax设置diggs+1

首先需要建立对应的产品属性,这边我们命名为 diggs . 类型为文本,默认值为 0
新建完成后添加此属性到对应的属性组,如Default

20140318212918

接下来,需要进行ajax操作 就要有一个对应的请求url
于是我们需要在控制器中添加对应的动作
修改core/Mage/Catalog/controllers
ProductController.php 文件,添加indexAction 方法 (由于magento local 目录中方法重载偶尔会抽风,所以这边直接对核心文件进行修改)
代码如下:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
public function indexAction()
     {
         $productId = $this ->getRequest()->getParam( 'id' );
         $qty = (int) $this ->getRequest()->getParam( 'qty' );
         $key = Mage::getSingleton( 'core/cookie' )->get( $productId . 'diggs' );
         if (! $key ){
             Mage::getSingleton( 'core/cookie' )->set( $productId . 'diggs' ,md5( $productId . 'diggs' ));
             $product = Mage::getModel( 'catalog/product' )
                     ->load( $productId )
                     ->setDiggs( $qty )
                     ->save();
 
             echo 'yes' ;
         }
     }

属性及处理动作有了,现在要做的就是把他们关联起来了。
这边我们使用jquery进行操作,由于比较菜 就没用prototype去重写ajax 方法了
修改page.xml 或 catalog.xml 在对应位置 调用jquery库,为了防止js库冲突,建议在page.xml 中最先调用jquery
修改 产品查看页代码 view.phtml
添加动作按钮 及 调用相关数据的代码 (样式可自行定义):

1
2
3
4
5
<?php  if ( $_product ->getDiggs()!= '' ): ?>
<span class = "diggs" ><a id= "diggs" href= "javascript:;" >Diggs</a> (<span id= "diggs-qty" >
<?php echo $_product ->getDiggs(); ?>
</span> customers like this)</span><span id= "loadimg" style= "display: none;background:url(<?php echo $this->getUrl('js/jquery').'opc-ajax-loader.gif'; ?>) no-repeat;float:left;height:16px;width:16px;" ></span>
<?php endif ; ?>

然后就是按钮动作控制的js代码了,样例代码如下:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
< script type = "text/javascript" >// <![CDATA[
     jQuery.noConflict();
     jQuery("#diggs").click(function(){
         jQuery("#loadimg").show();
         var diggs = parseInt(jQuery("#diggs-qty").text())+1;
         jQuery.ajax({
         url:"<?php echo Mage::getBaseUrl()?>catalog/product/index",
         dataType:"text",
         data:"id=<?php echo $_product->getId();?>&qty="+diggs,
         success:function(data){
             jQuery("#loadimg").hide();
             if(data){
                 jQuery("#diggs-qty").html(diggs); alert('Thank you!');
             }else{alert('You have already dugg this product.')} }});
     });
// ]]> </ script >

这样一整条 逻辑流程 就算走完了, 清理缓存后测试看看吧 :)


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值