Principle: Extract the inventory of each attribute from the database, put it into a function, and then call it out using a template.
Files that need to be modified:
1. Theme template goods.dwt
2. lib_goods.php under includes
Step 1.
Modify goods.dwt
在294行左右, 和 之间,增加(库存:{$value.product_number} {$goods.measure_unit})
Step 2.
Modify lib_goods.php under includes.
In line 625, /* Get product specifications */, modify it as follows: The red part is the added call.
$sql = “SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type, “.
"g.goods_attr_id, g.attr_value, g.attr_price". ",p.product_sn,p.product_number".
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods_attr’) . ‘ AS g ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘attribute’) . ‘ AS a ON a.attr_id = g.attr_id ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘products’) . ‘ AS p ON g.goods_attr_id = p.goods_attr ‘ .
“WHERE g.goods_id = ‘$goods_id’ ” .
‘ORDER BY a.sort_order, g.attr_price, g.goods_attr_id’;
$res = $GLOBALS[‘db’]->getAll($sql);$arr['pro'] = array(); // Attribute
$arr['spe'] = array(); // Specification
$arr['lnk'] = array(); // Associated propertiesforeach ($res AS $row)
{
$row[‘attr_value’] = str_replace(“\n”, ‘
’, $row[‘attr_value’]);if ($row[‘attr_type’] == 0)
{
$group = (isset($groups[$row[‘attr_group’]])) ? $groups[$row[‘attr_group’]] : $GLOBALS[‘_LANG’][‘goods_attr’];$arr[‘pro’][$group][$row[‘attr_id’]][‘name’] = $row[‘attr_name’];
$arr[‘pro’][$group][$row[‘attr_id’]][‘value’] = $row[‘attr_value’];
}
else
{
$arr[‘spe’][$row[‘attr_id’]][‘attr_type’] = $row[‘attr_type’];
$arr[‘spe’][$row[‘attr_id’]][‘name’] = $row[‘attr_name’];
$arr[‘spe’][$row[‘attr_id’]][‘values’][] = array(
‘label’ => $row[‘attr_value’],
‘price’ => $row[‘attr_price’],
‘format_price’ => price_format(abs($row[‘attr_price’]), false),
‘id’ => $row[‘goods_attr_id’],
‘product_sn’ => $row[“product_sn”],
‘product_number’ => $row[“product_number”]);
}
This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:
Original author:Jake Tao,source:"Get Inventory for Each Attribute in Ecshop - Applicable to All Versions"