osCommerce添加无属性虚拟商品出错的解决办法
在osCommerce添加无属性虚拟商品时,系统会自动默认该商品为真实商品。
其原因很简单,在shopping_cart类中,get_content_type()函数会依据类中的每个商品的product_id,在TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD表中查找,如果找到相当于的记录,则该商品被判断为虚拟商品,但是这个仅仅针对有属性的商品。如果想添加无属性虚拟商品,请做以下修改:
1、在文件catalog/includes/classes/shopping_cart.php中,找到函数get_content_type()。
2、找到isset($this->contents[$products_id]['attributes'])的else部分,用以下代码替换else内的代码:
$virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.products_attributes_id = pad.products_attributes_id");
$virtual_check = tep_db_fetch_array($virtual_check_query);
if ($virtual_check['total'] > 0) {
switch ($this->content_type) {
case 'physical':
$this->content_type = 'mixed';
return $this->content_type;
break;
default:
$this->content_type = 'virtual';
break;
}
} else {
switch ($this->content_type) {
case 'virtual':
$this->content_type = 'mixed';
return $this->content_type;
break;
default:
$this->content_type = 'physical';
break;
}
}