Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Adding database-driven shipping charge functionality to an online store

by Joseph Lowery

Joseph Lowery
  • jlowery@idest.com

Modified

26 October 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
database Dreamweaver dynamic website e-commerce

Requirements

Prerequisite knowledge

Basic understanding of the building blocks and tools required for building dynamnic websites.

User level

Intermediate

Required products

  • Dreamweaver CS4 (Download trial)

Unless your online store deals with digital goods, shipping is a fact of life. Given the complexity of incorporating shipping charges into an e-commerce shopping cart, some store owners may find it tempting to simply absorb the costs. While free shipping may make for very happy customers, it's not an effective long-term solution─the ongoing costs are just too high. This article examines one of the viable alternatives for passing shipping charges onto the customer: a database-driven method that maintains local control. In another article, Retrieving shipping rate quotes in real time, I will review a web service-based technique that gets current ship rates direct from the shipper.

Shopping cart extensions for Dreamweaver support shipping charges to a variety of degrees. Cartweaver uses variations of the database-driven shipping method, whereas WebAssist eCart supports both database-driven and the web service techniques.

Choose your shipping path

Which method you choose is determined both by the client's established shipping accounts, if any, and how you want the shipping charges maintained. If your client does not already have an account with a major shipper like UPS or FedEx that offers web service quotes, the database-driven option is the natural choice. The database-driven method also allows a bit more control over pricing than the formulaic web service technique.

On the other hand, the amount of work involved in setting up and updating the back end for the database approach is extensive. By contrast, the web service method appears quite attractive from a workload perspective, especially after the initial set-up is complete. It's important to keep in mind that with a web service you don't have the precise control over charges granted by a database-driven approach. However, you do have the option to either pass along the exact shipping rate quote returned by the web service or to charge a calculated amount, such as a 10% increase to cover handling.

Setting up the database schema

The first step in enabling database-driven shipping is to establish the proper schema. As you might imagine, there is a great deal of flexibility in how you accomplish this, depending on your shipping requirements. In this section, I'll describe the approach eCart uses in its eCommerce Recipes.

If you've ever looked at a UPS rate chart, you know the basic structure of the shipping elements in your database. The online store needs to be able to charge for shipping based on several factors:

  • Distance: Shipping charges generally increase the greater the distance between the shipping origin and the destination.
  • Weight: Most shippers charge a base rate for the initial pound plus an incremental rate for additional pounds.
  • Service: The type of service—ground, 2-day, or overnight for example—also affects the price; typically the faster the service the higher the cost.

Table 1 shows a sample database shipping schema that addresses all these factors. The database accounts for distance by the ShipState and ShipZone columns; zones are larger areas of the countries encompassing more than one state. Different amounts are entered into the ShipRate column according to the state or zone shipped to. The weight of a shipment is typically calculated in the online store's shopping cart and the charges applied are a combination of the basic shipping rate and the incremental amount. The service factor is handled by the ShipType column. Note that there is a separate database record for each service type within each state. This gives the developer the ability to fine tune shipping costs.

ShipID ShipType ShipState ShipZone ShipRate ShipInc
1 Standard CA 1 $4.85 $0.15
2 2-Day CA 1 $6.80 $0.55
3 Overnight CA 1 $14.75 $0.80
4 Standard NY 4 $5.65 $0.75
5 2-Day NY 4 $10.50 $1.70
6 Overnight NY 4 $20.00 $2.75

Table 1. Sample database shipping schema with data

Let's look at an example of how this database information might be applied. Let's say that the shopper has ordered goods that weigh 5 pounds and wants 2-day delivery to New York. The calculation would look like this:

Shipping Cost = BaseRate + (Increment * (Total Weight – 1))

Translated into English, the formula reads, "The shipping cost is equal to the shipping base rate (for the first pound) plus the shipping incremental rate, times the total weight, minus the first pound." You must, of course, deduct one pound to compensate for the initial pound, accounted for with the base rate. With this example, the formula would evaluate as follows:

  • Shipping Cost = 10.50 + (1.70 * (5 – 1))
  • Shipping Cost = 10.50 + (1.70 * 4)
  • Shipping Cost = 10.50 + 6.80
  • Shipping Cost = $17.30

Where do you get the values to insert into your database shipping table? The best place to start is in the rate sheets used by your client's shipper. You can be as precise—charging different amounts for each zip code—or as broad as desired. You're also free to modify the charges as needed, making them more or less expensive according to the client's wishes. Many stores, like the one in this example, ship from just one location, but larger companies may use multiple shipping centers; in this situation, the database schema will need to be expanded to allow for this possibility.

Two other enhancements are to establish separate tables for the states (or other areas) shipped to and the shipping types (see Table 2). These implementations are great if you want your customers to be able to select their shipping destination and service from select list. It's a simple matter on any page requiring such a list to create two recordsets—one from the state table and another from the services table—and populate the select lists with the results.

ShipTypeID ShipTypeName
1 Standard
2 2-Day
3 Overnight

