PHP

浏览模式: 标准 | 列表 | 图文
Add tags when creating product in Magento?

Add tags when creating product in Magento?

A) to add tags directly when entering/editing a product, you will need an extension, such as this one. This method is most useful to let people with less magento experience create tags (such as data entry people).

B) To add tags without leaving the administrator (not going to the frontend). This is useful for applying the same tag to multiple products:

Create tags through Catalog->All Tags-> Add New Tag button.

After creating the tags, click on each tag. You’ll see a detailed set of options to “Edit Tag”.

Go to the “Products tagged as administrator” tab, click on ‘Reset Filter” . You see all your products getting listed.

Select the products to which you want to assign the tag & click on “Save Tag”.

C) To add tags via the frontend & the backend, which is useful when you want to add a lot of tags to each single product:

Just create your products as normal. When you are ready to add tags to your products just create yourself a customer account for your store and go to each product and add them as a customer would. I wrote out all of my tags in a text editor. Now since I am using phrases, and not just words, my tags will be entered as:

‘Stylus C64’ ‘Stylus C66’ ‘Stylus C84’ ‘Stylus C84N’ ‘Stylus C84WN’ ‘Stylus C86’ ‘Stylus CX3600’ ‘Stylus CX3650’ ‘Stylus CX4600’ ‘Stylus CX6400’ ‘Stylus CX6600’

Take note that you need the single quote (’) to bracket your phrases… or just spaces between each word if your tags are single words. Very easy to write out and then copy/paste into the Add Your Tags section of each product.

Once you copy/paste your tags in the front-end you will be prompted with a message that they must be approved from the admin/moderator. Now log into the back-end and go to the tags section (Catalog > Tags > Pending Tags). There you will see the list of tags you just submitted from the front-end of the site. Now just click “Select All”, then from the Actions drop-down menu choose “Change Status”, and then from the status drop-down choose “Approved” and then “Submit”.

Now you can pick a method most appropriate for each type of use!

http://stackoverflow.com/questions/9261935/add-tags-when-creating-product-in-magento

magento 中处理 catalog_product_prepare_save 行为

magento 中处理 catalog_product_prepare_save 行为

最近在做magento二次开发,遇到个问题,即,我要针对商品的数据中的某些数据做二次处理。看了一下代码,发现在initProduct前有一个event事件:catalog_product_prepare_save,所以我想我只要覆盖这个方法就OK了。网上找了些资料,发现如果再绑定一个event则多个Event都会执行。于是,我就按照这个思路在config.xml里加入了events事件。

然后在Model下面加了Observer.php来监听事件。为了测试系统自有的event能够工作,我在系统默认的event里做了一下输出,发现确实有变化 了。所以证明我的思路还是正确的。当然,这也借鉴了网上的一些资料

config.xml里加入:

<adminhtml>
<events>
<catalog_product_prepare_save>
<observers>
<xxx_web_observer>
<type>singleton</type>
<class>Xxx_Web_Model_Observer</class>
<method>prepareProductAuthor</method>
</xxx_web_observer>
</observers>
</catalog_product_prepare_save>
</events>
</adminhtml>

本来我class想写成xxxx/observer的,但死活通不过,我不知道是我写错了。还是。。最后写成详细的类名才OK。(也可能是因为不在系统目录下,而在local目录下的原因吧?)

Observer就不写了。参考core/mage/bundle/model/observer.php即可(本来有大小写的,我忽略了)

php能做什么?

php能做什么?

最近好象关于PHP能做什么的话题又出来了。其实说白了,PHP啥都能做,进可攻退可守。有人说,PHP没有多线程,没有这没有那。其实很多人都用PHP实现了这些功能。

先说其他的,上次thinkinlamp聚会的时候,一位台湾朋友就展示了php用来做类似单片机功能的事情。也从侧面证明了,PHP可以搞类似驱动的事情(也只能在linux下面,毕竟linux下面任何东西都是文件)
PHP还能做什么?有人用php来自己做Web服务器。或许有人说了,PHP自带不是有PHP -S xxx:81吗?其实是很多人用socket自己实现了webserver。
还有人说PHP没有多线程,但PHP在linux下面fork进程后,也能算是当成多线程了吧。
只是目前可能是异步在实现上没有那么好吧。
有些项目大家可以看看的,先不谈有人直接用C实现PHP的框架,这没意思,为了提升性能,这些代码我们都看不到了。
不过,有些纯用PHP实现的玩意可以学习一下。这些代码,也不错,思路更不错
1、reactphp
2、aopphp
3、国内的swolephp
这些都是改变思路的程序,如果你要学多进程,其实,你可以看APNSPHP,即能用来当成apns server,你也可以照着学多进程的程序。
BAE的坑

BAE的坑

自从GAE出来后。什么SAE,ACE,BAE什么什么的就全部出来了

ACE我跑几个程序一直有问题,禁用了一些函数,所以我最近在看BAE。速度也不错,也能绑域名。所以它就成了首选。但BAE有一个坑 需要注意
如果你的程序的上传没有改过。那么一般都是上传在自己当前的项目目录里,而这个目录由于没有经过svn上传,所以它并不在版本库里,因此,一旦碰到BAE来一个svn迁移的事件。或者更新的时候,极有可能你上传的那些附件会全部丢失。
慎重。我就觉得BAE就象一个实验室。我们上传代码到BAE的svn库里。然后svn库会自动 checkout到BAE的平台。于是。。如果他们要迁移了。这些数据应该都是直接delete。然后再checkout一份。
建议找个程序,上传到BAE自带的存储中(就象sae的存储)。
转:2011-10-12 PHP重用curl句柄, CURLOPT_HTTPGET的BUG

转:2011-10-12 PHP重用curl句柄, CURLOPT_HTTPGET的BUG

转的文章。主要是因为经常会用curl来抓取数据。而且几乎是http_get和http_post混用。但我没遇上这个BUG。不清楚以后会不会遇上,所以我先记录一下,以防万一遇到时候不知道怎么做。

原文地址来自:http://www.ideawu.net/blog/archives/622.html

重用一个CURL句柄时, 发现curl_setopt($ch, CURLOPT_HTTPGET, TRUE) 不起作用. 期望在调用这条语句之后发起请求, 应该发送的是GET, 但看服务器log, 却使用了和前一次请求相同的HTTP方法.

PHP脚本:

<?php $url = 'http://www.ideawu.net/';  $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_exec($ch);  curl_setopt($ch, CURLOPT_HTTPGET, true); // 错误! BUG curl_exec($ch);  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // 正确 curl_exec($ch); ?>

web server log:

124.127.130.50 "2011-10-12 18:55:09" "POST / HTTP/1.1" 200 3516 "-" www.ideawu.net 124.127.130.50 "2011-10-12 18:55:09" "POST / HTTP/1.1" 200 3516 "-" www.ideawu.net 124.127.130.50 "2011-10-12 18:55:09" "GET / HTTP/1.1" 200 3516 "-" www.ideawu.net

这个BUG目前还没找到相关的资料.

补充: 不仅仅是CURLOPT_HTTPGET, CURLOPT_POST也有同样的问题. 所以, 结论是: 只有CURLOPT_CUSTOMREQUEST才是正确的方法.

开始要关注性能了

开始要关注性能了

不得不说,我现在要开始关注性能和稳定性了

最近检查命令行下程序的输出,发现最后退出的LOG大多数是allow memory ....的问题,固然这个命令行下面内存释放有问题有关,但主动释放还是必要的。
毕竟web页在处理完当前请求后,还能够被回收掉一点。php-fpm之类的,还能帮忙,但命令行,它就没有断开过,一直在运行,因此,需要注意一下释放了
或者在无法释放的时候,自己设置一个临界点。到临界点的时候自我重启一下也OK。
逐步开始研究下

完成两个小工具

今天完成了两个小工具
1、靖江日报电子版的提取

2、上海交通违章的自动查询
靖江日报电子版的难点不多,很快就解决了,基本上也就半小时
上海交通违章的查询就有点麻烦了
1、验证码是bmp的。。
2、验证码的提交经常失败
3、post的时候,模拟数据用的是utf-8,死活不对。。
解决这三个问题,剩下的就是一些细节了。
---
其实这两天还做了很多小玩意
1、淘宝商品的获取和商品详情的取得
2、上述功能的自动更新和批量处理
3、不足:不知道淘宝客的点击怎么生成(目前我没有isv权限,如果说用接口的,请绕路)
4、测试了阿里妈妈的jssdk,但无法跳转(点击的时候是可以生成s.click的url,但没法入库,很纠结)
5、暂时没有办法生成阿里妈妈后台的:单品自定义链接(用flash的,我一下子不会生成),不过应该很快了。。。
将typecho移植到bae

将typecho移植到bae

发现一个问题,BAE可以直接用$_FILES变量,所以相对来说,移值到BAE上面的项目其实就只不过将数据库的配置改一下罢了。在正常情况下,因为没有办法使用install.php(主要是因为大部分的安装文件 都不允许你在form表单里输入常量,而只能是一个字符串)。

OK,下载原版的typecho ,然后在本地安装一下。将config.inc.php中的数据库配置调整一下。改为线上配置

同时将你的mysql导出,到线上去的phpmyadmin里执行一下。

整个世界就清静多了。

如果你觉得我说的太简单,或者你觉得太麻烦,不想先在本地安装,你可以参考这个:http://mrasong.com/item/typecho-for-bae.html,注意文章的最后有一段不要忘了,就是它的密码。。。。。否则你会发现你没办法登录。

---
BAE有另一个很严重的问题,那就是我之前说的$_FILES可以直接使用,同时可以直接将文件上传在项目目录下,但这部分代码是不受控制的。很让人麻烦。

typecho也能够在线修改模版文件 ,即这些修改的文件,又不在代码控制的范围了。。。
---有时候我不知道BAE究竟是什么,只是一个虚拟空间吗?或许我这样理解,就不会有感慨 了。。

phing的配置文件

phing的配置文件

官网上有一份phing的基本配置文件,网上又找了一份比较复杂的,根据自己的项目对比一下喽

官网配置文件:
<?xml version="1.0" encoding="UTF-8"?>

<project name="FooBar" default="dist">

<!-- ============================================ -->
<!-- Target: prepare -->
<!-- ============================================ -->
<target name="prepare">
<echo msg="Making directory ./build" />
<mkdir dir="./build" />
</target>

<!-- ============================================ -->
<!-- Target: build -->
<!-- ============================================ -->
<target name="build" depends="prepare">
<echo msg="Copying files to build directory..." />

<echo msg="Copying ./about.php to ./build directory..." />
<copy file="./about.php" tofile="./build/about.php" />

<echo msg="Copying ./browsers.php to ./build directory..." />
<copy file="./browsers.php" tofile="./build/browsers.php" />

<echo msg="Copying ./contact.php to ./build directory..." />
<copy file="./contact.php" tofile="./build/contact.php" />
</target>

<!-- ============================================ -->
<!-- (DEFAULT) Target: dist -->
<!-- ============================================ -->
<target name="dist" depends="build">
<echo msg="Creating archive..." />

<tar destfile="./build/build.tar.gz" compression="gzip">
<fileset dir="./build">
<include name="*" />
</fileset>
</tar>

<echo msg="Files copied and compressed in build directory OK!" />
</target>
</project>
第三方配置文件 :
<?xml version="1.0" encoding="UTF-8"?>

<project name="ucenter" default="deploy">

<!-- Target: config 设置变量,控制部署到不同环境-->
<target name="config">
<property name="svn_user" value="leric" />
<property name="svn_pass" value="" />
<input propertyname="deploy_env">Deploy to Env(prod|test):</input>
<if>
<equals arg1="${deploy_env}" arg2="prod" />
<then>
<property name="project_home" value="/opt/www/ucenter" />
<property name="web_servers" value="www.ucenter.com,www2.ucenter.com" />
<property name="web_server_user" value="leric" />
<property name="web_server_pass" value="leric" />
</then>
</if>
<if>
<equals arg1="${deploy_env}" arg2="test" />
<then>
<property name="project_home" value="/opt/www/ucenter" />
<property name="web_servers" value="127.0.0.1" />
<property name="web_server_user" value="root" />
<property name="web_server_pass" value="123456" />
</then>
</if>
</target>

<!-- Target: build Checkout from svn, and make tar.gz -->
<target name="build" depends="config">
<echo msg="Export code from svn..." />
<input propertyname="export_revision">Revision to export from svn:</input>
<svnupdate
svnpath="svn"
revision="${export_revision}"
username="${svn_user}" password="${svn_pass}"
nocache="true"
todir="./"/>

<echo msg="Creating archive..." />
<delete file="./dist.tar.gz" />
<tar destfile="./dist.tar.gz" compression="gzip" prefix="rev_${export_revision}">
<fileset dir="./" defaultexcludes="true">
<include name="**" />
<exclude name="**/.svn" />
</fileset>
</tar>
</target>

