Magento与wordpress整合插件-WordPress Integration
最近在折腾Magento与wordpress的整合。在朋友的推荐下今天装了WordPress Integration这个插件。安装方法很简单,首先在Magento根目录下安装wordpress。数据库可以新建一个,也可以使用Magento的。然后安装这个插件就好。如果你使用的是独立数据库,需要在后台设置下,否则无法连接到数据库。Magento 后台wordpress->Settings->Database/Integration,中设置下。

看了下插件的官方文档,常用的一些wordpress插件都是支持的,具体的使用方法和效果,以后再分享。刚装上插件,还没玩……
Magento seo优化——让产品链接唯一
在Magento后台会默认开启Use Categories Path for Product URLs。

这时候产品链接就会变成两个http://127.0.0.1/magentoyouhua/index.php/furniture/living-room/ottoman.html,http://127.0.0.1/magentoyouhua/index.php/ottoman.html。两个链接同时链向一个页面时,这样对seo是不好的。解决方法:
一、在后台关闭这个功能。
二、修改php文件去除分类url路径,因为在关闭这个功能后,一些插件还是会自带分类url路径。打开app/code/core/Mage/Catalog/Model/url.php
找到
1 2 3 4 5 6 7 8 9 10 11 12 13 | if (null === $parentPath) { $parentPath = $this->getResource()->getCategoryParentPath($category); } elseif ($parentPath == '/') { $parentPath= ''; } 修改成 //if (null === $parentPath) { //$parentPath = $this->getResource()->getCategoryParentPath($category); //} //elseif ($parentPath == '/') { $parentPath= ''; //} |
然后刷新下索引就可以了。
可筛选下拉框在Magento商城中的应用
在Magento添加可配置产品的时候,某一属性如果选项很多,我们就要盯着下拉框一个一个扫描下去了,这样会崩溃的。我用jQuery写了个可以对属性进行筛选的方法。实现原理就是弄了个假的select选择框覆盖在上面。先看下事例图。
未进行筛选的下拉框

筛选后的下拉框

在app/design/adminhtml/default/default/template/cagalog/product /edit/super/config.phtml加入以下代码.
其中#simple_product_huaxing是select的id,改为你的select的iD即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <div id="huase"> <div id="selecthuaxin"><input type="text" /></div> </div> <script type="text/javascript">// <![CDATA[ jQuery("#huase").insertBefore("#simple_product_huaxing"); jQuery("#selecthuaxin input").keyup(function(){ var inputval=jQuery(this).val(); jQuery("#weiselect li").remove() jQuery("#simple_product_huaxing option:contains("+inputval+")").each(function(){ var selecton=jQuery(this).text(); var opval=jQuery(this).val(); var li=jQuery(" <li />") li.text(selecton) jQuery("#weiselect").append(li) li.addClass(opval) jQuery("#weiselect li").click(function(){ var lion=jQuery(this).attr("class") var litext= jQuery(this).text() jQuery("#simple_product_huaxing").val(lion); jQuery("#selecthuaxin input").val(litext) jQuery("#weiselect li").remove() }) jQuery("#simple_product_huaxing").change(function(){ var selcted=jQuery("#simple_product_huaxing option:selected").text() jQuery("#selecthuaxin input").val(selcted) }) jQuery("#weiselect li").hover(function(){ jQuery(this).css({background:"#2E4A99",color:"#fff"}) },function(){ jQuery(this).css({background:"#fff",color:"#000"}) } ) }); }) // ]]></script> |
Magento注册验证加强
Magento有自带的一个验证机制,但是用起来,用户体验不太好,Magento是在点击提交按钮以后才开始验证的。良好的用户体验是在客户提交表单前就提出错误的地方,可以去玩下淘宝的注册。
我先讲下Magento自带的验证机制的使用方法,首页看下js/prototype/validation.js,整个网站的验证相关的东西都写这里面,有能力的可以直接在这里面改,改成你想要的模式。Magento是通过class名来触发这个验证。我以注册页面为例,先看下注册页面的Email的html
1 | <input type="text" class="input-text validate-email required-entry" id="email_address" name="email"> |
required-entry说明这个是必填项,validate-email说明这个是邮箱验证。如果你想在其他的地方做这些验证 只要加上这两个class就行。
我在Magento的基础上,用jQuery做了点判断,做成类似淘宝的了。
我是通过blur事件来触发的,隐藏和显示div达到这个效果,下面发一些判断的正则。
判断电话号码,手机,座机一起判断的
1 | ((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$) |
判断邮编
1 | ^[0-9]{6}$ |
判断邮箱
1 | ^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$ |
Magento在产品页添加SKU,产品属性
Magento产品页有时需要把SKU号调出来,方法:
1 | <?php echo $this->htmlEscape($_product->getSku()) ?> |
Magento的产品属性,在catalog.xml中已经写进去了。你可以在product view中找到
1 2 3 | <block type="catalog/product_view_attributes" name="product.attributes" as="additional" template="catalog/product/view/attributes.phtml"> <action method="addToParentGroup"><group>detailed_info</group></action> </block> |
现在只要在产品详细页(view.phtml)中想要的位置插入
1 | <?php echo $this->getChildHtml('additional') ?> |
Magento速度优化——异步加载
Magento的这个速度优化,之前有讲到过了Magento加速利器——lazyload,其实就是异步加载。这次我讲的是在protype下的lazyload,效果是和淘宝的一样,不过淘宝用的是YUI的。不想加载jQUery的可以用这个protype下的lazyload,同样是减少http请求,但是他会先遍历一遍所有的预选的img类型。我就不详细解释了,我直接放js地址了http://www.bram.us/projects/js_bramus/lazierload/
Magento的加速要一点一点的坐上去, 最近为magento的速度事情纠结了很久。希望大家对于magento的速度优化有什么妙招,可以告诉我,嘿嘿
Magento进入插件管理报错解决方法
今天在安装magento插件的时候碰到的问题,报错信息是:
Fatal error: require_once() [function.require]: Failed opening required ‘System.php’。这个是因为后台编译打开的原因,关掉即可。
另外还碰到个下载插件后无效的解决方法(仅限于转移服务器后),进入magento文件夹downloader\pearlib,里面有个pear.ini,删除就可以了。把安装无效的那个插件卸载了重新安装就可以了。
以上是水水友情协助,并强迫我给他的magento博客加链接http://blog.csdn.net/shuishui8310,强大的博客啊 ,可惜被百度惩罚了。magento开发人员去那寻宝吧。
Magneto功能强大的分页
Magento分页功能基本包含了常用的分页功能。之前没有去挖掘分页的功能,以为只有默认的一种,还在纠结默认的太简单了,准备换个。水水最近研究了下那东西,我就直接把他的劳动成果拿出来分享了,嘿嘿……
这里只是简单的介绍下,让大家知道有这个功能,配置什么的都很简单。进入magento后台system->Configuration->Design有个Pagination栏,设置都在里面了,可以实现一般的分页功能了。有需要的可以慢慢玩了,如果有更好的,希望大家推荐下。
Magento获取分类的销售排行
Magento有个热门商品的插件,但是那个插件不显示产品的销售数量,现在分享下能够指定分类,显示销售数量的方法。
新建一个block,内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | $totalPerPage = ($this->show_total) ? $this->show_total : 8; $counter = 1; $catalogid = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); $catalogid=($catalogid) ? $catalogid : 2; $_featcategory = Mage::getModel('catalog/category')->load($catalogid); $visibility = array( Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG ); $storeId = Mage::app()->getStore()->getId(); $_productCollection = Mage::getResourceModel('reports/product_collection') ->addAttributeToSelect('*') ->addOrderedQty() ->addAttributeToFilter('visibility', $visibility) ->addCategoryFilter($_featcategory) //全部产品的排行 ->setOrder('ordered_qty', 'desc'); ?> <ul> <?php foreach($_productCollection as $product): ?> <?php if($counter <= $totalPerPage): ?> <?php $productUrl = $product->getProductUrl() ?> <li class="l"> <a onclick="this.target='_blank'" class="hotimg" href="<?php echo $productUrl ?>" title="View <?php echo $product->name ?>"> <img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(77); ?>" alt="<?php echo $product->name ?>" /> </a> <h2><a onclick="this.target='_blank'" href="<?php echo $productUrl ?>" title="View <?php echo $product->name ?>"> <?php echo Mage::helper("core/string")->truncate($product->name,6,'') ;?> </a> </h2> <span class="price-label"><?php echo $this->__('Special Price:') ?></span> <span class="bestprice"> <?php echo $this->helper('core')->currency($product->getFinalPrice(),true,false) ?></span> <span class="selled">已售出: <?php echo (int)$product->ordered_qty ?></span> </li> <?php endif; $counter++; ?> <?php endforeach; ?> </ul> |
然后在magento中需要的地方插入即可,这个我在一个商城中已经用上,没有问题。
Magento中新建添加了special price的产品模块
在Magneto中新建special price页面这个功能模块用到的应该不多,现在的商城基本都是所有的产品的会加上special price。国外有些商城可能会用到这个功能,放假的时候查了些资料,现在分享下这个功能模块。
在app/design/frontend/default/你的主题/template/catalog/product中新建special.phtml,加入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <?php include_once 'app/Mage.php'; Mage::app(); Mage::getSingleton('core/session', array('name' => 'frontend')); $_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection') ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->addMinimalPrice() ->addStoreFilter(); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection); $todayDate = date('m/d/y'); $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y')); $tomorrowDate = date('m/d/y', $tomorrow); $_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate)) ->addAttributeToFilter('special_to_date', array('or'=> array( 0 => array('date' => true, 'from' => $tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null'))) ), 'left'); foreach($_productCollection as $_product){ if($_product->getData('special_price')!=null){ echo '<img src="'.$this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75).'" alt="'.$_product->getName().'" /><br />'; echo $_product->getName().'<br />'; $specialPrice = $_product->getData('special_price'); $orignalPrice = $_product->getData('price'); echo number_format($specialPrice, 2)."<br/>"; echo number_format($orignalPrice, 2)."<br/>"; echo '<a href="http://www.yourwebsite.com/magento/checkout/cart/add?product='.$_product->getId().'&qty;=1">Add To Cart</a><br />'; } } ?> |
这个只是实现了基本功能,样式布局方面还需要修改。有什么问题欢迎一起探讨。
紫月蓝骋