Magento产物添加了个自界说属性Free Shipping(免运费)。要实现当Free shipping属性的值为YES的时候,自动把产物指定到一个叫Free Shipping的目次。
前台还可以处理惩罚下,使有这属性值的产物添加标识条幅。如图,结果照旧挺惹人喜的。
我的处理惩罚步伐是,重写app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php这个文件。
在_initProductSave要领里的
/*** Initialize product categories
*/
这个步调添加特别处理惩罚。
完整代码为:
// addEd at: 10:20 2011/7/30 by chen@sjolzy.cn/*
$productData['free_shipping']: 21 yes 20 no
Free Shipping Specials category id: 31
*/
$ifFreeShipping = (int)$productData['free_shipping']===21?true:false;
$freeShippingCategoryId = 31;
// addEd at: 10:20 2011/7/30 by chen@sjolzy.cn
if (null !== $categoryIds) {
if (empty($categoryIds)) {
$categoryIds = $ifFreeShipping?$freeShippingCategoryId:array();
}else{
$categoryIds = explode(',',$categoryIds);
$categoryIds = $this->freeShippingCategoryIdProcess($freeShippingCategoryId,$ifFreeShipping,$categoryIds);
}
$product->setCategoryIds($categoryIds);
}else{ // addEd at: 10:20 2011/7/30 by chen@sjolzy.cn
$categoryIds = Mage::getResourceSingleton('catalog/product')->getCategoryIds($product);
if($categoryIds){
$categoryIds = is_array($categoryIds)?$categoryIds:array($categoryIds);
$categoryIds = $this->freeShippingCategoryIdProcess($freeShippingCategoryId,$ifFreeShipping,$categoryIds);
$product->setCategoryIds($categoryIds);
}
} // addEd at: 10:20 2011/7/30 by chen@sjolzy.cn
别的添加的freeShippingCategoryIdProcess要领是
protected function freeShippingCategoryIdProcess($freeShippingCategoryId,$ifFreeShipping,$categoryIds){if(!$ifFreeShipping){
$k = array_search($freeShippingCategoryId,$categoryIds);
if(false!==$k){
unset($categoryIds[$k]);
}
}else{
$categoryIds[] = $freeShippingCategoryId;
}
return implode(',',$categoryIds);
}
颠末测试,到达预期结果,产物配置YES后自动添加到free shipping的目次,配置No之后再打消。
magento下载magento开源电子商务平台 v1.5.1.0 多国语言版下载