Table 2. Shipping services table

If you create these additional tables, be sure to use the lookup function of your database to include their data when crafting your core database shipping table.

Bringing the data into the cart

Now that the data is entered into your database, the next step is to make it accessible to the shopping cart. Because an online store is a multipage web application, the typical technique is to retrieve the information from the database—based on user selections—and store it in session variables. The session variables can then be used in calculations, displayed in a view of the cart, or passed onto to the payment gateway.

Session variables also come into play to store the customer-supplied information required to properly filter the recordsets. You'll recall that of the three criteria for determining a shipping cost, two—shipping destination and service type—are gathered directly from the shopper. The shipping information is input into a form, like the one in Figure 1, before the shipping costs are displayed.

Information entered by the shopper helps to determine the shipping rate
Figure 1. Information entered by the shopper helps to determine the shipping rate

The two select lists—one for the State/Province and the other for the Shipping Method—are both dynamically populated. Recordsets are added to the page to pull in the database-stored information for each. In this example, these form elements are also the ones used to calculate the shipping rate. After the user clicks the Complete Checkout button, server-side code on the next page displayed picks up the state/province and shipping method values and inserts them into session variables. eCart includes a custom server behavior, Set Session Value, that handles this action without coding.

A recordset on the final checkout page uses the shipping type and state session variables to get the right shipping rate. In the case of the example recordset shown in Figure 2, a database view pulls information from three tables: shipping rates, shipping types, and states. Among the information included in the retrieved data are the correct base and incremental charge.

Data from the form elements on the previous page, now in session variables, filters for the right shipping cost data
Figure 2. Data from the form elements on the previous page, now in session variables, filters for the right shipping cost data.

The code uses two more session variables to store the base and increment values. You can then tie these session variables to the shopping cart.

Again, there are a variety of ways to handle the shopping cart manipulations. One technique, used by eCart, is to establish merchandising rules for the charges. Two rules are required, one for the base rate—which is always applied to shippable items—and another for the increment, applied only if the total weight is over a pound. One detail to keep in mind when working with session variables for certain server models, notably ASP and Coldfusion, is that any data stored in a session variable is converted to text; PHP does not have this issue. To be used in a calculation, you'll need to convert the text-based session variable value into a number. Here's how you would convert the base rate session variable:

[ASP-JS] parseFloat(Session("BaseRate")) [ASP-VB] CDbl(Session("BaseRate")) [CF] ToNumber(Session.BaseRate)

Displaying the shipping charge

The last shipping-related step is to display the calculated charge to the shopper. Naturally, you want the customer to see all the total due, including all charges and discounts before completing the checkout procedure. Shipping costs are typically grouped with other charges after the subtotal and any applied discounts. Shopping cart displays, like eCart are automatically formatted for you, like the one shown in Figure 3, while remaining customizable.

Shipping information is inserted to the Charges section of a cart
Figure 3. Shipping information is inserted to the Charges section of a cart.

If you want to repeat the shipping information in another location, you'll need to insert the code to display it. eCart treats any shopping cart rule, such as shipping charges, like other dynamic data and displays it in the Bindings panel; to show it anywhere on the page, you can just drag-and-drop it onto the page.

Where to go from here

This article explored a developer-initiated method for setting your shipping charges within Dreamweaver. A related article, Retrieving shipping rate quotes in real time, discusses the process of getting shipping quotes from the major shipping companies in real time by taking advantage of the web services from UPS and FedEx.

For more web development tutorials, check out the Learn to build dynamic websites page in the Dreamweaver Developer Center.

More Like This

  • Beginner's guide to databases
  • Managing multiple subscriptions in PHP
  • Building a subscribe/unsubscribe app in PHP with Dreamweaver CS3
  • Which server-side technology should I choose?
  • Creating master and detail ColdFusion pages
  • Creating user-defined functions for ColdFusion 8 in Dreamweaver CS4
  • Creating a ColdFusion upload page in Dreamweaver CS4
  • Creating custom server behaviors and Dreamweaver extensions
  • Exchanging data using the Spry framework for Ajax and PHP
  • SQL primer for Dreamweaver users

Tutorials and samples

Tutorials

  • Understanding HTML5 semantics: Changed and absent elements
  • Mobile app with PhoneGap: Submitting to the Apple App Store
  • PhoneGap and Dreamweaver: Releasing on iOS
  • Mobile app with PhoneGap: Submitting to Android Market

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Dreamweaver user forum

More
04/23/2012 Resolution/Compatibility/liquid layout
04/20/2012 using local/testing server with cs5 inserting images look fine in the split screen but do not show
04/18/2012 Ap Div help
04/23/2012 Updating

Dreamweaver Cookbook

More
11/07/2011 Simple social networking share buttons
09/20/2011 Registration form that will generate email for registrant to validate
08/21/2011 Spry Accordion - Vertical Text - Auto Start on Page Load - Mouse Over Pause
08/17/2011 Using cfdump anywhere you like

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement