ECSHOP obtains the top-level category id and name of a product on the product details page. ecshop top-level

Source: Internet
Author: User

ECSHOP obtains the top-level category id and name of a product on the product details page. ecshop top-level

In the goods. php file,

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

Method 1:

$cat_arr = get_parent_cats($goods['cat_id']);foreach ($cat_arr AS $val) 
{  $goods['topcat_id']=$val['cat_id'];  $goods['topcat_name']=$val['cat_name'];}

Method 2:

$cat_arr = get_parent_cats($goods['cat_id']);$topcat_arr = end($cat_arr);$goods['topcat_id']=$topcat_arr['cat_id'];$goods['topcat_name']=$topcat_arr['cat_name'];

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

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


In ecshop, the home page obtains the cat_id of a category. How do I call it and its sub-category products?

$ Children = get_children ($ cat_id); obtain all classes of the specified category at the same level and subcategories under the specified category

/**
* Obtain products under a category
*
* @ Access public
* @ Param string $ children
* @ Return array
*/
Function category_get_goods ($ children, $ brand, $ min, $ max, $ ext, $ size, $ page, $ sort, $ order)

Let's see how category. php is used.

How does ecshop call the top-level category and subcategory name of a specified id?

The homepage calls the subcategory method under a specified category.
Generally, the template home page contains classified items displayed on different floors. Each floor is displayed in the upper-right corner of the page:
In the past, some templates were displayed statically. You need to manually modify them in sequence. Now the template center tells you how to change them to dynamic calling. You only need to modify one id.
1. Open the pludes/lib_goods.php file in the root directory of your file, 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 it in the template file, such as in index. dwt of the homepage:

<? Php
$ This-> assign ('thisciid1', get_parent_id_tree (17); // calls the subcategory of the parent category
?>

<! -- {Foreach from = $ thiscid1 item = list name = name} -->
<A href = "{$ list. url}" target = _ blank >{$ list. name} </A>
<! -- {/Foreach} -->

The "17" in the brackets is the category id, which is modified according to the category of your website products ...... the remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.