close ad
 
Important WebAssist Announcement
open ad
View Menu

Web development tutorial

Add dynamic product options II (eCommerce Series)

Tutorial created by Ray Borduin, WebAssist

Categories: Data Bridge, eCart, PHP

rating

In this tutorial, the fourth in the eCommerce series, you will learn how to add dynamic product options, which include options within themselves, to your website's online store using eCart's shopping cart functionality. As an example, specialty clothing lines often need the ability to increment prices for extra-large sizes since they are more costly to manufacture. So while sizes small, medium, and large could have a base price of $9.99, extra large and extra-extra large sizes could be incrementally priced at an additional $2.

If you want to add static product options (for example, product lines that do not change often) or dynamic product options (for example, product options that need categorizing) to your website, there are dedicated tutorials in this series to walk you through the steps. You'll find a linked index including an overview of each tutorial belonging to the eCommerce series at the bottom of this page.

arrow downWhat do you need to start?

  1. Dreamweaver CS4 or higher.
  2. eCart 5 or higher installed and activated in Dreamweaver
  3. Site defined in Dreamweaver. For assistance defining a site, view these tutorials: Define a dynamic site in CS4 or Define a dynamic site in CS5+.
  4. PHP web page and connection in Dreamweaver to your database. For assistance, view this tutorial: Create a PHP database connection.
  5. MySQL database. If you do not have one, you can download our free eCommerce MySQL database in this tutorial.
  6. Product catalog pages. For assistance creating product catalog pages, view this tutorial: Create a product catalog.
  7. Shopping cart. For assistance creating a shopping cart, view this tutorial: Create a shopping cart.

arrow downWhy use incremental pricing?

There are two main methods of customizing a shopping cart. The most basic is to add custom columns to store data specific to the product line. For instance size and color are common columns. But in this tutorial, you'll learn the more complex technique of options affecting more than one column in a shopping cart.

A common example is a store that sells t-shirts. The t-shirts each have a base price of $9.99. But the XL and XXL sizes cost $2 more. Thus, size affects price. The store owner could individually price the larger t-shirts. But using one option group with incremental pricing simplifies future updates. For example, when prices need to be increased, one update to the base price is all that will be required.

While incremental pricing is probably the most common use for options affecting more than one column, this technique can be applied in other ways. For example, an eCommerce site might sell boats as a single product. The options would be the actual boat, a 1976 Bayliner or a 1973 Chris Craft. In this case, when a boat is selected as an option, the make, model, length, year, etc. are automatically set in the shopping cart. This is the same concept as size affecting price, where one item chosen from the list affects the value of more than one column in the shopping cart.

arrow downPopulate your product catalog

Before you begin to add product option functionality to a shopping cart, you need to populate your product catalog, adding into a database the various product options and option groups to display products you wish to sell on your website. You can use our free eCommerce MySQL database with the necessary tables for defining product options. However, if you already have a database and a product catalog, you can skip this step and move to the next section of this tutorial.

In this tutorial, we will be setting up two types of product options for a fictitious online store selling t-shirts:

  1. Color options without a price increment.
  2. Size options with a price increment for certain sizes.
If you are not using the eCommerce MySQL database, you will need to review the table and column references to make sure they match up with your database structure.


Go to a MySQL administration tool of your choice and open the eCommerce MySQL database that you downloaded. You will be working in these five tables, OptionGroups, Options, ProductCategories, Products, and ProductOptions.

  1. OptionGroups table: The first table we are going to populate in the eCommerce MySQL database is OptionGroups. Fill in 1 for color and 2 for size.


  2. Options table: Give each color an individual OptionID as well as the sizes. Enter the OptionGroupID to join the color and size options to the OptionGroups table.


  3. ProductCategories table: There are four categories of men's athletic shoes in our fictitious store, Running, Walking, Hiking, and Track and Trail. They each are assigned an individual CategoryID, 1, 2, 3, and 4. The two types of t-shirts each have an individual CategoryID also.


  4. Products table: Give each product its own ProductID and an actual product name. Fill in price, weight, and a description of the product. In the ProductCategoryID column, place the CategoryID number from the ProductCategories table. In the ProductColor column, place the OptionGroupID for color from the OptionsGroup table.


  5. ProductOptions table: Now it is time to join the T-Shirts to color options, size options, and price increment. First though, give each t-shirt a unique ProductOptionID. Then fill in the ProductID found in the Products table. In the OptionID column, display colors and sizes by adding the corresponding OptionID. Fill in the OptionGroupID, which joins this table to the OptionGroups table for color and size. Lastly, determine the incremental pricing option.

arrow downUpdate eCart Object

In the Add a shopping cart tutorial, you already created the eCart Object. Now you are going to update the eCart Object by adding new columns and calculations to accommodate your online store's product options.

Add new columns:

  1. Back in Dreamweaver, go to Webassist > eCart > eCart Object.

  2. From the eCart Object panel, select your cart and click Edit.


  3. Choose the Columns tab of your eCart object. This is where you will define specific columns for use within your shopping cart.


  4. Click Add to add a new column. Name it color.

  5. From the menu list, choose Text as the Output Type for the color column so your shopping cart can display the various colors contained in your database.
    The six available Output Types are number, Text, Currency, Date, Integer, and Weight. For example, the price column's Output Type is Currency.

  6. Select the unique checkbox so that the shopping cart recognizes that some customers may want to purchase more than one pair of red shoes, for example.

  7. Click the Add icon to add another new column and name it size.

  8. From the menu list, choose text for the column and select the unique checkbox.

  9. Add a third new column called sizePriceInc but this time choose currency for the column.

  10. Select the unique checkbox.


  11. Just as you used the Add icon to insert a new column into the list, you can also use the Delete icon to remove an existing column.


Add new calculations:

  1. Choose the Calculations tab.


  2. Add a new calculation called truePrice.

  3. For the truePrice calculation, enter the following:
    [Price] + [sizePriceInc]

  4. With this new calculation, the TotalPrice calculation needs updating.

  5. Modify the TotalPrice calculation to look like this:
    ([Price] + [sizePriceInc]) * [Quantity]


  6. Click OK to save your changes and close the eCart Object window.
    Although cart columns can be added at any time, it will require that you manually update the Add to Cart button interface and shopping cart display. So save time by carefully setting up your product options in advance.

arrow downUpdate shopping cart

In the Add a shopping cart tutorial, you created the shopping cart. You also created a page named cart.php. Now that you have made changes to your eCart Object by adding columns, you need to update the shopping cart page. This requires that you remove the Shopping Cart instance from your cart page, and insert a new one using the eCart Display Manager.

  1. Open your shopping cart page and remove your shopping cart. Place your cursor where you wish your new shopping cart display to be inserted.


  2. Go to WebAssist > eCart > Display Manager. Open the specific cart to review the settings. Make any updates to the design of your cart, and click Next.


  3. Click Add to add the color, size, and sizePriceInc columns you added to the eCart Object.


  4. In the Label column, change sizePriceInc to * XL XXL so that price increment options are self-explanatory to your shoppers.
    To display additional columns that you created in the eCart object, click the Add icon. However, if you decide that you want additional columns, they need to be created first in the eCart object before being added on this page.

  5. Use the up and down arrows to adjust the order of the columns. Check the Group with previous column box to group items together. You can also delete columns. Click Next.


  6. Next you can determine how charges, discounts, shipping, and tax will be displayed. Choose between Summary which includes the section header and a corresponding total, Individually for each rule triggered in the shopping cart as well as the sum, or Do not show to disable the selected option on the cart display. Summary is a common choice. After you have have made your selection, click Finish.


  7. Review your shopping cart columns.
    .

  8. Save the page (Ctrl or Cmd + S).

arrow downAdd product options recordset

Now that you have updated your eCart Object and recreated your Shopping Cart Display, the server behaviors need updating in order to populate select lists with the dynamic product options.

  1. Open your product detail page.
    The product detail page is typically created by DataAssist to display the details for a specific item and a related Add to Cart button.

  2. Go to Window > Server Behaviors.

  3. From the Server Behaviors panel, click the + icon and then Recordset to open the Recordset dialog box.


    When the Recordset dialog box displays, it may open in Simple mode. For these instructions, you will need to change this to Advanced. Choose Advanced from the buttons on the right. If you see Simple, you are already in Advanced mode.


  4. In the Name field enter rsColor.

  5. Select and copy (Ctrl or Cmd + C) the following code:
    SELECT productoptions.OptionPriceincrement, productoptions.ProductOptionID, options.OptionName, options.OptionGroupID, optiongroups.OptionGroupName
    FROM options
    INNER JOIN productoptions ON options.OptionID = productoptions.OptionID
    INNER JOIN optiongroups ON options.OptionGroupID = optiongroups.OptionGroupID
    WHERE optiongroups.OptionGroupName = 'color' AND productoptions.ProductID = paramItem

  6. Place your cursor in the SQL box of the Recordset dialog and press (Ctrl or Cmd + V) to paste this content.


  7. In the Variables section, click the + icon.

  8. Enter paramItem into the Name field of the Variables dialog.

  9. From the menu list choose Integer.

  10. In the Default value field, enter -1.

  11. Copy (Ctrl or Cmd + C) and paste (Ctrl or Cmd + V) the following parameter into the Runtime value field:
    $row_WADAproducts['ProductID']



  12. Click OK.
    WADAproducts is the name of the products recordset created by the DataAssist: Create Pages wizard. If you are using your own details page, you will need to substitute WADAproducts with the name of your own products recordset

  13. Now that you have created a recordset for colors, you also want to create a recordset for sizes.

  14. In the server behaviors panel, select rsColor.

  15. Copy (Ctrl or Cmd + C) and paste it (Ctrl or Cmd + V) back in.

  16. A duplicate recordset (Recordset 1) will be added to your server behaviors panel.


  17. Double click the new recordset to open it.

  18. Change the Name to rsSize.

  19. Go to advanced mode if you are in simple mode.

  20. In the SQL file, change:
    WHERE optiongroups.OptionGroupName = 'color'

    to
    WHERE optiongroups.OptionGroupName = 'size'


  21. Click OK.

  22. When prompted, click rename to rename the recordsets.

arrow downUpdate Add to Cart button

The next step is to update your Add to Cart buttons that you added during the Add a shopping cart tutorial.

  1. To begin updating, launch the Add to Cart button interface by double-clicking the eCart Add from Recordset option in the Server Behaviors panel.

  2. From the General tab, choose the correct cart name.

  3. Select Look up item ID from recordset.

  4. Choose the DataAssist recordset, WADAProducts. This recordset was created by DataAssist and displays all the products in the products database table.
    If you are not using a DataAssist created page, you will want to create this recordset, and then re-enter the Add to Cart interface.

  5. To specify the page you wish the customer to be taken to after adding this product to their cart, click the folder icon and browse to the page. In this tutorial, the page is named cart.php.


  6. Choose the Bindings tab.

  7. Select the color column but instead of binding it to the recordset, check the Updatable checkbox and from the menu list, choose the select list. Set Action to Sum so that the quantity of the item in the cart can be increased, for example, two pairs of blue running shoes.


    You may bind other items such as Name, Description and Price to the proper columns in your Products table (WADAProducts) at this time if they are not already bound. By default, the Quantity of the item added to the cart is automatically configured to be set using a text field placed on the page with the Add to Cart button.

  8. Now select the Button tab. In the Style menu, browse through the 11 different color schemes. Then select the button that fits best with your website's design. You can also choose a form button or specify a custom image location. You can also add an image description in the Alt text field.


  9. Click OK to update the Add to Cart button.
    You will be modifying the Add to Cart button to handle more information in the last step of this tutorial.

arrow downCreate size lookup recordset

The next step is to create the recordset that handles the size price increment.

  1. From the Server Behaviors panel, click the + icon and then Recordset to open the Recordset dialog box.

  2. Make sure you are in Advanced Mode.

  3. In the Name field, enter rsSizeLookup.

  4. Copy and paste the following SQL query into the SQL text field.
    SELECT productoptions.OptionPriceincrement, productoptions.ProductOptionID, options.OptionName, options.OptionGroupID, optiongroups.OptionGroupName
    FROM options
    INNER JOIN productoptions
    ON options.OptionID = productoptions.OptionID
    INNER JOIN optiongroups
    ON options.OptionGroupID = optiongroups.OptionGroupID
    WHERE optiongroups.OptionGroupName = 'size' AND productoptions.ProductOptionID = paramOption AND productoptions.ProductID = paramItem



  5. Under the Variables section, click the + icon.

  6. In the Name field of the Variables dialog, enter paramOption.

  7. From the menu list choose Integer.

  8. In the Value field, enter -1.

  9. Copy and paste the following parameter in the Runtime Value field.
    $_POST['eCart1_1_size_Add']


  10. Under the Variables section, click the + icon.

  11. In the Name field of the Variables dialog, enter paramItem.

  12. From the menu list choose Integer.

  13. In the Value field, enter -1.

  14. Copy and paste the following parameter in for the Runtime value:
    $_POST['eCart1_1_ID_Add']


  15. Click OK.


  16. Click OK.
    In case your select list name differs, make sure that the name entered in the parameter above matches the name you copied earlier.

arrow downCreate color lookup recordset

The next step is to create the recordset that handles the color price increment.

  1. From the Server Behaviors panel, click the + icon and then Recordset to open the Recordset dialog box.

  2. Make sure you are in Advanced Mode.

  3. In the Name field, enter rsColorLookup.

  4. Copy and paste the following SQL query into the SQL text field:
    SELECT productoptions.OptionPriceincrement, productoptions.ProductOptionID, options.OptionName, options.OptionGroupID, optiongroups.OptionGroupName
    FROM options
    INNER JOIN productoptions
    ON options.OptionID = productoptions.OptionID
    INNER JOIN optiongroups
    ON options.OptionGroupID = optiongroups.OptionGroupID
    WHERE optiongroups.OptionGroupName = 'color' AND productoptions.ProductOptionID = paramOption AND productoptions.ProductID = paramItem



  5. Under the Variables section, click the + icon.

  6. In the Name field of the Variables dialog, enter paramOption.

  7. From the menu list choose Integer.

  8. In the Value field, enter -1.

  9. Copy and paste the following parameter in the Runtime Value field.
    $_POST['eCart1_1_color_Add']


  10. Click OK.

  11. Under the Variables section, click the + icon.

  12. In the Name field of the Variables dialog, enter paramItem.

  13. From the menu list choose Integer.

  14. In the Value field, enter -1.

  15. Copy and paste the following parameter in for the Runtime value:
    $_POST['eCart1_1_ID_Add']


  16. Click OK.


  17. Click OK.
    In case your select list name differs, make sure that the name entered in the parameter above matches the name you copied earlier.

arrow downPopulate select lists

The Color Select List was automatically created for you when you created your eCart Add to Cart button. However, we are going to manually create the Size Select List since this list will include a price increment for certain options.

Size list:

  1. Place your cursor where you wish the Size Select List to display.

  2. From the Insert menu, choose Form > List/Menu.

  3. In the name field, enter eCart1_1_size_Add.


    This name is already being used in the recordset you created above. So, in order to ensure this works, you will need to enter the name exactly as it is displayed.

  4. Select the Size Select List you just created.

  5. From the Properties Inspector, choose the Dynamic button.


  6. Click in the Value/Label box and delete any blank entry that could be hiding using the minus icon next to Static options. (This corrects a Dreamweaver error.)

  7. From the Options from recordset field, choose rsSize.

  8. From the Value field, choose ProductOptionID.

  9. From the Labels field, choose OptionName.


  10. Click OK.

    Color list:

  11. Select the Color Select List that was created when you added the eCart Add to Cart button.

  12. From the Properties Inspector, choose the Dynamic button.


  13. Click in the Value/Label box and delete any blank entry that could be hiding using the minus icon next to Static options. (This corrects a Dreamweaver error.)

  14. From the Options from recordset field, choose rsColor.

  15. From the Value field, choose OptionName.

  16. From the Labels field, choose OptionName.


  17. Click OK.

arrow downModify Add to Cart button

Now that we have created and populated the color and size lists, we need to modify the Add to Cart button on your Products Detail page.

  1. From the Server Behaviors panel, double-click the eCart Add From Recordset behavior.

  2. This will launch the Add to Cart interface for modifying the behavior.

  3. Select the Bindings tab.

  4. Select the size column.

  5. Choose the Default value lightning bolt.


  6. Expand the rsSizeLookup Recordset.

  7. Choose OptionName and click OK.


  8. Select the sizePriceInc.

  9. Choose the Default value lightning bolt.



  10. Expand the rsSizeLookup Recordset.

  11. Select OptionPriceIncrement and click OK.


  12. Click OK.


  13. Save your Products Detail page (Ctrl or Cmd + S).

arrow downModify size select list

Now you will modify the Size Select List to inform customers that XL and XXL sizes cost an additional $2. This is done so that customers aren't surprised by the incremental pricing for larger sizes in the shopping cart,

  1. View your Products Detail page in Split view so you can see both the page and code.

  2. Click directly in the Size Select List indicated by red marker.


  3. In the Bindings panel, select OptionPriceincrement and drag it into the code, inserting as indicated in the above screenshot by the yellow marker.


  4. Within the code, add + $ as indicated in the screenshot, adding a few spaces to make the Size Select List more aesthetically pleasing. Note that + $ has been added to the Size Select List.


  5. Save your Products Detail page (Ctrl or Cmd + S) and view in your browser (File > Preview in Browser) where you can choose quantity, color, and size before adding the product to your shopping cart.


  6. By clicking the Add to Cart button, you can review your order on the shopping cart page (assuming the product page was re-directed to the shopping cart page in the General tab). Note the incremental pricing for XL and XXL sizes per t-shirt. Use the Continue Shopping button to make another selection. You can also increase quantity, remove items, clear the cart, update the cart, and proceed to checkout from the shopping cart.

arrow downWebAssist eCommerce series

With eCart technology as the cornerstone of the WebAssist eCommerce series, these in-depth tutorials will walk you through the steps of building an eCommerce site: product catalogs, shopping carts, product options (both static and dynamic), and checkout including payments. Completing the eCart portion of the series is help for setting up a back-end administration to manage your eCommerce business. Additionally, to be used with or without eCart, you will learn about payment gateway providers, hosting solutions, and online shipping accounts.

  1. Introduction to the eCommerce series: An overview of the WebAssist eCommerce series including a detailed description of each tutorial.

  2. Create a product catalog: Learn to create a dynamic product catalog for an online store.

    1. In Create a product catalog I, you will learn if a dynamic product catalog is appropriate for your online store and how to complete the initial set-up.
    2. In Create a product catalog II, you will learn how to create product administration pages, product catalog pages, and order pages for your dynamic product catalog.


  3. Add a shopping cart: Learn about using eCart to create a responsive shopping cart for selling your products online.

    1. Create an eCart object to define the structure of your shopping cart.
    2. Place an Add to Cart button on a product catalog which your customers can use to select items to purchase and add them to their shopping cart.
    3. Design a responsive shopping cart page that holds informational details about the products a customer is purchasing.


  4. Add dynamic product options I: Learn how to add dynamic product options to your website's online store using eCart's shopping cart functionality.

  5. Add dynamic product options II: Learn how to add dynamic product options, which include options within themselves (for example, incremental pricing), to your website's online store using eCart's shopping cart functionality.

  6. Add static product options: Learn how to add static product options to your online catalog store.

  7. Add checkout and administration: Learn how to manage checkout, payments, and the back-end administration of your eCommerce site using the seven tabs in the eCart Checkout Wizard - Settings, Payments, Shipping, Tax, Orders, Email, and Form Design.

    1. In the Settings tab, you will choose the general settings for your site and checkout pages.
    2. In the Payments tab, you will set up payment provider and checkout options.
    3. In the Shipping tab, you will choose shipping providers and set charges.
    4. In the Tax tab, you will set the rules for sales tax or VAT.
    5. In the Orders tab, you will configure your order storage options.
    6. In the Email tab, you will enter your email server settings.
    7. In the Form Design tab, you will select your checkout form from preset designs.


  8. Online payment solutions: Learn about online payment solutions including seamless checkout, remote checkout, and various PayPal checkout options.

  9. Hosting provider solutions: Learn about and choose between five hosting providers, 1&1, GoDaddy, HostGator, Network Solutions, and DreamHost.

  10. Online shipping solutions: Learn where and how to set up free shipping accounts with FedEx, UPS, USPS, and Australia Post.

arrow downReviews and comments

Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.

Sign in to add comments
rating

Robert Crespo: 10 Years, 5 Months, 6 Days, 14 Hours, 6 Minutes ago

Excellent tutorial! My clients website required the price to be increased for very specific products only. After reading through this tutorial I was able to not only achieve the goal of incremental pricing, but I also ramped up my relational database skills quite a bit.

Kate Ford: 10 Years, 5 Months, 5 Days, 3 Hours, 4 Minutes ago

So glad to hear the tutorial helps your business! Thanks for letting us know. Kate

PS Don't miss the other eCommerce tutorials! Links to the entire series are included above.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.