原理:从ecshop数据库提取各个属性的库存,放到一个函数里,然后用模板调用出来。 需要修改的ecshop文件: 1.主题模板goods.dwt 2.includes下的lib_goods.php Step 1. 修改goods.dwt 在294行左右,原理:从ecshop数据库提取各个属性的库存,放到一个函数里,然后用模板调用出来。
需要修改的ecshop文件:
1.主题模板goods.dwt
2.includes下的lib_goods.php
Step 1.
修改goods.dwt
在294行左右, <!– {foreach from=$spec.values item=value key=key} –>和 <!– {/foreach} –>之间,增加(库存:{$value.product_number} {$goods.measure_unit})
Step 2.
修改includes下的lib_goods.php
在625行/* 获得商品的规格 */中,修改成如下样子:红色部分是增加的调用
$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(); // 属性
$arr[‘spe’] = array(); // 规格
$arr[‘lnk’] = array(); // 关联的属性foreach ($res AS $row)
{
$row[‘attr_value’] = str_replace(“\n”, ‘<br />’, $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”]);
}
获取Ecshop各个属性的库存的简单方法
相关推荐
- ThinkPHP5中find()和select()区别 - 范仁义 - 博客园
- 深入理解 PHP 高性能框架 Workerman 守护进程原理 - Yxh_blogs - 博客园
- 【干货】ThinkPHP6对接微信扫码登录_thinkphp6 微信扫码登陆-CSDN博客
- 报错 General error: 1366 Incorrect string value: ‘\xF0\x9F\x8D\x83‘ for column ‘per_name‘ at row 1-CSDN博客
- WP精仿小刀娱乐网源码整套 带翻页和手机版并有3000+文章-壹软资源网
- php防sql注入过滤代码 - 搬砖小伙子 - 博客园
- 如何解决Namespace declaration statement has to be the very first statement or after any declare call-CSDN博客
- ThinkPHP 页面跳转和重定向_thinkphp $this->success 重定向到指定页面-CSDN博客