How to add an item to the cart with button

Let's say you're trying to customize your view image page to add a link or button so your clients can add a package, or any other single item, to your cart by clicking on a link or button rather than scrolling through a list of items. With a bit of digging in your database plus a little HTML it's fairly easy to do.

Database ID

First thing you'll need is the database ID for the pricing item you're wanting to add, and this is admittedly will be the hardest part for most of y'all.

Somewhere within your hosting control panel - the place where you go to create email addresses and build databases - you should have a link to view your databases. On most hosts you can look for something named phpMyAdmin. If you're using cPanel, and most of y'all probably are, phpMyAdmin should be under the MySQL section. If you're using GoDaddy take a look at this article on how to find phpMyAdmin.

Bit of a quick aside. While you're in looking directly at the database, DO NOT change anything. Before ProofBuddy stores data in your database it checks to make sure that data makes sense, but if you change data while you're in phpMyAdmin it's possible that ProofBuddy won't understand that information and may not work.

Not to worry though. We're not changing anything here. We're just looking for a number.

What we're looking for is a table that ends with _pricing. It's most likely named pb_pricing, but the pb may be different if you set a different prefix during setup.

pb_pricing table screen shot

Click on the Browse link next to the pb_pricing table. Depending on what version of phpMyAdmin is on your server it make be written out like the screen shot above or just an icon.

What you're looking for is the number in the ID column. It's 71 in the screen shot below. You can ignore the rest of the columns.

Building the Button

You've done the hard part. Now it's just a bit of HTML

You're going to add the following to your fullimage.tpl template file where ever you want your button to show up.

<form action="<?php echo $cProofBuddy->url; ?>/user/user-script-addtocart.php" method="post">
<input type="hidden" name="item" value="THE ID NUMBER FROM ABOVE">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="imageid" value="<?php echo $_GET['id']; ?>">
<input type="hidden" name="colortype" value="color">
<input type="hidden" name="albumid" value="<?php echo $_SESSION['currentalbum']; ?>">
<input type="submit" value="Add my special item to cart">
</form>
Categories:Development Blog

4 comments on this post

  1. Ryan, thanks for posting this. I was going to reply to the thread with the information you provided by email, but never got around to it.

    I actually ended up taking this a step further since I was using this for a "Digital Negative DVD" package. I put in some conditional logic that would check to see if the person had added the package to their cart already, if they didn't then it would display a button that would add the Package to the cart. If they had added the package to their cart already then it would display a button to add an image to the package.

    If anyone is interested in how to do this and has an understanding of php and html, send me a PM through the forum and I'll be happy to assist.

  2. I am having some difficulty getting this to work. When using the code above I get this error:

    Error: Database query error
    File: -------/database.class.inc.php(8) : eval()'d code(3) : eval()'d code:528

    I am using the PRO/paid for version.

    • In the cache folder, there's a file named pb_error_log.php. Can you send that file to us, along with the code you're using to make the button?

      The "Database query error" is intentionally vague and doesn't really explain what's going on.

  3. I have emailed the to you :) TIA

Leave a Reply