Magento集成:HowTo – “Google +1″ extension for Magento

2,530次阅读
没有评论

共计 3867 个字符,预计需要花费 10 分钟才能阅读完成。

Embedding Google’s +1 button is pretty easy and straightforward. All it takes is to include 2 code snippets in your web page. One goes in the header of the page, and the other one goes to wherever where you want the +1 button to render. To do so all you need is to follow the official Google guideline outlined here.

With that in mind, let’s build us Magento extension, preferably the non-obtrusive one.

We will call our extension “GPlusOne” and place it under the “Inchoo” namespace. Let’s start by creating the /app/etc/modules/Inchoo_GPlusOne.xml file with the following content:

[php]<?xml version="1.0"?>
<config>
<modules>
<Inchoo_GPlusOne>
<active>true</active>
<codePool>community</codePool>
</Inchoo_GPlusOne>
</modules>
</config>
[/php]

Now we need to create second file, app/code/community/Inchoo/GPlusOne/etc/config.xml with the following content:
[php]
<?xml version="1.0"?>
<config>
<modules>
<Inchoo_GPlusOne>
<version>1.0.0.0</version>
</Inchoo_GPlusOne>
</modules>
<global>
<blocks>
<inchoo_gplusone>
<class>Inchoo_GPlusOne_Block</class>
</inchoo_gplusone>
</blocks>
</global>
<frontend>
<layout>
<updates>
<inchoo_gplusone>
<file>inchoo/gplusone.xml</file>
</inchoo_gplusone>
</updates>
</layout>
</frontend>
</config>
[/php]
As you can see we are declaring a new layout file here, called gplusone.xml which we will place under the app/design/frontend/default/default/layout/inchoo/gplusone.xml, with the following content:
[php]
<?xml version="1.0"?>
<layout version="1.0.0">
<catalog_product_view>
<reference name="head">
<block type="core/template" name="inchoo_gplusone_head" template="inchoo/gplusone_head.phtml" />
</reference>
<reference name="alert.urls">
<block type="inchoo_gplusone/PlusButton" name="inchoo_gplusone" />
</reference>
</catalog_product_view>
</layout>

[/php]
Carefully observing the gplusone.xml layout update shows that my layout is to “kick in” only on the product view page. Since embedding the Google +1 Button reguires two scripts to be loaded on page, I’m splitting them into two view files, app/design/frontend/default/default/template/inchoo/gplusone_head.phtml and app/design/frontend/default/default/template/inchoo/gplusone_button.phtml.

File app/design/frontend/default/default/template/inchoo/gplusone_head.phtml is loaded into the head area of HTML via ‘reference name=”head”‘ layout update, having the following content:
[php]

<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>

[/php]
While file app/design/frontend/default/default/template/inchoo/gplusone_button.phtml is loaded into the content area of the page, more specifically “alert.urls” block via ‘reference name=”alert.urls”. For more detailed understanding one should study the app/design/frontend/base/default/layout/catalog.xml file and its ‘‘ section. Content of gplusone_button.phtml is as follows:
[php]

<g:plusone <?php if($size = $this->getSize()) { echo ‘ size="’.$size.’"’; } ?>></g:plusone>
[/php]

Which bring’s us to the final file needed to get this running, app/code/community/Inchoo/GPlusOne/Block/PlusButton.php with the following content:

[php]

<?php
class Inchoo_GPlusOne_Block_PlusButton extends Mage_Core_Block_Template
{
/**
* Constructor. Set template.
*/
protected function _construct()
{
parent::_construct();
$this->setTemplate(‘inchoo/gplusone_button.phtml’);
}
public function getSize()
{
//Here we can implement the code to read the config values for sizes
return ”;
}
}
[/php]
If you look at the gplusone_button.phtml file you will see it has a call towards getSize() method from Inchoo_GPlusOne_Block_PlusButton class. At the moment, this method does nothing. It’s merely here for possible extension of this simple module. Given that Google +1 button supports various sizes (“small”, “medium”, “tall”, or no size definition for standard size) you can easily add some extra logic to this extension to have it read some config values that could be set from Magento admin.

The point of this article was not to give you a full blown extension ready to be used in instance, rather to show you the amount of effort needed to implement something as simple as Google +1 button in Magento the right way (not to say that this is the best possible way).

And here is the screenshot of the final result.

Magento集成:HowTo – “Google +1″ extension for Magento

Hope someone finds it useful.

Cheers.

备注:http://inchoo.net/ecommerce/magento/howto-google-1-extension-for-magento/

正文完
 0
评论(没有评论)

空瓶子部落

文章搜索
推荐阅读
工序质量控制:自检+首检+巡检内容和规则

工序质量控制:自检+首检+巡检内容和规则

*工序质量检验的目的,是利用一定的方法,对工序操作及其完成产品的质量,进行实际而及时的测定和检查。 并将所测得...
工作能力强的人,都会建立SOP思维

工作能力强的人,都会建立SOP思维

在工作中,我们常常会听到有人抱怨工作杂乱无章、效率低下,或者因为忙碌而频频出错。 其实,许多工作能力强的人并不...
如何绘制因果图

