We chose to improve on the standard eCommerce shopping cart programming methodology. Although traditional methods work well, and there are many ways to tackle the same beast, our line of attack was to program more complex multi-dimensional arrays for tracking shopping cart items, quantities, flavors, styles, colors, sizes and other variables for each product. Many inventories are shallow in depth with little more than an item with a description and a price. The need arises when inventory is deep with multiple variables and ranges of values for a singe product.
Take for example clothing items that come in multiple sizes, colors, and have multiple prices. A pair of pants might have 5 sizes and 7 colors. They may also have retail, sale, and discount price types. As well, each price type may have a variant for retail, wholesale and distributor prices. There are other variables than can come into play, depending on the product and the industry.
Starting with the simple sizes variable, a single pair of pants might need to track 7 sizes. This is because a customer might want to buy seven pairs of the same pants, each in a different size. Rudimentary database and programming techniques might setup seven different database records, each with a single size and an associated price. Now, add into the calculations just two prices, retail price and sale price. There are already seven records for the one product, which each need two prices. Now add into the mix a retail, wholesale and distributor price type for different customers. Are you going to create dozens of database records to handle each combination of these variables? Are you going to change dozens of records and juggle the prices, colors, sizes and other factors every time you want to update your inventory? Of course not, and this does not happen with databases and programming that is done correctly. But it outlines the point of needing many variables and values for a single product.
eCommerce shopping carts are simply data tracking systems powered by the PHP server and a back-end MySL database designed for eCommerce. The “eCommerce” part really only comes into play during checkout when a credit card is submitted, the merchant gateway is used to request authorization and debiting of the card, and the payment is rejected or completed. Prior to that, we’re dealing entirely with just a “shopping cart.” It’s simply more common for shopping cart technology to be used for eCommerce than wish lists and data collection methods without payment. Perhaps you might envision a credit based system where no money changes hands, but something is collected into the cart.
So, how does all that data get tracked by the server and the browser? Short of getting into the depths of PHP Programming, Cookies, and Sessions, suffice it to say we use PHP Programming to track collected information and associate it to a specific user, preferably without session hijacking vulnerabilities!
Referring back to the low-end database that generates a record for every product-variable-variable combination and so on, the same mistakes can be made during data collection and tracking. It is less efficient to track a single product with dozens of separate tracking variables. The answer is to use multi-dimensional arrays stored in tracking variables.
Arrays are parseable lists of data that are stored in a single element, called an “array.” Think of an array as a single row in a spreadsheet. Information can be stored in each cell along the row. This would be considered a single-dimensional array. Now add columns to the view and you have a proper spreadsheet as expected. This is like a 2-dimensional array, which means each row is an element, and there are stacks of elements. Well, multi-dimensional arrays are similar to this line of thought, but different.
Taking that single row of data cells in a single element, we can insert an entire row of data into a cell of another row. So, the main row has cells that each contain another row of data. This can be done indefinitely, creating dimensions each time an array is inserted inside the cell of another array.
Arrays are referred to by variable names, which can have multiple “keys” that represent each element. So, an array called “stuff” can have multiple “keys” and each key refers to each “row” of data within the array. So, when we assemble multi-dimensional arrays, we’re inserting an entire “spreadsheet” inside of the cell of another entire “spreadsheet.” This being done iteratively within countless arrays, the result is a multi-dimensional array as complex as the programmers is capable of handling with code.
How do multi-dimensional arrays affect the quality of an eCommerce Shopping Cart? Well, the answer is both simple and complex, so we’ll talk simple. The main array is the shopping cart itself, perhaps called “shopping-cart” and the keys are the product item number, database ID, or some other database tracked value that is specific to the product added to the eCommerce Shopping Cart. That pair of pants above becomes a single array inside a “cell” of the main shopping-cart array, perhaps named “101” and the array for the pants has a name like “large.” Now we have an element that is tracking a pair of Large Pants that has an ID of 101.
The trickiness comes into play when we start tracking the sizes, colors, and price combinations. Each time we apply a new level of variable, we need to create a new dimension in the array, making it deeper in multi-dimensionality. Lets take that Large Pants array and add a price layer. There are three prices, being retail, sale and discount. Granted, these would normally not be tracked in the eCommerce shopping cart, rather checked against the database in realtime during checkout, and each time the shopping cart view is loaded for the customer to edit. We’re using these variables here for sake of explanation.
The main array now contains a pair of pants array called Large. The Large array then contains a set of elements, one for each price type. We’ll use the second price type “discount” for clarity. Now we have three price groups, being regular retail, wholesale, and distributor. The “discount” price element subsequently contains an array with three elements for each price group.
Representing arrays with code is very different from spreadsheets and the representation below. The following is just to represent the layers for non-programmer types. The point to take is that each layer represents a fork in the storage container that can have multiple forks itself.
When the eCommerce Shopping Cart is “deciphered” during checkout, it is easier to associate product requests to their product groups, they can be processed in clearer order, the multi-dimensional array can be stored as-is to the MySQL Database, and so on. The multi-dimensional eCommerce Shopping Cart can be retrieved from the database and reassembled into the tracking system, restoring a customer’s shopping session quickly, and exactly as assembled during their browsing experience.
Multi-dimensional eCommerce Shopping Cart Arrays are not for the weak hearted, the feint of heart, or the beginner. Dealing with eCommerce is serious business and can cause significant loss to the business owner, or create undue hardship on the administrators, if done poorly of incorrectly. The web server used to host multi-dimensional arrays must be tested for processing efficiency. This is from experience, that misconfigured servers can drop the ball when trying to handle multi-dimensional arrays, despite the notion that servers are all the same.
Multi-dimensional arrays can be utilized for much more than just eCommerce Shopping Carts. Any data that should be grouped and cascaded can be tracked this way very efficiently. After using multi-dimensional arrays for awhile, it’s painful to work with a multitude of shallow arrays. The question is not whether multi-dimensional arrays are appropriate for eCommerce Shopping Carts, rather how the deeper dimensionality lends itself for more efficiency shopping cart processing and quality data handling.
If you have questions about multi-dimensional eCommerce Shopping Cart Arrays and how deeper dimensionality can enhance your eCommerce site, call us at 801-253-2564 and we’ll help.