The key to making it work with the size and color options is to first ensure that you are tracking the inventory for these items in regards to the options offered. With an update similar to the one that you are using now you can check if the item has these options and if so use an update specific to these types of items, otherwise use the update code you are already working with.
This is a custom implementation that we won't be able to offer any detailed support for.