Php shopping cart program. This is a simple php code developed and used by myself for shopping cart functions. a few files are used and no database is used to implement shopping cart. if the user closes the browser, the shopping cart vendor is a simple php code developed and used for shopping cart functions. it uses a few files and does not use databases to implement the shopping cart. if the user closes the browser, all the items in the shopping cart will be lost. if you need it, you can improve it. it is better to use database + session + cookie.
The code is as follows: |
|
Class Shopcar { // Product list Public $ productList = array (); /** * * @ Param unknown_type $ the product to be imported * @ Return true no such item exists in the shopping cart */ Public function checkProduct ($ product) { For ($ I = 0; $ I ProductList); $ I ++) { If ($ this-> productList [$ I] ['name'] = $ product ['name']) Return $ I; } Return-1; } // Add to shopping cart Public function add ($ product) { $ I = $ this-> checkProduct ($ product ); If ($ I =-1) Array_push ($ this-> productList, $ product ); Else $ This-> productList [$ I] ['num'] + = $ product ['num']; } // Delete Public function delete ($ product) { $ I = $ this-> checkProduct ($ product ); If ($ I! =-1) Array_splice ($ this-> productList, $ I, 1 ); } // Returns information about all products. Public function show () { Return $ this-> productList; } }
Html
Insert title here
|