如何绘制因果图

作为qc7大手法之一的因果图,其作用是帮助品管人员选出影响质量的因素,并将它们联系起来。通过阐明每个因素是怎样...
​向上管理就像养狗,方法其实很简单

​向上管理就像养狗,方法其实很简单

01 都需要了解对方的“语言” 有个笑话,一个人总对狗说“你真聪明”,结果狗一直不理他。 后来他改口说“汪汪汪...
最新文章
群晖 Let’s Encrypt 泛域名证书自动更新

群晖 Let’s Encrypt 泛域名证书自动更新

目前acme协议版本更新,开始支持泛域名(wildcard),也就是说,可以申请一个类似*.domain.co...
可以卸载TV Box 了,这款支持「绅士模式」的影视神器你值得拥有

可以卸载TV Box 了,这款支持「绅士模式」的影视神器你值得拥有

还在为找优秀片源难、广告多、平台会员太贵而烦恼?今天给大家挖到一款真正的影视宝藏工具——小猫影视! 作为开源免...
【收藏】一次性解决TV点播/直播自由

【收藏】一次性解决TV点播/直播自由

很多时候,资源就在面前,但是我们视而不见,因为长久的安逸,已经让人失去动手的兴趣。但是每次我需要挨个切换APP...
OpenWrt 存储空间扩容的两种方案

OpenWrt 存储空间扩容的两种方案

说明:当我们通过群晖 VMM 虚拟机安装 Open­Wrt 时,默认会分配一个 10GB 的存储空间,而实际情...
OpenWrt修改IP地址两种方法(直接命令修改跟后台修改)

OpenWrt修改IP地址两种方法(直接命令修改跟后台修改)

OpenWrt是什么?OpenWrt一般常见于无线路由器(软路由)第三方固件,它是一个高效、可靠、功能多的路由...
热门文章
提高过程能力指数(CP/CPK)的途径

提高过程能力指数(CP/CPK)的途径

编者按:过程能力指数(CP/CPK)想必各位质量人都耳熟能详、运用自如,质量工程师之家前期也共享过数篇关于过程...
SPC控制图的八种模式分析

SPC控制图的八种模式分析

SPC控制图有八种模式,即八种判断异常的检验准则,每一种检验准则代表一种异常现象,应用SPC控制图进行过程评估...
测量高手放大招:圆跳动测量技巧总结

测量高手放大招:圆跳动测量技巧总结

01. 前言 在五金机加工厂实际的测量工作中,经常碰到要求测量两个要素的圆跳动问题, 利用不同的测量辅件及夹具...
过程能力分析(CP&cpk)

过程能力分析(CP&cpk)

引入过程能力分析的目的? 在我们现有的管理过程中,我们经常会遇到有些具体指标总是不尽人意,存在许多需要改进的地...
新能源汽车 “两会”精神宣贯会

新能源汽车 “两会”精神宣贯会

此次和大家分享新能源汽车相关政策: [embeddoc url=”https://www.ctro...
最新评论
多乐士 多乐士 通过摸索发现ssh拉取会报错,直接网页访问下载会报404错误,不知道原因;但是可以通过群晖CM注册表访问下载,其方法如下: Container Manager-注册表-设置-新增-注册表名称随便写,注册表URL填你的加速地址,勾选信任的SSL自我签署证书,登录信息不填-应用-使用你的地址,这是注册表会显示了,在搜索栏中输入映像名称,搜索结果在每一页的最后一个,你需要划到最后一个进行下载,实测可正常下载安装。 以上供网友参考。
多乐士 多乐士 还有一个比较简单的方法,只是需要一些外部工具。 1、讲损毁硬盘取出,装入外部移动硬盘 2、打开Diskgenius,定位到硬盘 3、格式化系统分区 4、重新插入硬盘 5、存储池->修复存储池即可
多乐士 多乐士 写的不错的文章
辞了老衲 辞了老衲 这个确实有帮助。
渋驀 渋驀 当然任何时候都可以用curl命令和crontab来实现动态更新DDNS的ip地址: 1、安装crontab之后为root用户创建文件/var/spool/cron/root 2、创建并配置ddnsupdate.sh,放到/usr/bin/文件下,文件内容(以he.net为例): Autodetect my IPv4/IPv6 address: IPV4:curl -4 "http://dyn.example.com:password@dyn.dns.he.net/nic/update?hostname=dyn.example.com" IPV6:curl -6 "http://dyn.example.com:password@dyn.dns.he.net/nic/update?hostname=dyn.example.com" 3、添加执行权限chomod +x /usr/bin/ddnsupdate.sh 4、编辑root用户的crontab:*/10 * * * * /usr/binddnsupdate.sh,每10分钟执行一次。好了,可以享受你的DDNS了
21410 21410 请问下载链接在那里?
madkylin madkylin 不错,不错,谢谢分享了,好东西啊 :lol:
feilung feilung 求方法
zengsuyi zengsuyi 应该挺不错的
zise zise 看看是怎么操作的。。 :oops: