linux下计划任务cron配置

crond服务操作命令:

/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置

配置定时任务:

cron有两个配置文件,一个是一个全局配置文件(/etc/crontab),是针对系统任务的;一组是crontab命令生成的配置文件(/var/spool/cron下的文件),是针对某个用户的.定时任务配置到任意一个中都可以。

查看全局配置文件配置情况: cat /etc/crontab

———————————————
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
———————————————-

查看用户下的定时任务:crontab -l或cat /var/spool/cron/用户名

crontab任务配置基本格式:
*   *  *  *  *  command
分钟(0-59) 小时(0-23) 日期(1-31) 月份(1-12) 星期(0-6,0代表星期天)  命令

第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

配置用户定时任务的语法:

crontab [-u user]file

crontab [-u user] [-l| -r | -e][-i]

参数与说明:

crontab -u//设定某个用户的cron服务

crontab -l//列出某个用户cron服务的详细内容

crontab -r//删除没个用户的cron服务

crontab -e//编辑某个用户的cron服务

crontab -u user -e编辑某个用户的cron任务

cat /var/log/cron 查看cron日志

Magento获取产品ID,根据ID获取产品信息

Magento获取产品ID,根据ID获取产品信息,如果想在产品页面的其他相关页面,比如左侧、头部、底部获取产品的信息:
如果知道ID是最好的,但是不知道的情况下,我们可以先获取当前产品id

$product_id = Mage::registry(‘current_product’)->getId();
$_product = Mage::getModel(‘catalog/product’)->load($product_id);

可以先判断是否为产品页面

if (Mage::registry(‘product’)){/**/}//先获取是否为产品页面

然后直接获取产品相关信息

echo $_product->getShortDescription(); //product’s short description
echo $_product->getDescription(); // product’s long description
echo $_product->getName(); //product name
echo $_product->getPrice(); //product’s regular Price
echo $_product->getSpecialPrice(); //product’s special Price
echo $_product->getProductUrl(); //product url
echo $_product->getImageUrl(); //product’s image url
echo $_product->getSmallImageUrl(); //product’s small image url
echo $_product->getThumbnailUrl(); //product’s thumbnail image url

超级有用的PHP代码片段-四个

分享九个超级有用的PHP代码片段。当你在开发网站、应用或者博客时,利用这些代码能为你节省大量的时间。

一、查看邮件是否已被阅读

当你在发送邮件时,你或许很想知道该邮件是否被对方已阅读。这里有段非常有趣的代码片段能够显示对方IP地址记录阅读的实际日期和时间。
<?
error_reporting(0);
Header(“Content-Type: image/jpeg”);

//Get IP
if (!empty($_SERVER[‘HTTP_CLIENT_IP’]))
{
$ip=$_SERVER[‘HTTP_CLIENT_IP’];
}
elseif (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’]))
{
$ip=$_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
else
{
$ip=$_SERVER[‘REMOTE_ADDR’];
}

//Time
$actual_time = time();
$actual_day = date(‘Y.m.d’, $actual_time);
$actual_day_chart = date(‘d/m/y’, $actual_time);
$actual_hour = date(‘H:i:s’, $actual_time);

//GET Browser
$browser = $_SERVER[‘HTTP_USER_AGENT’];

//LOG
$myFile = “log.txt”;
$fh = fopen($myFile, ‘a+’);
$stringData = $actual_day . ‘ ‘ . $actual_hour . ‘ ‘ . $ip . ‘ ‘ . $browser . ‘ ‘ . “\r\n”;
fwrite($fh, $stringData);
fclose($fh);

//Generate Image (Es. dimesion is 1×1)
$newimage = ImageCreate(1,1);
$grigio = ImageColorAllocate($newimage,255,255,255);
ImageJPEG($newimage);
ImageDestroy($newimage);

?>

二、从网页中提取关键字

一段伟大的代码片段能够轻松的从网页中提取关键字。
$meta = get_meta_tags(‘http://www.emoticode.net/’);
$keywords = $meta[‘keywords’];
// Split keywords
$keywords = explode(‘,’, $keywords );
// Trim them
$keywords = array_map( ‘trim’, $keywords );
// Remove empty values
$keywords = array_filter( $keywords );

print_r( $keywords );

三、查找页面上的所有链接

使用DOM,你可以轻松从任何页面上抓取链接,代码示例如下:

$html = file_get_contents(‘http://www.php100.com’);

$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate(“/html/body//a”);

for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute(‘href’);
echo $url.'<br />’;
}

四、自动转换URL,跳转至超链接

在WordPress中,如果你想自动转换URL,跳转至超链接页面,你可以利用内置的函数make_clickable()执行此操作。如果你想基于WordPress之外操作该程序,那么你可以参考wp-includes/formatting.php源代码。

function _make_url_clickable_cb($matches) {
$ret = ”;
$url = $matches[2];

if ( empty($url) )
return $matches[0];
// removed trailing [.,;:] from URL
if ( in_array(substr($url, -1), array(‘.’, ‘,’, ‘;’, ‘:’)) === true ) {
$ret = substr($url, -1);
$url = substr($url, 0, strlen($url)-1);
}
return $matches[1] . “<a href=\”$url\” rel=\”nofollow\”>$url</a>” . $ret;
}

function _make_web_ftp_clickable_cb($matches) {
$ret = ”;
$dest = $matches[2];
$dest = ‘http://’ . $dest;

if ( empty($dest) )
return $matches[0];
// removed trailing [,;:] from URL
if ( in_array(substr($dest, -1), array(‘.’, ‘,’, ‘;’, ‘:’)) === true ) {
$ret = substr($dest, -1);
$dest = substr($dest, 0, strlen($dest)-1);
}
return $matches[1] . “<a href=\”$dest\” rel=\”nofollow\”>$dest</a>” . $ret;
}

function _make_email_clickable_cb($matches) {
$email = $matches[2] . ‘@’ . $matches[3];
return $matches[1] . “<a href=\”mailto:$email\”>$email</a>”;
}

function make_clickable($ret) {
$ret = ‘ ‘ . $ret;
// in testing, using arrays here was found to be faster
$ret = preg_replace_callback(‘#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is’, ‘_make_url_clickable_cb’, $ret);
$ret = preg_replace_callback(‘#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is’, ‘_make_web_ftp_clickable_cb’, $ret);
$ret = preg_replace_callback(‘#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i’, ‘_make_email_clickable_cb’, $ret);

// this one is not in an array because we need it to run last, for cleanup of accidental links within links
$ret = preg_replace(“#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i”, “$1$3</a>”, $ret);
$ret = trim($ret);
return $ret;
}

 

英文出自: Catswhocode

PHP图片裁剪、缩放函数

根据自定义的目标图高宽, 按目标图高宽比裁剪、缩放源图.

传入参数:
$source_path string 源图路径
$target_width integer 目标图宽度
$target_height integer 目标图高度

源图支持MIMETYPE: image/gif, image/jpeg, image/png.

function imagecropper($source_path, $target_width, $target_height)
{
	$source_info   = getimagesize($source_path);
	$source_width  = $source_info[0];
	$source_height = $source_info[1];
	$source_mime   = $source_info['mime'];
	$source_ratio  = $source_height / $source_width;
	$target_ratio  = $target_height / $target_width;

	// 源图过高
	if ($source_ratio > $target_ratio)
	{
		$cropped_width  = $source_width;
		$cropped_height = $source_width * $target_ratio;
		$source_x = 0;
		$source_y = ($source_height - $cropped_height) / 2;
	}
	// 源图过宽
	elseif ($source_ratio < $target_ratio)
	{
		$cropped_width  = $source_height / $target_ratio;
		$cropped_height = $source_height;
		$source_x = ($source_width - $cropped_width) / 2;
		$source_y = 0;
	}
	// 源图适中
	else
	{
		$cropped_width  = $source_width;
		$cropped_height = $source_height;
		$source_x = 0;
		$source_y = 0;
	}

	switch ($source_mime)
	{
		case 'image/gif':
			$source_image = imagecreatefromgif($source_path);
			break;

		case 'image/jpeg':
			$source_image = imagecreatefromjpeg($source_path);
			break;

		case 'image/png':
			$source_image = imagecreatefrompng($source_path);
			break;

		default:
			return false;
			break;
	}

	$target_image  = imagecreatetruecolor($target_width, $target_height);
	$cropped_image = imagecreatetruecolor($cropped_width, $cropped_height);

	// 裁剪
	imagecopy($cropped_image, $source_image, 0, 0, $source_x, $source_y, $cropped_width, $cropped_height); 
	// 缩放
	imagecopyresampled($target_image, $cropped_image, 0, 0, 0, 0, $target_width, $target_height, $cropped_width, $cropped_height);

	header('Content-Type: image/jpeg');
	imagejpeg($target_image);
	imagedestroy($source_image);
	imagedestroy($target_image);
	imagedestroy($cropped_image);
===========================================================
       保存在本地可以使用
    //header('Content-Type: image/jpeg');
    $name=$target_width.'x'.$target_height.time().'.jpg';
    imagejpeg($target_image,$name);
    echo 'OK';

}

原文地址: http://www.php100.com/html/php/hanshu/2013/1025/6320.html

Magento一些实用插件,Magento常用插件整理

Magento一些实用插件,Magento常用插件整理:挺有用的

53. 全页缓存插件
一:Lesti::Fpc
URL:http://www.magentocommerce.com/magento-connect/lesti-fpc-4534.html
KEY:http://connect20.magentocommerce.com/community/Lesti_Fpc

52. Magento 价格小数位管理
一:Price Layout Extension
URL:http://www.magentocommerce.com/magento-connect/price-layout-extension.html
KEY1:magento-community/wp_price_decimal
KEY2:http://connect20.magentocommerce.com/community/wp_price_decimal
二:ET Currency Manager
URL:http://www.magentocommerce.com/magento-connect/et-currency-manager.html
KEY1:magento-community/ET_CurrencyManager
KEy2:http://connect20.magentocommerce.com/community/ET_CurrencyManager

51. 丰富网页内容(与36同类型)
URL:http://www.magentocommerce.com/magento-connect/msemantic-semantic-seo-for-rich-snippets-in-google-and-yahoo.html
KEY1:magento-community/Semantium_MSemanticBasic
KEY2:http://connect20.magentocommerce.com/community/Semantium_MSemanticBasic

50. 漂亮左侧菜单导航
URL:http://www.magentocommerce.com/magento-connect/mtoo-advance-left-vertical-navigation-with-nice-css-design-6858.html
KEY:http://connect20.magentocommerce.com/community/Advance_Left_Vertical_Navigation

49. 属性组切换插件
URL:http://www.magentocommerce.com/magento-connect/flagbit-change-attribute-set.html
KEY1:magento-community/Flagbit_ChangeAttributeSet
KEY2:http://connect20.magentocommerce.com/community/Flagbit_ChangeAttributeSet

48. A-Z 排序插件 for 1.3_1.4
URL:http://www.magentocommerce.com/magento-connect/alphabates.html
KEY:magento-community/alphabates

47. 清理无用图片
URL:http://www.magentocommerce.com/magento-connect/image-clean.html
KEY2:http://connect20.magentocommerce.com/community/Mage_Imaclean

46. 广告推荐热卖产品
URL:http://www.magentocommerce.com/magento-connect/catalog/product/view/id/14745/s/advertise-upsell-products-5581/
KEY2:http://connect20.magentocommerce.com/community/AdvertiseUpsellProducts

45. 广告推荐产品(自动关联相关、交叉、热卖产品)
URL:http://www.magentocommerce.com/magento-connect/catalog/product/view/id/14924/s/advertise-suggested-products-2487/
KEY2:http://connect20.magentocommerce.com/community/AdvertiseSuggestedProducts

44. Facebook Store 插件
URL:http://www.magentocommerce.com/magento-connect/facebook-products-tab.html
KEY1:magento-community/Facebook_Products_Tab
KEY2:http://connect20.magentocommerce.com/community/Facebook_Products_Tab

43. 快速购物
URL1:http://www.magentocommerce.com/magento-connect/quickview-7580.html
KEY1:magento-community/Quickview
KEY2:http://connect20.magentocommerce.com/community/Quickview

URL2:http://www.magentocommerce.com/magento-connect/em-quick-shop-quick-view-product.html
KEY1:magento-community/EM_Quickshop
KEY2:http://connect20.magentocommerce.com/community/EM_Quickshop

42. 搜索结果预览
URL:http://www.magentocommerce.com/magento-connect/search-autocomplete-8858.html
KEY1:magento-community/Searchautocomplete
KEY2:http://connect20.magentocommerce.com/community/Searchautocomplete

41. 自定义属性复制
URL:http://www.magentocommerce.com/magento-connect/custom-options-replicator.html
KEY2:http://connect20.magentocommerce.com/community/ZetaPrints_Options

40. Enhanced Admin Product Grid 增强产品管理
URL:http://www.magentocommerce.com/magento-connect/enhanced-admin-product-grid.html
KEY1:magento-community/TBT_Enhancedgrid
KEY2:http://connect20.magentocommerce.com/community/TBT_Enhancedgrid
附:插件设置的页面404错误修复
app/code/community/TBT/Enhancedgrid/Model/System/Config/Source/Columns/Show.php
第 10 行,将 “->addVisibleFilter();” 换成 “->addFilter(“is_visible”, 1);”

39. 客户反馈
URL:http://www.magentocommerce.com/magento-connect/feedback-1959.html
KEY1:magento-community/bc_feedback
KEY2:http://connect20.magentocommerce.com/community/bc_feedback

38. 单页结账
URL:http://www.magentocommerce.com/magento-connect/iwd-free-one-page-step-checkout-6454.html
KEY2:http://connect20.magentocommerce.com/community/1213

37. ASchroder SMTP Pro
URL:http://www.magentocommerce.com/magento-connect/aschroder-com-smtp- pro-email-free-and-easy-magento-emailing-for-smtp-gmail-or-google-apps-email.html
KEY1:magento-community/ASchroder_SMTPPro
KEY2:http://connect20.magentocommerce.com/community/ASchroder_SMTPPro

36. Google 产品微标记
URL:http://www.magentocommerce.com/magento-connect/ayaline-rich-snippets-1339.html
KEY1:magento-community/Ayaline_RichSnippets
KEY2:http://connect20.magentocommerce.com/community/Ayaline_RichSnippets

35. 支付方式过滤
URL:http://www.magentocommerce.com/magento-connect/paymentfilter-for-products-and-customer-groups.html
KEY1:magento-community/RicoNeitzel_PaymentFilter
KEY2:http://connect20.magentocommerce.com/community/RicoNeitzel_PaymentFilter

34. 属性选项导入插件
URL:http://www.magentocommerce.com/magento-connect/attribute-options-add-6435.html
KEY:http://connect20.magentocommerce.com/community/Tds_Attributeoptionupdate

33. 分类访问控制
URL:http://www.magentocommerce.com/magento-connect/category-access-control.html
KEY1:magento-community/category_access_control
KEY2:http://connect20.magentocommerce.com/community/category_access_control
卸载需要运行:
DELETE FROM `eav_attribute` WHERE attribute_code LIKE ‘accesscontrol_show_group%’;
DELETE FROM `core_resource` WHERE code=’accesscontrol_setup’;

32. 邮件订阅分组
URL:http://www.magentocommerce.com/magento-connect/newsletter-groups-8781.html
KEY1:magento-community/Fsite_NewsletterGroup
KEY2:http://connect20.magentocommerce.com/community/Fsite_NewsletterGroup

31. 分享优惠
URL:http://www.magentocommerce.com/magento-connect/social-power-share.html
KEY1:magento-community/Social_Power_Share
KEY2:http://connect20.magentocommerce.com/community/Social_Power_Share

30. 访问最多的产品
URL:http://www.magentocommerce.com/magento-connect/product-slider-9077.html
KEY1:magento-community/BP_Mostviewed
KEY2:http://connect20.magentocommerce.com/community/BP_Mostviewed

29. 清理 Magento
URL:http://www.magentocommerce.com/magento-connect/magentoo-magentools.html
KEY:magento-community/Magentoo_Magentools

28. 验证码插件
URL:http://www.magentocommerce.com/magento-connect/outsourceonline-captcha-6034.html
KEY1:magento-community/OutsourceOnline_Captcha
KEy2:http://connect20.magentocommerce.com/community/OutsourceOnline_Captcha
另外一个
URL:http://www.magentocommerce.com/magento-connect/i95dev-captcha.html

27. 特价倒计时
URL:http://www.magentocommerce.com/magento-connect/price-countdown.html
KEY1:magento-community/Price_Countdown
KEY2:http://connect20.magentocommerce.com/community/Price_Countdown

26. Groups Catalog 隐藏分类和产品 (1.4 – 1.5 -1.6 )
1.4-1.5
URL:http://www.magentocommerce.com/magento-connect/netzarbeiter-groupscatalog.html
KEY1:magento-community/Netzarbeiter_GroupsCatalog
KEY2:http://connect20.magentocommerce.com/community/Netzarbeiter_GroupsCatalog
1.6
URL:http://www.magentocommerce.com/magento-connect/customer-groups-catalog2-4585.html
URL2:http://connect20.magentocommerce.com/community/Netzarbeiter_GroupsCatalog2

25. 订单咨询插件
URL:http://www.magentocommerce.com/magento-connect/site-management/customer-service/order-tickets.html
KEY1:magento-community/Order_tickets
KEY2:http://connect20.magentocommerce.com/community/Order_tickets

24. 给“联系我们”页添加一个调查表单
URL:http://www.magentocommerce.com/magento-connect/site-management/customer-service/webforms-community-edition.html
KEY1:magento-community/WebForms
KEY2:http://connect20.magentocommerce.com/community/WebForms

23. 首页产品
URL:http://www.magentocommerce.com/magento-connect/homesellers-5in1-free.html
KEY1:magento-community/Magazento_Homesellers
KEY2:http://connect20.magentocommerce.com/community/Magazento_Homesellers

22. 热卖产品插件
URL:http://www.magentocommerce.com/magento-connect/easy-topsellers-free.html
KEY1:magento-community/Easy_Topsellers
KEY2:http://connect20.magentocommerce.com/community/Easy_Topsellers
URL2:http://www.magentocommerce.com/magento-connect/bestseller-products-7401.html
URL3:http://www.magentocommerce.com/magento-connect/vs-bestseller-7235.html
URL4:http://www.magentocommerce.com/magento-connect/votum-bestseller.html
URL5:http://www.magentocommerce.com/magento-connect/jextn-bestselling-products-1455.html
URL6:http://www.magentocommerce.com/magento-connect/catalog/product/view/id/13946/s/custom-listings-7646/
URL7:http://www.magentocommerce.com/magento-connect/catalog/product/view/id/14095/s/product-slider-9572/
URL8:http://www.magentocommerce.com/magento-connect/catalog/product/view /id/13827/s/magento-mostviewed-mostpopular-products-free-7566/

21. 西联支付插件
URL:http://www.magentocommerce.com/magento-connect/atwix-western-union-payment-method.html
KEY2:http://connect20.magentocommerce.com/community/Atwix_Western_Union_Payment_Method
KEY1:magento-community/Atwix_Western_Union_Payment_Method

20. 给品牌属性添加图片
URL:http://www.magentocommerce.com/magento-connect/manufacturer-1679.html
KEY:http://connect20.magentocommerce.com/community/manufacturer-community

19. 给联系我们添加附件
URL:http://www.magentocommerce.com/magento-connect/contact-form-attachment-7158.html
KEY:http://connect20.magentocommerce.com/community/ContactFormAttachment

18. 完美图片形象
URL:http://www.magentocommerce.com/magento-connect/picture-perfect-mass-product-image-uploader-6636.html
KEY:http://connect20.magentocommerce.com/community/pictureperfect_wexo

17. 图片显示库存状态
URL:http://www.magentocommerce.com/magento-connect/xogenics-stock-status-images.html
KEY1:magento-community/Xogenics_StockStatusImages
KEY2:http://connect20.magentocommerce.com/community/Xogenics_StockStatusImages

16. 运费规则管理
URL:http://www.magentocommerce.com/magento-connect/shipping-table-rates.html
KEY:http://connect20.magentocommerce.com/community/ShippingTablerate

15. 侧边栏显示评论(插件两个)
URL:http://www.magentocommerce.com/magento-connect/reviews-sidebar.html
KEY1:magento-community/Reviews_Sidebar
KEY2:http://connect20.magentocommerce.com/community/Reviews_Sidebar
URL:http://www.magentocommerce.com/magento-connect/vs-sidebarreview.html
KEY1:magento-community/VS_Sidebarreview
KEY2:http://connect20.magentocommerce.com/community/VS_Sidebarreview

14. 产品附件
URL:http://www.magentocommerce.com/magento-connect/product-attachments-extension.html
KEY1:magento-community/ProductAttachments_Module
KEY2:http://connect20.magentocommerce.com/community/ProductAttachments_Module

13. 更加友好的图片名称
URL:http://www.magentocommerce.com/magento-connect/netzarbeiter-nicerimagenames.html
KEY:http://connect20.magentocommerce.com/community/Netzarbeiter_NicerImageNames

12. 迷你弹窗登陆
URL:http://www.magentocommerce.com/magento-connect/giko-ajaxlogin.html
KEY2:http://connect20.magentocommerce.com/community/Giko_AjaxLogin

11. 允许客户在产品页上传一个附件
URL:http://www.magentocommerce.com/magento-connect/dynamic-file-attachments.html
KEY:http://connect20.magentocommerce.com/community/ZetaPrints_Attachments

10. 自定义分层导航风格
URL:http://www.magentocommerce.com/magento-connect/custom-layered-navigation-style.html
KEY2:http://connect20.magentocommerce.com/community/Custom_Layered_Navigation
KEY1:magento-community/Custom_Layered_Navigation

9. 移动管理插件
URL:http://www.magentocommerce.com/magento-connect/customer-experience/mobile/mobileadmin-7554.html
KEY:http://connect20.magentocommerce.com/community/snm_mobileadminc

8. 关联产品管理 自动设置交叉、热卖、相关产品
URL:http://www.magentocommerce.com/magento-connect/related-proudcts-manager-7301.html
KEY:http://connect20.magentocommerce.com/community/CommerceStack_Recommender

7. 简单评论模板插件
URL: http://www.magentocommerce.com/magento-connect/site-management/order-management/easycomments-3534.html
KEY1:magento-community/EasyComments
KEY2:http://connect20.magentocommerce.com/community/EasyComments

6. 退货插件
URL:http://www.magentocommerce.com/magento-connect/site-management/order-management/returnslink-rma-2707.html
KEY2:http://connect20.magentocommerce.com/community/ReturnsLink

5. Magento 移动插件
URL:http://www.magentocommerce.com/magento-connect/magento-mobile-6497.html
KEY1:magento-core/Magento_Mobile
KEY2:http://connect20.magentocommerce.com/community/Magento_Mobile

4. Magento 博客插件
URL:http://www.magentocommerce.com/magento-connect/blog-community-edition.html
KEY1:magento-community/AW_Blog
KEY2:http://connect20.magentocommerce.com/community/AW_Blog

3. 自定项友好切换插件
URL:http://www.magentocommerce.com/magento-connect/gala-color-swatches-free-9787.html
KEY1:magento-community/Gala_Colorswatches
KEY2:http://connect20.magentocommerce.com/community/Gala_Colorswatches

2. 导入产品关联,交叉销售,热卖推荐关系 ( ERIC 分享 )
URL:http://www.magentocommerce.com/magento-connect/itib-mass-import-product-relations-upsell-and-cross-sell.html
KEY2: http://connect20.magentocommerce.com/community/ITIB_MassImportProductRelations
KEY1: magento-community/ITIB_MassImportProductRelations

1. 商品按库存排序
URL: http://www.magentocommerce.com/magento-connect/customer-experience/category-product-page-enhancements/sort-products-by-stock-status-9821.html
KEY2:http://connect20.magentocommerce.com/community/Rayfox_Catalog

编程的名言名句

下面是一些迄今为止最好的关于编程的名言名句。阅读它们时相信你会有几分愉悦,你可以在一些会谈场合引用它们,一定能为你的团队吸引到不少的好程序员。
UNIX很简单。但需要有一定天赋的人才能理解这种简单。
–Dennis Ritchie
软件在能够复用前必须先能用。
–Ralph Johnson
优秀的判断力来自经验,但经验来自于错误的判断。
–Fred Brooks
‘理论’是你知道是这样,但它却不好用。‘实践’是它很好用,但你不知道是为什么。程序员将理论和实践结合到一起:既不好用,也不知道是为什么。
–佚名
当你想在你的代码中找到一个错误时,这很难;当你认为你的代码是不会有错误时,这就更难了。
-Steve McConnell 《代码大全》
如果建筑工人盖房子的方式跟程序员写程序一样,那第一只飞来的啄木鸟就将毁掉人类文明。
-Gerald Weinberg
项目开发的六个阶段:
充满热情
醒悟
痛苦
找出罪魁祸首
惩罚无辜
褒奖闲人
–佚名
优秀的代码是它自己最好的文档。当你考虑要添加一个注释时,问问自己,“如何能改进这段代码,以让它不需要注释?”
-Steve McConnell 《代码大全》
我们这个世界的一个问题是,蠢人信誓旦旦,智人满腹狐疑。
–Bertrand Russell
无论在排练中演示是如何的顺利(高效),当面对真正的现场观众时,出现错误的可能性跟在场观看的人数成正比。
–佚名
罗马帝国崩溃的一个主要原因是,没有0,他们没有有效的方法表示他们的C程序成功的终止。
–Robert Firth
C程序员永远不会灭亡。他们只是cast成了void。
–佚名
如果debugging是一种消灭bug的过程,那编程就一定是把bug放进去的过程。
–Edsger Dijkstra
你要么要软件质量,要么要指针算法;两者不可兼得。
–(Bertrand Meyer)
(有思想的话…)
有两种方法能写出没有错误的程序;但只有第三种好用。
–Alan J. Perlis
用代码行数来测评软件开发进度,就相对于用重量来计算飞机建造进度。
–比尔-盖茨
最初的90%的代码用去了最初90%的开发时间。余下的10%的代码用掉另外90%的开发时间。
–Tom Cargill
程序员和上帝打赌要开发出更大更好——傻瓜都会用的软件。而上帝却总能创造出更大更傻的傻瓜。所以,上帝总能赢。
–Anon

Magento产品列表增加A-Z字母过滤功能

Magento如何将产品列表增加A-Z字母过滤功能,字母过滤对seo也有一定的帮助
首先把
app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php
复制到
app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

1

 

 

然后增加一个函数

01
02
03
04
05
06
07
08
09
10
public
function
str_replace_once(
$needle
, 
$replace
, 
$haystack
){
 
// Looks for the first occurence of $needle in $haystack
 
// and replaces it with $replace.
 
$pos
= 
strpos
(
$haystack
, 
$needle
);
 
if
(
$pos
=== false) {
 
// Nothing found
 
return
$haystack
;
 
}
 
return
substr_replace(
$haystack
, 
$replace
, 
$pos
, 
strlen
(
$needle
));
 
}

然后将以下函数换在如下代码

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
public
function
setCollection(
$collection
){
 
$this
->_collection = 
$collection
;
 
$this
->_collection->setCurPage(
$this
->getCurrentPage());
 
// we need to set pagination only if passed value integer and more that 0
 
$limit
= (int)
$this
->getLimit();
 
$postData
= ”;
 
if
(
$limit
) {
 
$this
->_collection->setPageSize(
$limit
);
 
}
 
if
(
$this
->getCurrentOrder()){
 
/////Alphabate search Code Start From here.
 
$postData
= Mage::app()->getRequest()->getParam(‘alpha’).’%';
 
$postData_all
= Mage::app()->getRequest()->getParam(‘alpha’);
 
if
(isset(
$postData_all
) && 
$postData_all
!= ” && trim(
$postData_all
) !=’ALL’){
 
$this
->_collection->setOrder(
$this
->getCurrentOrder(), 
$this
->getCurrentDirection())
 
->addAttributeToFilter(
array
(
array
(‘attribute’=>’name’, ‘like’=>
$postData
)  ));
 
}
else
{
 
$this
->_collection->setOrder(
$this
->getCurrentOrder(), 
$this
->getCurrentDirection());
 
}
////Code End
 
}
 
return
$this
;
 
}

在app/design/frontend/default/default/template/catalog/product/list/toolbar.phtml

尾部增加如下代码如可:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
<
div
>
 
<
p
>
 
<?
php
 
$
postData
= 
Mage
::app()->getRequest()->getParam(‘alpha’);
 
foreach ($search_array  as $search_array_value):
 
if (strstr( $this->helper(‘core/url’)->getCurrentUrl(), “?” )){
 
$final_Url =  $this->str_replace_once(‘&’,'?’,str_replace
 
(“?alpha=”.trim($postData['alpha']),”,str_replace($make_nbsp.
 
“alpha=”.trim($postData['alpha']),”,$this->helper(‘core/url’)->getCurrentUrl())));
 
}else{
 
$final_Url = str_replace(“?alpha=”.trim($postData['alpha']),”,
 
str_replace($make_nbsp.”alpha=”.trim($postData['alpha']),”,
 
$this->helper(‘core/url’)->getCurrentUrl()));    }?>
 
<
a
href=”<?php echo $final_Url.$make_nbsp.’alpha=’.$search_array_value;?>”
 
title=”<?
php
echo $_label ?>”><?
php
echo $search_array_value; ?></
a
>&nbsp;&nbsp;
 
<?
php
endforeach; ?>
 
</
p
>
 
</
div
>

好了,完成了Magento产品列表增加A-Z字母过滤功能.

转载自Magento • 解百纳