Home Delivery Shipping Module 2.3.1

One of my good clients contacted me to see about having coded a shipping module that;

– available for DK clients only 1
– available only to certain postcodes within Denmark (those near the customers real shop, to be delivered by car) 2
– ability to add further away postcodes at a higher price 3

Within a couple of hours I had the basis of the code in place, it has now been tested and seems to work well;

1. Hardcoded, but can easily be changed to react with the STORE_COUNTRY.

2. Insert the Zipcodes as a comma separated list.

3. You need more zones, just increase the number of zones in the module.

which gives extra inputs in the Admin area.

In real use;

A. A Zip that is not configured as a deliverable zip;

B. A Zip that is close to the Store (Zone 1);

C. A Zip that is further away (Zone 2);

Customers Who Bought This…

I was approached by a new client who uses osCommerce both as a shop and as a sort of “community”. What this client wanted was a way to show who had bought each product…

Step 1, was to add the ability for clients to add an “avatar” as part of the create_account process.

Step 2, was to code up a module to show on each product page, showing each person (who bought the item) avatar.

Easy as 123 to get something quite basic up and running.

Step 3, is to code up a way for the customer to change/delete their avatar. The best place for this is in the account_edit.php page – but this is something for the future as the client is quite happy with the code as is (at the moment).

Shipping Prices per product (for two regions) UPDATE

The project I started on for a client (read a bit here), worked well. The client came back to me with some extra requirements, namely;

1. Give each product an “extra cost” per region. To be used when people order more than 1 item, thus a widget costing $5 for postage with an extra fee of $2, would charge $7 for postage if the buyer ordered 2. And so on.

2. This to be done per product, per region.

3. Postage only to charge the HIGHEST postage cost + any extras.

Well, I have to say this complicated matters and took some thinking about!

Step 1 was to add the extra inputs in the admin – category – product (adding/editing) page, along with the relevant database changes;

Step 2 was to recode the shipping module I built to get the MAX value of an array. This array created by the costs of the postage (in the above image “HOME Shipping Cost” / “ROW Shipping Cost”).

Step 3 was to recode the cart class to enable the cart to keep track of the “extras” cost.

Now I have all the info needed to make sure that the shipping charges correctly. I’ve tested this to destruction and cannot break the calculations, so I am happy to make this live on the clients site – whilst also advising him to keep an eye on the shipping costs charged and let me know of any problems.


In the example above, the cart holds 1 hoodie (charged at $5 + $2.50 for extras) and 3 tshirts (charged at $2.99 + $1.25 for extras). So the total postage charge is;

1 Hoodie @ 5.00
No extra charge for Hoodies as only 1 purchased.
No postage charge for T-shirts, as the Hoodie postage charge is higher.
3 extra postage charges for the tshirt @ 1.25 * 3

$5 + $1.25 + $1.25 + $1.25 = $8.75


Hope that anyone reading can see that pretty much anything is possible with osCommerce. The 2.2 and 2.3.1 versions of osCommerce are loosely coded, so it is easy to make the changes to enable whatever it is that you need to do. The v3 osCommerce will be harder to code for, but only because the code is so much more structured.

Interesting Project – File Uploads

Finished up another interesting osCommerce project this week, which involved allowing the shop owner to put a “flag” on a product. This flag determines whether the product requires interaction from the customer in terms of an upload (think in terms of an image for a printed t-shirt).

Step 1 was to add in the flag capability. Easy, I simply added an extra column in the category structure, along with the relevant DB changes.

Step 2 was to add in the upload facility in the account_history_info.php page. There is a contribution that allows file uploads from the product_info.php but this was unsuitable as the site already has too much complications in contributions – QTPro, different attributes and so on.

When the files are chosen, they are uploaded and show in the page;

Step 3 was to allow the Shop Owner to grab the files, make the product and use the order.php page as so;

to uploads images of the product;

At this point, Shop Owner emails the client asking him/her to log in to the account_history_info page.

Step 4 the account_history_info page shows the two client uploaded images and the two admin uploaded images.

along with “Fancy Box” popup to show the two admin images larger;

At this point, the client can “approve” the product, or “reject” the product – and tell the Shop Owner why.

If the product is rejected, the Admin/order shows this;

The Shop Owner makes the corrections, and uploads the images of the new product using the orders page. The customer can now see the new product and can again “approve” or “reject”;

This time, the product is perfect, so the customer “approves”.

The Shop Owner can now send the product to the customer.

As you can see, quite a big task, and fiddly to get right. This involved changes across multiple files, though the two main files changed are admin/orders.php and account_history_info.php

A very nice project to work on, and I am very pleased with the end result. As is my client;

….you did a great job….

Stock Taking, jQuery, Reporting

Last week a new client approached me to help out with an admin function within her site. Here’s the basic idea;

Each Order received has a tickbox by the product:

The tickbox would update an entry in the database to state whether the product is “in stock” (1) or “out of stock” (0). The system worked well, but was coded as part of the form so needed the [update] button to be pushed. That’s not a massive big deal, but it’s an extra step that might get forgotten by the data entry people and so on.

Once the days orders of products had been “ticked”, a report is run to show the shopwoner what needs to be ordered from her suppliers and what she has already on hand. This was already coded.

The client had attempted to make the checkbox fire automatically using javascript, but had come to a dead end – which is when I was contacted.

The brief (in brief!!)

