O'Reilly logo

Professional CodeIgniter® by Thomas Myer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.5. Reworking Colors and Sizes for Products

Reworking the way you're handling colors and sizes takes quite a bit of work. Ideally, you want to avoid these kinds of changes, but sometimes it is inevitable. This change has been left in here on purpose to show you how to handle this kind of situation in real life.

As you'll see, there's no need to panic, because CodeIgniter is flexible enough to let you rework just about any change, no matter how complex. Before you jump in, though, it's definitely worth the time to write out a list of all the changes that need to be made.

You will need to:

  1. Create two new database tables, one for colors and the other for sizes. A good suggestion is to keep them simple, with ID, name, and status fields. You will also need mapping tables to store individual settings for each product.

  2. Delete any references to the old product color/size fields. (Don't forget the MProducts model!)

  3. Create two new models for your new tables, with simple functions that allow you to retrieve, add, edit, and deactivate colors and sizes.

  4. Create the administrative functions for both colors and sizes.

  5. Add color and size checkboxes to the product create/edit views.

  6. Use the information in the mapping tables to display color and size data on the public side of the Shopping Cart.

Let's get to work.

7.5.1. Creating New Database Tables

You need to create four tables: colors, sizes, products_colors, and products_sizes. The first table, colors, has three fields: ID, name, and status.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required