Magento在产品页面提供了一个简单的图片放大功能,不是非常好,假设考虑使用放大镜来使用户查看产品的大图。能够考虑使用基于jQuery的插件,jqZoom便是一款优秀的放大镜插件。以下将介绍如何把jqzoom集成到Magento中。

1 载入jQuery
由于jqZoom是基于jQuery的插件,所以我们须要在Magento中载入jQuery库,并下载jqZoom文件包,放在站点的根文件夹的js文件夹下,比方/js/jqzoom

2 建立模块
作为样例,我们在/app/code/local/MagentoBoy/Jqzoom文件夹下新建一个模块MagentoBoy_Jqzoom。并加入模块文件:
/app/etc/modules/MagentoBoy_Jqzoom.xml
  1. <?

    xml version="1.0"?>

  2. <config>
  3. <modules>
  4. <MagentoBoy_Jqzoom>
  5. <active>true</active>
  6. <codePool>local</codePool>
  7. </MagentoBoy_Jqzoom>
  8. </modules>
  9. </config>
并加入配置文件
/app/code/local/MagentoBoy/Jqzoom/etc/config.xml
  1. <?xml version="1.0"?>
  2. <config>
  3. <modules>
  4. <MagentoBoy_Jqzoom>
  5. <version>0.1.0</version>
  6. </MagentoBoy_Jqzoom>
  7. </modules>
  8. </config>

3 加入Layout文件
/app/design/frontend/default/default/layout/jqzoom.xml
  1. <?xml version="1.0"?>
  2. <layout>
  3. <catalog_product_view>
  4. <reference name="head">
  5. <action method="addItem"><type>js</type><name>jqzoom/js/jquery.jqzoom-core.js</name></action>
  6. <action method="addItem"><type>js_css</type><name>jqzoom/css/jquery.jqzoom.css</name></action>
  7. </reference>
  8. <reference name="product.info.media">
  9. <action method="setTemplate"><template>jqzoom/media.phtml</template></action>
  10. </reference>
  11. </catalog_product_view>
  12. <review_product_list>
  13. <reference name="head">
  14. <action method="addItem"><type>js</type><name>jqzoom/js/jquery.jqzoom-core.js</name></action>
  15. <action method="addItem"><type>js_css</type><name>jqzoom/css/jquery.jqzoom.css</name></action>
  16. </reference>
  17. <reference name="product.info.media">
  18. <action method="setTemplate"><template>jqzoom/media.phtml</template></action>
  19. <action method="disableGallery"/>
  20. </reference>
  21. </review_product_list>
  22. </layout>
并在config.xml中加入layout文件
  1. <config>
  2. <frontend>
  3. <layout>
  4. <updates>
  5. <jqzoom>
  6. <file>jqzoom.xml</file>
  7. </jqzoom>
  8. </updates>
  9. </layout>
  10. </frontend>
  11. </config>