<!-- Target: deploy Upload tar.gz, switch to uploaded revision -->
<target name="deploy" depends="config,build">
<foreach list="${web_servers}" param="web_server" target="deploy_one" />
</target>
<target name="deploy_one">
<scp username="${web_server_user}" password="${web_server_pass}"
host="${web_server}" todir="${project_home}/revs"
file="./dist.tar.gz" />

<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="cd ${project_home}/revs; tar zxf dist.tar.gz; rm dist.tar.gz;" />

<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="rm -f ${project_home}/current; ln -s ${project_home}/revs/rev_${export_revision} ${project_home}/current" />
</target>

<!-- Target: switch Switch current revision -->
<target name="switch" depends="config">
<foreach list="${web_servers}" param="web_server" target="switch_one" />
</target>
<target name="switch_one">
<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="ls -al ${project_home}/revs" />
<input propertyname="revision">Revision to set as active:</input>
<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="rm -f ${project_home}/current; ln -s ${project_home}/revs/rev_${revision} ${project_home}/current" />
</target>


<!-- Target: update_deps Update server setting by execute scripts(database, crontab, restart service, etc.) -->
<target name="update_deps" depends="config">
<foreach list="${web_servers}" param="web_server" target="update_deps_one" />
</target>
<target name="update_deps_one">
<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="cd ${project_home}/current; sudo cp crontab /etc/cron.d/ucenter" />
<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="cd ${project_home}/current; php app/scripts/migration.php" />
<input propertyname="confirm_sql">Confirm database migration sql script(yes|no):</input>
<if>
<equals arg1="${confirm_sql}" arg2="yes" />
<then>
<ssh username="${web_server_user}" password="${web_server_pass}"
host="${web_server}"
command="cd ${project_home}/current; php app/scripts/migration.php execute" />
</then>
</if>
</target>
</project>
详细的文档还是看官方吧:http://www.phing.info/trac/wiki/Users/Documentation,我目前是在利用phpstorm的phing进行测试,但事实上还不如直接用命令行罢了,自从phpstorm升到6之后,对于一些可执行文件都开始用phar进行封装了。这是一件好事。
为了更好的使用phing,还是需要把文档看完的:http://www.phing.info/docs/guide/stable/,事实上phing在几年前就准备开始尝试了,但最终都没有正式在项目里使用。为了以后更好的管理和发布项目,想了想,还是先试一下。
事实上,我是想将一份代码分发到N台服务器,所以我最近在做不停的尝试。。。也考虑过用git进行分发,只是还没有开始罢了。估计下一步就会用git进行测试了
淘宝客程序中获取图片尺寸

淘宝客程序中获取图片尺寸

在sablog上看到淘宝客图片的尺寸,还有,在各种各样的网站上都看到了一些尺寸,其实,这些都是大家在摸索

然而,官方早就有了文档,只是我们没有看到罢了。比如在这里:http://www.taobao.com/market/market/mobile/yuanjin.php?spm=0.0.0.0.Zz1B0Y,点击【获取图片】,你会发现,原来官方提供了N个尺寸,
淘宝后台的图片尺寸规格如下:
ZoomAddType _80x40.jpg 84(代表相素为80*40)以下类似
ZoomAddType _60x30.jpg 63
ZoomAddType _300.jpg 300
ZoomAddType _81x65.jpg 81 65
ZoomAddType _110x90.jpg 110 90
ZoomAddType _24x24.jpg 24
ZoomAddType _30x30.jpg 30
ZoomAddType _40x40.jpg 40
ZoomAddType _60x60.jpg 60
ZoomAddType _70x70.jpg 70
ZoomAddType _80x80.jpg 80
ZoomAddType _100x100.jpg 100
ZoomAddType _110x110.jpg 110
ZoomAddType _120x120.jpg 120
ZoomAddType _160x160.jpg 160
ZoomAddType _170x170.jpg 170
ZoomAddType _250x250.jpg 250
ZoomAddType _310x310.jpg 310
ZoomAddType _670x670.jpg 670
ZoomAddType _620x10000.jpg 620 10000
这时候,你是什么情况?有没有和你的小伙伴一样都惊呆了?嗯,我在网上看到的这些:
缩图常见尺寸:

_40x40.jpg
_70x70.jpg
_100×100.jpg
_120x120.jpg
_160x160.jpg
_320x320.jpg
_480x480.jpg
_600x600.jpg
_sum.jpg(缩略图专用,其实是80x80)
_b.jpg(大图专用,220x220)
和上面的尺寸不太一样,不过也差不多了,做一个merge吧。
获取淘宝图片的方法如下:
不算太复杂吧?