Ecshop secondary development: add the latest transaction Scroll display function

Source: Internet
Author: User

Yesterday, I added the homepage rolling display function of the latest transaction to the speed shopping network. Today, I sorted it out and sent it to benefit the people ~ To add new features to ecshop, I feel that there are almost two changes. The displayed template needs to be modified. To facilitate the next upgrade, we 'd better make all the changes LBI. I copied the new features to the next upgrade, then, just modify the DWT template. ForProgramFor some modifications, I suggest you create a directory of your own, such as Dev, and then put each function you add into a PHP file into the dev directory, when necessary, include or require in the PHP of the original ecshop. In this way, the next system upgrade directory will be copied, and then the include option will be OK, saving time and worry. Of course, I personally suggest you maintain a table to save the changes you have made to facilitate the next upgrade. Next, let's talk about what needs to be modified from the template and program aspects.

I. Program-level Modification
What we want to display is nothing more than who purchased something at what time. In this case, we need to read the information from the database. Find the data dictionary of ecshop on the Internet and check that there are three ecs_order_info, ecs_order_goods, and ecs_users related to our tables, respectively storing order information, the product information corresponding to the order and the user information of the purchased product. These three tables are associated with three keys: user_id, order_id, and goods_id. Below we will write an SQL statement to retrieve the information we need. The SQL statement is as follows:

 
 
Select ecs_users.user_name, region, region, order_info.add_time from ecs_users, (select order_id, user_id, add_time from ecs_order_info order by ecs_order_info.add_time DESC limit 0, 20) As order_info, ecs_order_goods where order_info.order_id = ecs_order_goods.order_id and order_info.user_id = ecs_users.user_id;

The preceding statement extracts the first 20 transactions from ecs_order_info and obtains the username, product name, product ID, and order time based on the association between order_id, goods_id, and user_id. After the SQL statement is completed, we need to write a function in ecshop mode. This function obtains the content of the SQL statement from the database and then encapsulates the record of this SQL statement into an array, to the smarty template. BelowCodeFor more information, see:

 
 
>/*** Call to obtain the latest purchaser and item query ** @ access private * @ return array */function consumer () {$ SQL = 'select ecs_users.user_name, ecs_order_goods.goods_id, ecs_order_goods.goods_name, orders from ecs_users, (select order_id, user_id, add_time from ecs_order_info order by limit DESC limit 0, 20) As order_info, where order_info.order_id = orders and order_info.user_id = ecs_users.user_id ;'; $ all = $ globals ['db']-& gt; getall ($ SQL); $ arr = array (); foreach ($ all as $ idx = & gt; $ row) {$ arr [$ idx] ['username'] = $ row ['user _ name']; $ arr [$ idx] ['goodname'] = $ row ['goods _ name']; $ arr [$ idx] ['goodid'] = $ row ['goods _ id']; $ arr [$ idx] ['add _ time'] = local_date ($ globals ['_ CFG'] ['date _ format'], $ row ['add _ time']);} return $ arr ;}

The above Code uses $ globals ['db']-> getall ($ SQL); To obtain records in the database, which is in init. in PHP, the system initializes the loaded global variables and interacts with the database to obtain data and other functions. I have time to write several pieces of ecshop code for analysis.ArticleFor more information about the initialization process of ecshop, you can understand the high-quality code of ecshop. The foreach below is actually used to encapsulate the data into an array. The smarty group is friendly when processing the template. The above only gets the array. The following statement is to assign the array value to the smarty template"

 
12
 
// Obtain the latest purchaser Information $ smarty-& gt; assign ('recent _ buys ', index_get_recent_buy_query ());

Add this sentence to a similar place in index. php, which is basically in the 80 + rows where the ecshop template is assigned a value. Let's take a look at how to use the previously assigned value smarty template.

2. template-level Modification
We create businessactivities. LBI to store the content of our smarty template. The following code is used to analyze the Code:

 
 
 
   
    
  
  

{$ Lang. sale_activities}

{$ buy_info.username} bought {$ buy_info.goodname}

Note that the above section describes the basic information of your template. I am utf8 here. If you are a GBK, you need to change it to GBK. It corresponds to $ smarty-> assign ('recent _ buys ', index_get_recent_buy_query () in the above PHP program. If you assign a value to recent_buys, if this value is not null or 0, the template content is displayed. We will focus on the fact that foreach is a built-in function of the smarty template. Its main function is to traverse the input array and then generate content, similar to foreach in other languages. In this case, recent_buys is traversed and the items retrieved each time are called buy_info. In fact, this buy_info is the second-dimensional array of our data. You can directly use the form {$ buy_info.goodname} to call the content passed in your array. It's nice to use the smarty template to separate absolute data from reality.
You can add the following information to the display area.

In fact, this process is basically used for ecshop development. This part does not involve Ajax calls and other troublesome things, but is only displayed from database calls to templates, today, I am going to add an address selection function for the registration options, which will use Ajax and other things. I have finished writing it and sent it to the next blog post. Please look forward to O (register _ blank) O ~

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.