Choose your own selection project

A guest post from Matt over at www.sweetnessandlight.com – purveyor of chocolate and other goodies.

Selecting a bunch of products to create 1 overall product

When you need your customers to be able to choose from a variety of products to create one final product to add to their cart, you will find that the basic osCommerce comes up quite short.

An example of this was on my own shop: I needed customers to be able to choose from a selection of items to create their own chocolate assortment box. The items they are choosing from are other products on the site which had to be turned into attributes. Those attributes also had to be able to be chosen in quantities. The total amount they can choose is is determined by you when you setup the products in your admin.

Two of the neat things with this project are:
1. The attributes can be chosen in quantities (not standard osCommerce which allows you to add only one of any given attribute per product added to cart).
2. The attributes have an image and description so the customer can see and read about what they are choosing.

As the customer is choosing options, the drop down menus count down along with them. If all the dropdowns start at 15 and they choose 2 of an attribute, all the other drop downs on the page repopulate with 13 and so on until 15 attributes have been chosen. This is done through javascript and there is also a counter at the top of the page so the customer can see how many options are left until they are done. It all gets a little confusing so here is a video to demonstrate the feature:

This project was very in depth and changed lots of things in the shopping cart and order classes. It also did a pretty good overhaul of the attributes system. This type of thing could be used in all kinds of different shops and is only limited by your creativity. Almost anything is possible with osCommerce! Thanks Gary for working so closely with me to get all the bugs worked out and helping me bring my thoughts into reality.

Gary says…

The project was very complicated – and as such needed a good base to work from. Between us we managed to get a wireframe working example based on a new osC 2.3.1. Because Matt had made many changes to his 2.3.1, we then needed to somehow fit it into his existing code, which was not easy at all. In the end though, we’ve come up with a system that has already allowed Matt to expand his online sales, and give his customers a really nice feature that no other osCommerce shop has.

Open a different box by default in Admin

Really short post as this is so simple.

When you open the osCommerce admin, the “configuration” box is open by default. This is because it is at the top of the boxes list. If you place a different box on the top of the list, that one will be open by default instead.

Easy as 123. To do this, open up admin/includes/column_left.php and move the line of code that displays the box up to the top. Eg, move

include(DIR_WS_BOXES . ‘customers.php’);

to right underneath

$cl_box_groups = array();

But…what if you want to keep the box order as is (NOT move any lines of code), and just have the customers box open as default?

Again, easy as 123. Count from ZERO until you get to the box you want open. Eg, in a standard install of osCommerce, the customers box is number 3. Open up admin/includes/column_left.php and add the following code;

,
active: 3

right after;

icons: {
‘header’: ‘ui-icon-plus’,
‘headerSelected’: ‘ui-icon-minus’
}

Now the boxes are as they were, but the customers box will be open by default instead of the configuration box.

Sort Shipping Modules by cost

Sorting the shipping modules is simple in osCommerce – just amend the sort order in the admin area. This is fine to do and works well.

I was recently approached to come up with an idea to sort the shipping modules based on the cost of shipping. This is much more difficult if the shipping modules are dynamic (eg, zones.php, table.php and so on).

With some lateral thinking I managed to come up with an idea and got some code that works;

This simple setting sorts the shipping modules by cost!

If the setting is “False”, then the modules look like this:

And if “True”, then this:

Conclusion

The main issue is that it is impossible to sort based on any type of sort_order via the admin IF the shipping module produces a dynamic price, that is a price that changes based on the value/weight of the order.

Import Customers

I have been working on a script which imports customers into osCommerce, based on a spreadsheet of customer details. It’s a little difficult as the customer data is patchy and I’ve had to write some custom functions to get the ID of the customers country and so on.

The reason for writing this is to save the shopowner from manually adding 3700 customers! This would take too long. So, I wrote a PHP script which reads a spreadsheer (90% of my work seems to be using CSV files!!), and it seems to work good – 90 lines of code which imported 3700 customers (including address book) in around 40 seconds => saving my customer weeks and weeks of data input.

Script is completely useless for any other shop owner, as it is set up to read his spreadsheet columns. But the same can be accomplished for anyone else wishing to import many customers in one go, get in touch.

Hazmat Module updated for oscmax 2.5

A long time ago I wrote a Hazmat module which allows the shop-owner to add a charge for shipping hazardous material. You can read more on this blog post from over a year ago.

At the same time, I recoded it to suit osCmax as a few of my clients use oscMax. At that time osCmax was pretty much osCommerce 2.2 with a few extras. Fasty forward 18 months or so and osCmax2.5 has been born. It is still pretty much osCommerce 2.2 with a few extras, but there have been some developments in what has been added. The two main things being QPBPP (Quantity Price Breaks Per Product) and a 1 page checkout.

These two additions change the way in which osCmax works quite a bit. They add some extra complexity behind the scenes, particularly QPBPP (which is a useful addon, but changes too many core files).

For this reason I had to recode the Hazmat Module…to deal with the changes. And pleased to say that it works well.

Thoughts on osCmax 2.5

Code is stuck at 2002. It’s 2012 now, so the underlying codebase needs to be updated desperately. The main problem is that oscMax is full up with other peoples addons, which (being honest) are sometimes not of a good enough quality to make it into core code. Michael needs to step up to the plate now, and serve something better than outdated tables based code. Time to fork osCommerce 3…

Shipping Module powered by CSV

Approached recently to quote for building a shipping module, powered by a CSV file.

The CSV file

Contains 4 pieces of information;

postcode, shipping_cost, amount at which shipping becomes free, courier name

The CSV file can consist of thousands of such entries.

Shipping Module (Shop)

This reads the CSV and outputs the necessary information;

Shipping Module (Admin)

Is pretty much the same as any other shipping module. Other than the store owner can set up a “default” courier, cost etc just in case the postcode cannot be found in the CSV file.

All in all, quite a nice little project!

I’m pretty sure that this will (at some point) make it into the addons area at osCommerce as this client specifically required the files in a format that would allow him to contribute it.

The Cherry on the Cake

How about a little feature in the shopping_cart.php page to show a shipping estimation? Well, that was done as well;

Here you can also see the message that it’s only another $50 or so to get free shipping…

Video in Action

NoIndex Header Tag Module

Sometimes you might want to have Google and other (are there any other?) search engines not show certain products in your site. This is where noindex is worth some value. Have a read of this Google Support page.

With that in mind, we know that any page with noindex will eventually be removed from the Google results pages. It might take some time, but it will happen when the Googlebot hits your page and reads the noindex tag.

Took me all of 10 minutes to code up a quick and easy mod to enable shop owner to set each product to index or noindex. Default is, of course, index!

Admin side:

An extra red/green selector;
red = noindex
green = index

Shop Side;

No outward change, but looking at the underlying code of the page, this is added if a product has that red selector;

This is done using a Header Tag Module

The benefit to this is that these modules are drop in, so there is not any need to amend the code of the product_info.php page.

Be aware that some people giving advice at the osCommerce sell SEO services and therefore are going to try to confuse the hell out of you by spouting shite.