ECSHOP gets the top category id and name of the product on the product details page, ecshop top_PHP tutorial

WBOY
Release: 2016-07-13 10:23:45
Original
1035 people have browsed it

ECSHOP gets the top-level category id and name of the product on the product details page, ecshop top-level

is in the goods.php file,

Find $smarty->assign('goods', $goods);
Add the following code above it:

Method 1:

<span>$cat_arr</span> = get_parent_cats(<span>$goods</span>['cat_id'<span>]);
</span><span>foreach</span> (<span>$cat_arr</span> <span>AS</span> <span>$val</span><span>) <br />{
  </span><span>$goods</span>['topcat_id']=<span>$val</span>['cat_id'<span>];
</span><span>  $goods</span>['topcat_name']=<span>$val</span>['cat_name'<span>];
}</span>
Copy after login

Method 2:

<span>$cat_arr</span> = get_parent_cats(<span>$goods</span>['cat_id'<span>]);
</span><span>$topcat_arr</span> = <span>end</span>(<span>$cat_arr</span><span>);
</span><span>$goods</span>['topcat_id']=<span>$topcat_arr</span>['cat_id'<span>];
</span><span>$goods</span>['topcat_name']=<span>$topcat_arr</span>['cat_name'];
Copy after login

Then, call the following in the product details template file goods.dwt:

Top category id: {$goods.topcat_id}
Top category name: {$goods.topcat_name}

The homepage of ecshop has obtained a category cat_id, how to call it and the products of its subclasses?

$children = get_children($cat_id); Get all categories of the same level as the specified category and subcategories under this category

/**
* Get products under the category
*
* @access public
* @param string $children
* @return array
*/
function category_get_goods($children, $brand, $min, $max, $ext, $size , $page, $sort, $order)

See how category.php is used

How does ecshop call the top-level category and sub-category name of the specified id

The homepage calls the subcategory method under the specified category
The template homepage generally has classified products displayed by floors. In the upper right corner of each floor, there will be small categories arranged and displayed under the category:
In the past, some templates were here For static display, customers need to manually modify it one by one. Now the template center will tell you how to modify it to dynamic call. You only need to modify an ID.
1. Open the includes/lib_goods.php file in your file root directory and add a method in the last line:
function get_parent_id_tree($parent_id)
{
$three_c_arr = array();
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
if ( $GLOBALS['db']->getOne($sql))
{
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
'FROM ' . $GLOBALS['ecs' ]->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC ";
$res = $GLOBALS['db']-> ;getAll($child_sql);
foreach ($res AS $row)
{
if ($row['is_show'])
$three_c_arr[$row['cat_id']][ 'id'] = $row['cat_id'];
$three_c_arr[$row['cat_id']]['name'] = $row['cat_name'];
$three_c_arr[$row[ 'cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
}
}
return $three_c_arr;
}

2. Call in the template file, such as in the homepage index.dwt:

$this-> ;assign('thiscid1', get_parent_id_tree(17));//Call the subordinate category of the parent category
?>


{$list.name}


The "17" in brackets is the category id, modify it according to the product category of your website... The rest of the full text >>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/834762.htmlTechArticleECSHOP gets the top category id and name of the product on the product details page, and the ecshop top level is in the goods.php file. Find $smarty-assign('goods', $goods); and add the following code above it: ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!