OrderForm Shopping Cart Functionality In HTML Pages
Previous  Top  Next

OrderForm uses JavaScript and forms to add full shopping cart functionality within HTML web pages for complete design flexability. For single item orders and checkout from HTML web pages, see Order Links.

The pages that use OrderForm must be within the AShop directory or below it. If AShop is installed in the root directory, then OrderForm will work in any HTML page within the domain.

1.A file named .htaccess containing the following instructions must be present within directories where OrderForm is to be used within HTML pages.  

AddType application/x-httpd-php .html .htm

Note: An example file
htaccessORDERFORM.txt is included with the AShop distribution folder.

Note:
All of the following code is included in an example file
orderform.html that is distibuted with AShop. The following links in the following code assume that the pages are in the same directory as AShop. Modify the links as needed depending on where the pages are in relation to AShop.

2.Place the following code within the header of the HTML pages that are to use OrderForm.  

<!-- Start AShop for Downloads OrderForm Header Script -->
<SCRIPT LANGUAGE=JavaScript TYPE="TEXT/JAVASCRIPT">
<!--Hide script from old browsers
function buyItem(itemno)
{
   window.open("buy.php?item="+itemno,"_blank","toolbar=no, location=no, scrollbars=no, width=300, height=200")
}
 //Stop hiding script from old browsers -->
 
</SCRIPT>

<?php
  include "admin/config.inc.php";
  $db = @mysql_connect("$databaseserver", "$databaseuser", "$databasepasswd");
  @mysql_select_db("$databasename",$db);
  $subtotal = 0;
  $items = explode("a", $basket);
  $arraycount = 1;
  if ($items[0] && count($items)==1) $arraycount = 0;
  for ($i = 0; $i < count($items)-$arraycount; $i++) {
   // Get the products price from the database...
    $sql="SELECT price FROM product WHERE productid=$items[$i]";
    $result = @mysql_query("$sql",$db);
    if (@mysql_num_rows($result) == 0) {
      $price = 0;
    } else {
      $price = @mysql_result($result, 0, "price");
      $subtotal += $price;
    }  
  }
?>
<!-- End AShop for Downloads OrderForm Header Script -->

3.Place the cart subtotal box, and shopping cart buttons in the page by inserting the following.  

<!-- Shopping cart subtotal text box and view cart and checkout buttons. The "amount" field must be present only one time within the body of the html. If you don't want the subtotal to appear, change the field type from "text" to "hidden". Place the view cart and checkout links in convenient locations on the page. If you don't want the view cart or checkout links to appear, omit the links. -->
                        <form name="shoppingcart">
              <table width="100%" cellpadding="2" cellspacing="0" border="0" align="right">
                <tr> 
                  <td align="right"><font face="Arial, Helvetica, sans-serif" size="2" color="#000000">Subtotal: 
                    $ </font><font face="Arial, Helvetica, sans-serif" size="2"> 
                    <input type="text" name="amount" style="border: 1px solid black; background: #ffffff; width: 60px; font: 11px verdana, arial, helvetica; color: #000000;" size="6" readonly value="<?php echo number_format($subtotal,2,'.',''); ?>">
                    </font></td>
                  <td width="76"><a href="basket.php"><img src="images/viewcart.gif" alt="View Cart:" border="0" width="76" height="21"></a></td>
                  <td width="76"><a href="checkout.php"><img src="images/checkout.gif" alt="Check out" border="0" width="76" height="21"></a></td>
                </tr>
              </table><!-- end of shopping cart subtotal box and buttons -->
            </form> 


4.Optionally display the product price that is set in AShop by placing the following code within the body of the HTML page.  

<b>$ <span style='font-size:10.0pt;font-family:Arial'>
<?php $get = "price of 1"; include "productinfo.inc"; ?>
</span></b>


5.Place Add To Cart buttons where needed by inserting the following code within the body of the page. Change the productid to correspond with the AShop productid that appears next to each product in the Administration Panel > Edit Catalogue for each product.  

clip0117


<!-- Begin Buy button.  Change the productid to correspond with the AShop productid that appears next to each product in the Administration Panel > Edit Catalogue for each product. -->
<form name="productform" style="margin-bottom: 0px;" onSubmit="return false">
</font><input type="image" border="0" name="imageField" src="images/buysp.gif" width="109" height="19" onClick="buyItem(1)" align="top">
<!-- where 1 is the productid. Change this to match the productid for each product. -->
</form>
<!-- end Buy button code -->

Note for Dreamweaver users: When creating forms, Dreamweaver's default preferences will automatically rename form items when pasting. Change this by unchecking the Rename Form Items When Pasting box in the Dreamweaver file menu; Edit > Preferences. The name of the order link forms must be "product" or "imagefield" and not "product1", "product2" or "imagefield1", imagefield2", etc.