spires Posted July 20, 2006 Share Posted July 20, 2006 Hi, I am building my first shopping cart and i'm already stuck.I have been all over the web to find article on how to build a cart, Which i have found very useful, I have taken a different parts of info so i can create my own cartcustomized to do what i want it to do. I cant get it to add more than one track at any one time, or get it to update the QTY.[url=http://www.spirestest.com/nicky/shop.php]http://www.spirestest.com/nicky/shop.php[/url]Any help pleaseThis code is now about 85% my own. I'm not to sure if thats the problem, or if its [2] which there are a few lines of codethat i dont understand.This is the main shop where you add to cart. [1][code]<?php echo "<center>";echo "<TABLE width=\"600\" class=\"TLRB_border\" cellpadding=\"1\" cellspacing=\"0\">"; echo "<TR bgcolor=\"#FFB876\"> <TD class=\"Title\">Track</TD> <TD class=\"Title\">Album</TD> <TD class=\"Title\">Price</TD> <TD class=\"Title\">Add</TD> </TR>\n" ;$query = "SELECT * FROM books ORDER BY id"; $result = mysql_query($query) or die ("Query failed"); $count = mysql_num_rows($result); for($i = 0; $i < $count; $i++) { $row = mysql_fetch_array($result); if($i % 2) { echo "<TR class=\"bggrey\">\n"; } else { echo "<TR class=\"bgwhite\">\n"; } echo '<TD align="left">"'.$row['title'].'"</TD> <TD align="left"> '.$row['author'].': </TD> <TD align="left"> £'.$row['price'].'</TD> <TD align="left"><a href="shop.php?action=add&id='.$row['id'].' "class="link">Add to cart</a></TD>'; echo "</TR>\n"; } if ($row['id']) { echo $id;} echo "</TABLE>\n"; echo "</center>";?>[/code]This is where the 'action=add and action=delete' is carried out. [2][code]<?phprequire_once('global.inc.php');// Include functionsrequire_once('functions.inc.php');// Start the sessionsession_start();// Process actions$cart = $_SESSION['cart'];$action = $_GET['action'];switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break;}$_SESSION['cart'] = $cart;?>[/code]Function showcart:This is displayed down the left hand side of every page. [3][code]<?phpfunction showCart() { $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); // pull out every id that and value and will be seperated by a , foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } echo "<center>"; echo '<TABLE width="125" class="TLRB_border" cellpadding="1" cellspacing="0" bgcolor="#FFF2DB">'; echo '<TR bgcolor="#FFB876" class="Title"> <TD colspan="3"> Shopping Cart </TD> </TR> <tr> <TD width="10"> </TD> <TD class="bold" >Track</TD> <TD class="bold" width="7">Qty</TD> </TR>' ; foreach ($contents as $id=>$qty) { $sql = "SELECT * FROM books WHERE id ='$id' "; $result = mysql_query($sql); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); for($i = 0; $i < $count; $i++) { echo $id; echo ' <tr> <td align="left" width="10"><br><a href="shop.php?action=delete&id='.$row['id'].'" class="link">X </a></td> <td align="left"><br>'.$row['title'].' </td> <td width="7"><br><div align="right">'.$qty.'</div></td> </tr>'; $total += $row['price'] * $qty; } } echo ' <tr> <TD width="5"> </TD> <td colspan="2" align="right"><HR width="100"><span>Grand total: <strong>£'.$total.'</strong></span></td> </tr>'; echo '</table>'; echo "</center>"; } else { echo '<center> <TABLE width="125" class="TLRB_border" cellpadding="1" cellspacing="0" bgcolor="#FFF2DB"> <TR bgcolor="#FFB876" class="Title"> <td> Shopping Cart </td> </tr> <tr> <td> <br><div align="center"><span class="loginBox_text">You shopping cart<br> is empty.</span></div> </td> </tr> </TABLE> </center>'; } }?>[/code] Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 20, 2006 Share Posted July 20, 2006 I would take a more OOP approach when dealing with a shopping cart project. Also, is this a personal project? Or are you doing this for a client? May I suggest looking into the following: http://www.turnkeywebtools.com/products.php?p=ss-shopping-cart-softwareIt's relatively inexpensive...and you wouldn't have to provide support. :-P Moreso, it has shipping and payment modules included. If your client wants to use real-time credit card processing & shipping calculations (UPS, Fedex etc API's) without having to be redirected to some lame third-party page, they can. Also...written in PHP. Just a suggestion. Quote Link to comment Share on other sites More sharing options...
spires Posted July 20, 2006 Author Share Posted July 20, 2006 Thanks, i was going to look in to buying one. but i can imagin them taking a time to learn how to customize them. Or is that not the case.by the way, This is for a customer. Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 20, 2006 Share Posted July 20, 2006 [quote author=spires link=topic=101252.msg400486#msg400486 date=1153409548]Thanks, i was going to look in to buying one. but i can imagin them taking a time to learn how to customize them. Or is that not the case.by the way, This is for a customer.[/quote]If it's for a customer, keep in mind that at some point, he will want support. Think of the constant questions you will be dealing with. :-P In such cases, I prefer a commercial solution...simply because they provide their own support (As well as releasing new updated versions frequently). Also...when you're dealing with credit cards and money...you want them to have immediate solutions/support for possible exploits/bugs being found...with a fast turn-around.In regards to customization...if you know PHP...and basic HTML...that shop I showed you would be easy to work with. I think they have links on their site to diferent shops. A few have been customized. I have at least 3 clients using that shop atm...and it's always nice not to have to provide the support for it. All I handle is the design end of it. Quote Link to comment Share on other sites More sharing options...
spires Posted July 20, 2006 Author Share Posted July 20, 2006 Sounds very good. So you know, If i buy it once, can i use it again? or only on one site? Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 20, 2006 Share Posted July 20, 2006 Also...the reason why I went with a payed solution versus some of the open-source stuff...was because of their support. The company for that shop has phone support, livechat, and a support ticket system. Also...they include all the diferent modules (Shipping & payment gateways etc) without any additional cost. A lot of other shops charge for adding modules. Buttholes. :-PI had used X-Cart for an older client...whatever you do...stay away from it. They suck! I had to do most of the work when it came to troubleshooting stuff since they have literally next-to-no support. Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 20, 2006 Share Posted July 20, 2006 [quote author=spires link=topic=101252.msg400506#msg400506 date=1153410342]Sounds very good. So you know, If i buy it once, can i use it again? or only on one site?[/quote]When you pay for it, they email you a link to download the software. (Basically, the PHP files in a compressed folder). The licenses are assigned by domain so, one license per domain name. Make sure you save ALL the files and backup your database. After the first year, if your client wants to renew their support with the company, they can renew the license. It costs half of the original price I think. Not a bad deal since usually people make money off the cart anyway.I think they have a live demo where you can mess around with the templates and stylesheet. I would look through it first if I was you.Hope that helps! Quote Link to comment Share on other sites More sharing options...
smartguyin Posted July 20, 2006 Share Posted July 20, 2006 If you are buying this then its good but check out this one here i find the open source project which is offered in Cpanel hosting in Fantastio Section you can find shopping cart script which works very fine with every thing check it out its free.... Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 20, 2006 Share Posted July 20, 2006 Well..the problem, is that he is providing it for a client of his. And giving him an open source one, that has very little (If you've ever had one of your clients try to get support for immediate issues for an open source package you'll know exactly what I mean...it's next to non-existant) support, it would not be very professional. Take it from someone who has much experience with ecommerce. Also...if he's going to be using shipping and payment gateways...you can't beat the built-in modules that are always kept up-to-date. Like I said before...for a personal project...open source is great. And I recommend it! However, when dealing with a paying client...you don't want to go open source. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.