Ecshop secondary development-Shopping Cart FAQs

Source: Internet
Author: User
1. Solution to saving shopping cart data of registered users in ecshop secondary development:
Ecshop shopping cart is supported by the cart table in the database. In the ecshop table, rec_id is the number, user_id is the ID of the registered user, and session_id indicates the session ID. If the browser is closed, session_id will be automatically logged out.
Therefore, we can change the condition for obtaining the shopping cart after logging on to "session alone" to session + User name. The modification is in function get_cart_goods () under lib_order ();
Of course, the method of not logging in IS session. After the user logs in, the update cart will be automatically updated, and the data in the shopping cart under the same userid will not be updated to the current session, and updateid of 0 in the userid of the current session to the current userid, which is located in flow. under PHP
Function flow_update_cart ($ ARR)
When the change exits, the automatic clear cart changes the content of the current session of distroy to the part where the user ID of the current session is 0. The change is located in: des/cls_session.php, function destroy_session ().
The code above implements: After a visitor closes the browser, the shopping cart of the registered user is permanently saved, and the shopping cart of the unregistered user is cleared, which reduces the pressure on the server, of course, this still depends on the number of users, the pressure on a large number of data servers, the program will automatically clear the user cart that has not been logged in for a certain period of time (or add an additional data, to indicate the time of adding to the shopping cart, and determine whether to automatically clean up based on the time ).

2. Next let's take a look at how ecshop secondary development retains all the products in the login's shopping cart.
First, we need to modify the destroy_session () function. This function is in ipvdes/cls_session.php.

$ This-> DB-> query ('delete from '. $ globals ['ecs']-> table ('cart '). "Where session_id = '$ this-> session_id' and user_id = ''");
Then modify the update_user_info () function in the lib_mian.php file:

$ SQL = "Update ". $ globals ['ecs']-> table ('cart '). "Set user_id = ". $ _ session ['user _ id']. "Where session_id = '". sess_id. "'";
$ Globals ['db']-> query ($ SQL );
$ Sql1 = "Update ". $ globals ['ecs']-> table ('cart '). "Set session_id = '". sess_id. "'where user_id = '". $ _ session ['user _ id']. "'";
$ Globals ['db']-> query ($ sql1 );
$ Re = $ globals ['db']-> getall ("select *, sum (goods_number) as goods_number from ". $ globals ['ecs']-> table ('cart '). "Where user_id = '{$ _ session ['user _ id']}' and session_id = '". sess_id. "'group by goods_id ");

If ($ re ){
Foreach ($ re as $ k => $ v ){
$ SQL = "Update ". $ globals ['ecs']-> table ('cart '). "Set goods_number = ". $ V ['goods _ number']. "Where rec_id = ". $ V ['rec _ id'];
$ Globals ['db']-> query ($ SQL );
$ SQL = "delete from ". $ globals ['ecs']-> table ('cart '). "Where rec_id <> {$ V ['rec _ id']} And user_id = '{$ _ session ['user _ id']}' and session_id = '". sess_id. "'and goods_id = ". $ V ['goods _ id'];
$ Globals ['db']-> query ($ SQL );
}
}
This solves another problem in the secondary development of ecshop.

3. The following describes the product brand displayed in the shopping cart during secondary development of ecshop:
Find the cart_goods () function (about 873 rows) in mongodes/lib_order.php:

$ Arr [$ key] ['formated _ subtotal'] = price_format ($ value ['subtotal'], false );
Add a program under this Code (as shown below ):

$ SQL = "select brand_name from ". $ globals ['ecs']-> table ('goods '). "G left join ". $ globals ['ecs']-> table ("brand "). "B on G. brand_id = B. brand_id where goods_id = '{$ value ['goods _ id']}' ";

$ Goods_brand = $ globals ['db']-> getone ($ SQL );

$ Arr [$ key] ['goods _ brand'] = $ goods_brand;

In the get_cart_goods () function (about 1603 rows), find $ goods_list [] = $ row;
Add the following code above this Code:

$ SQL = "select brand_name from ". $ globals ['ecs']-> table ('goods '). "G left join ". $ globals ['ecs']-> table ("brand "). "B on G. brand_id = B. brand_id where goods_id = '{$ row ['goods _ id']}' ";

$ Goods_brand = $ globals ['db']-> getone ($ SQL );

$ Row ['goods _ brand'] = $ goods_brand;

Next, modify the flow. DWT template file and find
<! -- {If $ goods. is_shipping} --> (<span style = "color: # ff0000" >{$ Lang. free_goods} </span>) <! -- {/If} -->
Add the following code:

{$ Goods. goods_brand },
Then we need to find
<A href = "goods. php? Id = {$ goods. goods_id} "target =" _ blank "> </a> <br/>

Add code after it
Brand: {$ goods. goods_brand}

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.