Make the checkbox fire automatically, to update the database entry on a per product, per order basis. Make the table row highlight if the checkbox is ticked.

The solution

Firstly, I tried to use the customers existing javascript code, but after a couple of hours was just going around in circles trying to make sense of what was happening. I gave up on that, and rolled my own.

The first step was to get it all working on a new RC2 (note that the client does not yet run 2.3.1, though 2.3.1 and 2.2 are very similar in most resepects especially in the admin area). I installed rc2 and amended the orders_products DB table to hold a tinyint flag saying 0 or 1 for stock purposes.

I then added a checkbox for each product ordered, the result looked exactly the same;

Next up, I coded up a .js file which (on checkbox tick) reads the value of the checkbox (1 or 0) and the value of the product ID and the Order ID. It then uses the ajax function of jquery to open a standalone php file which takes those inputs and updates the database accordingly. The .js file also fires off a css update using addClass to highight (or un-highlight) to row affected (which means anyone doing data work, can straightaway see what has been changed);

And no need to press the update button any more.

My osC site – create_account.php

In my own oscommerce site, that I have been working on for about the last year as time allows, I decided to do away with the need for the clients address. I don’t need the address details as I sell only intangible products such as scripts and templates…

So, I have been locally testing a new create_account page, which looks like this;

As you can see I only have name, email, company, password. This should help to stop abandonment of carts.

I also coded up a quick and easy password generator – if the buyer clicks “or Random”, then a random password is made, inserted into the two boxes, and a message appears;

Once the person has created the account, no addresses show anywhere. This presented a bit of an issue as checkout_shipping depends upon having an valid address in order to work out postage costs. No problem for me as I do not charge postage – so simply setting the order_type to virtual skips the problem.

Next up, I had to change the address format in the database, to show only the name and company. And change some internal pages (such as checkout_confirmation) to not show the addresses (usually shows billing address and delivery address).

You’ve added XYZ to your cart

For the build I’ve been working on for the last couple of days, a really nice feature is a message that shows when the buyer adds something to their cart. Basically it’s a reinforcement of the action they just took;

Let me know what you think.

The code is based on the last added product ID in the cart item list array. I had to create 1 function to grab the product model to get it working as I wanted.

In the video you might also notice a kinky “Best Sellers” box – I might blog about that tomorrow.

osCommerce Previously Purchased

Contacted today by someone who wanted the ability to show customers what they have already purchased (whilst browsing the site). In other words display a “You have already purchased this” warning message at the top of the product info page etc etc.

The first thing to know is that we need to have the customer logged in as without their customer ID there is no way to grab the needed information.

The next thing to know is that we need to join together two database tables; orders & orders_products

It’s really very straightforward;

1. customer logs in
2. we join the orders and orders_products table and grab the needed product IDs of the already purchased items
3. we place these into an array
4. we check the product Id whilst the customer is browsing the store, against the array. If the numbers match, show the message

All in all, this was 10 minutes work to get a viable solution. Of course, it could be cleaned up and made better (eg, show the “you’ve bought” message elsewhere such as the shopping_cart page, or in the products_new module etc), but for now all that is needed is the message on the product_info.php page, and it works OK.

Easiest install ever! FCK Editor

3 steps to installing a WYSIWYG (What You See Is What You Get) editor for product descriptions in osCommerce.

Step 1. Go to ckeditor.com and download the latest Editor Release (CK Editor, which has superseded FCK Editor)…

Step 2. Unzip it all, then upload the fckeditor folder and all it’s contents to your admin directory.

Step 3.
2.2 and older: Amend admin/categories.php
2.3 and newer: Amend admin/includes/template_top.php

Find this:
< script language="javascript" src="includes/general.js" >< /script >

Add after it:
< script src="ckeditor/ckeditor.js" >< /script >

Amend admin/categories.php

Find this:
tep_draw_textarea_field(‘products_description[‘ . $languages[$i][‘id’] . ‘]’, ‘soft’, ’70’, ’15’, (isset($products_description[$languages[$i][‘id’]]) ? stripslashes($products_description[$languages[$i][‘id’]]) : tep_get_products_description($pInfo->products_id, $languages[$i][‘id’])));

Change it to this:
tep_draw_textarea_field(‘products_description[‘ . $languages[$i][‘id’] . ‘]’, ‘soft’, ’70’, ’15’, (isset($products_description[$languages[$i][‘id’]]) ? stripslashes($products_description[$languages[$i][‘id’]]) : tep_get_products_description($pInfo->products_id, $languages[$i][‘id’])),’ class=”ckeditor”‘);

Upload it and refresh the category (prodcut adding/editing) page. You should see the newly installed Editor looking like this:

Easy as 123…now go and use underlines, bold, colours to make your product descriptions really stand out 😉

Sneak Preview at Discount Coupons v6

Just a couple of screenshots to whet your appetite;

I’ve restricted the 2 “graphic card” products to be excluded from the discount calculations…

So, assuming the customer now buys a couple of products including an “excluded” product, the shopping cart looks like this:

Notice the calculation is correct? It’s discounting only the “Beloved DVD” and not the “Matrox g200″…

And the end of the checkout confirmation looks like this:

Notice it’s discounted only $22 (which is 40% of $54.99)…obviously in the example I used a 40% money off coupon code.

And in the Admin area, the invoice shows like this:

I am still testing this and I have already noticed a couple of areas where the new v6 coupon code could do with a little tweak. No release date as yet…but it is coming soon.