4 改动template文件
/app/design/frontend/default/default/template/jqzoom/media.phtml
  1. <?

    php

  2. $_product = $this->getProduct();
  3. $_helper = $this->helper('catalog/output');
  4. ?>
  5. <?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
  6. <p class="product-image">
  7. <a href="<?php
    echo $this->helper('catalog/image')->init($_product, 'image');?

    >" class="jqzoom" rel="gal1" title="<?php
    echo $this->htmlEscape($this->getImageLabel());?>">

  8. <img id="image" src="<?

    php
    echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(265);?>" alt="<?

    php
    echo $this->htmlEscape($this->getImageLabel());?

    >" title="<?php echo
    $this->htmlEscape($this->getImageLabel());?>" style="width:265px;" />

  9. </a>
  10. </p>
  11. <p class="zoom-notice" id="track_hint"><?php echo $this->__('Hover
    on image to zoom in the picture') ?></p>
  12. <?php else: ?>
  13. <p class="product-image">
  14. <?php
  15. $_img = '<img
    src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(265).'"
    alt="'.$this->htmlEscape($this->getImageLabel()).'"
    title="'.$this->htmlEscape($this->getImageLabel()).'"
    />';
  16. echo $_helper->productAttribute($_product, $_img, 'image');
  17. ?

    >

  18. </p>
  19. <?

    php endif; ?>

  20. <?

    php if (count($this->getGalleryImages()) > 0): ?

    >

  21. <div class="more-views">
  22. <h2><?php echo $this->__('More
    Views') ?

    ></h2>

  23. <ul>
  24. <li>
  25. <a class="zoomThumbActive" href="javascript:void(0);" rel="{gallery:'gal1',
    smallimage:'<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(265);?>', largeimage:'<?php echo $this->helper('catalog/image')->init($_product, 'image');?>'}" title="<?php
    echo $this->htmlEscape($this->getImageLabel());?>"><img src="<?php
    echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(56);?>" width="56" height="56" alt="<?php
    echo $this->htmlEscape($this->getImageLabel());?>" /></a>
  26. </li>
  27. <?php foreach ($this->getGalleryImages() as $_image): ?

    >

  28. <li>
  29. <a href="javascript:void(0);" rel="{gallery:'gal1',
    smallimage:'<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(265);?>', largeimage:'<?php echo $this->helper('catalog/image')->init($_product, 'image', $_image->getFile());?

    >'}" title="<?php
    echo $this->htmlEscape($this->getImageLabel());?>"><img src="<?php
    echo Mage::helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(56);?>" width="56" height="56" alt="<?php
    echo $this->htmlEscape($this->getImageLabel());?>" /></a>

  30. </li>
  31. <?php endforeach; ?

    >

  32. </ul>
  33. </div>
  34. <?

    php endif; ?

    >

  35. <script type="text/javascript">
  36. //<![CDATA[
  37. var $j = jQuery.noConflict();
  38. $j(document).ready(function(){
  39. $j('.jqzoom').jqzoom({
  40. 'zoomWidth' : 300,
  41. 'zoomHeight' : 300,
  42. 'xOffset' : 10,
  43. 'yOffset' : 0,
  44. 'position' : 'right',
  45. 'preloadImages' : true,
  46. 'preloadText' : 'Loading zoom',
  47. 'title' : true,
  48. 'lens' : true,
  49. 'imageOpacity' : '0.4',
  50. 'showEffect' : 'show',
  51. 'hideEffect' : 'hide',
  52. 'fadeinSpeed' : 'slow',
  53. 'fadeoutSpeed' : '2000'
  54. });
  55. });
  56. //]]>
  57. </script>

清除缓存。刷新头版。当鼠标悬停在产品形象,看产品的放大图。

版权声明:本文博客原创文章。博客,未经同意,不得转载。

在Magento产品页面的使用jqZoom的更多相关文章

  1. Magento给新产品页面添加分页

    本文介绍如何让magento创建一个带分页功能的新到产品页面,方便我们在首页或者其它CMS Page调用和展示新到产品. 在Magento我们经常有的做法是建立一个可以调用新产品的block,然后通过 ...

  2. 如何给magento的产品页面添加返回按钮

    如何给magento的产品页面添加返回按钮,最模板提供教程 第一步: 打开 E:\xampp\htdocs\magento\skin\frontend\default\bluescale\css\st ...

  3. 如何修改magento产品详细页面的栏目

    magento默认模板里面的产品信息页面的布局是以两栏带右侧栏显示的,那么如何修改为两栏带左侧栏或者三栏.一栏的方式显示呢?下面教大家一种很简单的方法就可以实现.下面是默认的布局预览:

  4. 如何实现Magento产品批量导入?

    从事外贸的我们在工作中,经常需要添加成千上万个的产品,如果一个一个的去上传,要花费很多时间,有是很让人头痛,那么应该如何实现产品批量上传?如果使用的是Magento系统的话,那么你现在有福利了,因为M ...

  5. Magento产品批量导入方法?

    从事外贸的我们在工作中,经常需要添加成千上万个的产品,如果一个一个的去上传,要花费很多时间,有是很让人头痛,那么应该如何实现产品批量上传?如果使用的是Magento系统的话,那么你现在有福利了,因为M ...

  6. magento产品批量导出导入

    magento产品批量导出导入 博客分类: WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra ExcelMobile配置管理XML ...

  7. magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮

    1 添加产品到购物车成功后是跳转到购物车页面或不跳转.这个在后台可以设置 system -> configuration -> After Adding a Product Redirec ...

  8. 如何修改magento分类页面的产品的显示个数

    经常的有客户问,怎么修改分类页面的产品的个数 这个是magneto后台操作的设置问题 打开后台,在英文状态下: system-->configuration 进入后,点击catalog Prod ...

  9. magento 获得当前产品页面的产品id

    $product_id = Mage::registry('current_product')->getId();

随机推荐

  1. shell script 入门 笔记

    shell script 入门 在 shell script 注意必须使用完全相同写在下面: 1.  指令的运行是从上而下.从左而右的分析与运行: 2.  指令的运行就如同第五章内提到的: 指令.选项 ...

  2. 算法 《霍纳的方法java实践》

    [历史背景] 霍纳的方法是中国南宋时期的数学家秦九韶表述求解一元高次多项式的值的算法--正负开方术. 它也能够配合牛顿法用来求解一元高次多项式的根.在西方被称作霍纳算法(Horner algorith ...

  3. SDL2来源分析3:渲染(SDL_Renderer)

    ===================================================== SDL源代码分析系列文章上市: SDL2源码分析1:初始化(SDL_Init()) SDL2 ...

  4. RandomAccessFile实时读取大文件(转)

    最近有一个银行数据漂白系统,要求操作人员在页面调用远端Linux服务器的shell,并将shell输出的信息保存到一个日志文件,前台页面要实时显示日志文件的内容.这个问题难点在于如何判断哪些数据是新增 ...

  5. cocos2dx tolua传递参数分析

    cocos2dx tolua传递参数分析: tolua_Cocos2d_CCNode_addChild00 == void CCNode::addChild(CCNode *child) tolua_ ...

  6. mapxtreme C# 完美车辆动态轨迹展示

    演示程序请在 http://pan.baidu.com/s/1jG9gKMM#dir/path=%2F%E4%BA%A7%E5%93%81%2FDemos 找 Trajectory.rar 轨迹回放功 ...

  7. mysql 解压缩和赋权

    拉开拉链mysql紧凑根文件夹 注意ini配置文件的内容 basedir = D:\mysql-5.6.17-winx64  datadir = D:\mysql-5.6.17-winx64  por ...

  8. java生成二维码(带logo)

    之前写过一篇不带logo的二维码实现方式,採用QRCode和ZXing两种方式 http://blog.csdn.net/xiaokui_wingfly/article/details/3947618 ...

  9. MVC中使用泛型仓储模式和依赖注入

    在ASP.NET MVC中使用泛型仓储模式和依赖注入,实现增删查改 原文链接:http://www.codeproject.com/Articles/838097/CRUD-Operations-Us ...

  10. Hadoop Streaming 得到mapreduce_map_input_file中遇到的问题的版本号

    1.Hadoop Streaming,您可以在任务获得hadoop设置环境变量, 例如,使用awk书面map从而能获得:filename = ENVIRON["mapreduce_map_i ...