Show quantity in cart on each product_info.php page

On the official osCommerce forum, Will asks;

Does anyone know how I could had on the product page (product_info.php), near the buy it now button, a line of text saying: You have XXXX units of this item currently in your cart.

I didn’t really read the question so gave the advice to use the in_cart class for this. Wrong!

Will then went away and came up with some code to do this, which is like this:

[php]$superid = $product_info[‘products_id’];
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) { if ($products[$i]['id'] == $superid) { $qtyencart = $products[$i]['quantity']; echo"Vous avez $qtyencart unité de cet item dans votre panier actuellement.”;
break;
}
}[/php]

Workable, but ugly and complicated. Here’s my take on getting the same thing, coded to osCommerce conventions;

[php]echo $cart->get_quantity($product_info[‘products_id’]);[/php]

will bring you the number of products in the cart on the product info page. Use this with sprintf to show the text;

includes/languages/english/product_info.php
[php]define(‘TEXT_THE_QUANTITY’, ‘You have %s units of this item currently in your cart.’);[/php]

includes/languages/french/product_info.php
[php]define(‘TEXT_THE_QUANTITY’, ‘Vous avez %s unité de cet item dans votre panier actuellement.’);[/php]

in product_info.php
[php]echo sprintf(TEXT_THE_QUANTITY, $cart->get_quantity($product_info[‘products_id’]));[/php]

Pretty easy!

Get it right, lazy blogger

Over at “Raw SEO” I stumbled across an article about osCommerce, telling us why osCommerce is a nightmare.

osCommerce does have problems and some of them are big ones, but let’s keep perspective on this – here’s my response to this lazy blogger;

1) no separation of logic and presentation

True. osCommerce was first conceived in the late 90’s, hence this problem. There have been attempts to correct this using “template systems” such as BTS and STS, both of which haven’t really grasped the idea. The latest osCommerce goes some way to separating logic and presentation however.

2) difficult to integrate into an existing design

False. It is -very- simple to integrate any design into osCommerce. Remember that osCommerce usually becomes your website, not the other way around.

3) security a) Although it is updated, #1 makes it very difficult to make updates without having to manually open up each .php file and make the changes yourself.

There are a number of good contributions that deal with all sorts of security issues.

b) By default, there is no password protection in the admin section

There has been since RC release of osCommerce, which I believe was released over two years ago.

c) When oscommerce was first built, the latest version of PHP was 3.0. Because of this, old and insecure practices were used to build the core of the system. An example is register_globals.

Explained this one away yourself!

4) cannot have multiple sizes of image previews

False. There are any number of contributions that are multiple image sizes – I’ve even released 2 or 3 of them!

5) admin navigation issues a) hard to do shipping cost per item per country

This is what “zones” postage module is for. There is also a few more contributions that can cover this. In addition, shipping modules are the absolute easiest thing in osCommerce to create!

b) editing product descriptions seems a little awkward.

Clicking a text box, writing some stuff, press update. Awkward? Perhaps you need FCK Editor? A contribution exists for this…

overall, it looks like it was developed for a programmer, rather than a store owner.

Yes, this is true.

Conclusion

Raw SEO’s article is either copied from an older source or the owner of Raw SEO doesn’t know much about osCommerce. It’s lazy reporting at it’s best, either way.

One shipping module to control two shipping methods?

I was set a challenge by one of my clients to set up a method whereby he could use just one shipping module, but offer two different methods of shipping…

For weights under 5kgs he wanted to use Royal Mail.
For weights in excess of 5kgs he wanted to use a Courier Service.

Here is the breakdown in prices;

Royal Mail

0-100g £1.40
101-250g £1.75
251-500g £2.60
501-1Kg £3.25
1-2Kg £4.50
2-5Kg £5.95

Courier

£7.50 for each 25kgs or part thereof (example, a 32kg package would be £15)

How did I do this?

The first step was to quickly create a brand new shipping module. Shipping modules are the absolute easiest thing in osCommerce to work with…I have covered this in the past on this blog. I then hardcoded the “cost” logic in order to test the theory. My hardcoding looked like this (to cover Royal Mail):

[php]if ($shipping_weight <= .1) $cost = 1.40; if (($shipping_weight > .1)&&($shipping_weight <= .25)) $cost = 1.75; if (($shipping_weight > .25)&&($shipping_weight <= .5)) $cost = 2.60; if (($shipping_weight > .5)&&($shipping_weight <= 1)) $cost = 3.25; if (($shipping_weight > 1)&&($shipping_weight <= 2)) $cost = 4.50; if (($shipping_weight > 2)&&($shipping_weight < 5)) $cost = 5.95;[/php] pretty straightforward, a range of weights, with a price attached to each. Thus if the total weight is (say) 1.2kgs, the cost is £4.50 - as 1.2 comes in the weight range "greater than 1 but less than 2"...easy as 123, eh? And like this to cover Courier: [php]if ($shipping_weight >= 5) $cost = (ceil($shipping_weight/25)) * 7.50;[/php]

This is a bit more complicated as I am using the ceil function of PHP. The ceil function rounds up the value of an equation to the next full number. Thus if the total weight is (say) 10kgs, the equation goes like this: 10/25 = 0.4 – this is rounded up to 1 by “ceil”, then it is multiplied by 7.50 to work out the cost. Why 25? If you remember, the Courier charges £7.50 per 25kgs or part thereof…

I then tested a variety of different weights in order to make sure that the breakdown of price points was working. It didn’t work. CRAP! Every weight I tried was 3kgs too much – ahhhhh – I forgot to remove the TARE weight. So, I set it to zero and tried again. not working! CRAP! Everything was 10% too high – ahhhhh – I forgot to set the % increase to zero. Tried again – now it’s working!

Now, because I had hard coded all the weights and prices directly into the shipping module, it would make it very hard for the shop owner to update. He’d have to know which file to FTP, amend the figures correctly, then re-upload it. So I set out to store the weights and prices in the database – and create an easy to administer form where the shop owner can update whenever he needs to.

This is actually fairly simple, and is done by adding extra database queries in the shipping module, like this:

[php]tep_db_query(“insert into ” . TABLE_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values (‘Max Weight For Iteration 1’, ‘MODULE_CODPK_SHIPPING_TABLE_COST_ONE_WEIGHT’, ‘0.1’, ‘Iteration 1 – Max Weight’, ‘6’, ‘0’, now())”);
tep_db_query(“insert into ” . TABLE_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values (‘Price For Iteration 1’, ‘MODULE_CODPK_SHIPPING_TABLE_COST_ONE’, ‘1.40’, ‘The shipping cost for Iteration 1’, ‘6’, ‘0’, now())”);[/php]

The important bits are these; MODULE_CODPK_SHIPPING_TABLE_COST_ONE_WEIGHT and MODULE_CODPK_SHIPPING_TABLE_COST_ONE which is what I will use to determine the max weight for a price. Repeat for as many price breaks as is required!

Then recode the cost section as so;

[php]if ($shipping_weight <= MODULE_CODPK_SHIPPING_TABLE_COST_ONE_WEIGHT) $cost = MODULE_CODPK_SHIPPING_TABLE_COST_ONE; if (($shipping_weight > MODULE_CODPK_SHIPPING_TABLE_COST_ONE_WEIGHT)&&($shipping_weight <= MODULE_CODPK_SHIPPING_TABLE_COST_TWO_WEIGHT)) $cost = MODULE_CODPK_SHIPPING_TABLE_COST_TWO; if (($shipping_weight > MODULE_CODPK_SHIPPING_TABLE_COST_TWO_WEIGHT)&&($shipping_weight <= MODULE_CODPK_SHIPPING_TABLE_COST_THREE_WEIGHT))$cost = MODULE_CODPK_SHIPPING_TABLE_COST_THREE; if (($shipping_weight > MODULE_CODPK_SHIPPING_TABLE_COST_THREE_WEIGHT)&&($shipping_weight <= MODULE_CODPK_SHIPPING_TABLE_COST_FOUR_WEIGHT))$cost = MODULE_CODPK_SHIPPING_TABLE_COST_FOUR; if (($shipping_weight > MODULE_CODPK_SHIPPING_TABLE_COST_FOUR_WEIGHT)&&($shipping_weight <= MODULE_CODPK_SHIPPING_TABLE_COST_FIVE_WEIGHT))$cost = MODULE_CODPK_SHIPPING_TABLE_COST_FIVE; if (($shipping_weight > MODULE_CODPK_SHIPPING_TABLE_COST_FIVE_WEIGHT)&&($shipping_weight < MODULE_CODPK_SHIPPING_TABLE_COST_SIX_WEIGHT))$cost = MODULE_CODPK_SHIPPING_TABLE_COST_SIX;[/php] and [php]if ($shipping_weight >= MODULE_CODPK_SHIPPING_TABLE_COST_SIX_WEIGHT) $cost = (ceil($shipping_weight/25)) * MODULE_CODPK_SHIPPING_TABLE_COST;[/php]

Now, deactivate and reactivate the module and it is possible for the Shop Owner to set up a range of 6 weights/costs for Royal Mail and 1 cost for Courier.

Sweet! Then I thought it would be extra nice to differentiate between whether the order is going to be sent by Royal Mail or by Courier.

So, I added this:

[php]$way = “Royal Mail”;[/php]

and this:

[php]$way = “Courier”;[/php]

at appropriate points in the module. Then I changed this line of code:

[php]’title’ => MODULE_CODPK_SHIPPING_TABLE_TEXT_WAY[/php]

to

[php]’title’ => $way[/php]

and now everything works as it should do. The weights and costs work out correctly and both the client and the shop owner can see if the order should be sent Royal Mail or Courier.

New Template Available for RC osCommerce

I spent some time creating a template for RC versions of osCommerce. I’m going to sell this at the same sort of price that Template Monster sell their templates for…but read on to learn how to get this template “at no cost”…

Overall Idea of the template look

The header area includes;

  • search box
  • language flags
  • currency selector
  • cart contents

Then I have used jQuery to rotate a few images (in the template I rotate between some adverts for my oscbooks.com site, but you can change these to anything you wish, of course!). I also created a funky logo – which you’ll probably want to change before using on your live site.

I then added a few buttons underneath (home, new products, my account etc).

In the sidebar I stripped out a lot of boxes to only leave navigation – you can add boxes back in really easily – just amend the column file. I amended the categories box substantially to only show top level categories with a nice design;

In the image, the current category is the one with the grey background…nice and easy to see where you are, I think.

I also wanted to draw your attention to the product listings. I’ve recoded a number of them to look as much alike as possible. So they mostly now look like this:

Much better I think. This layout is standardised across a number of files so it looks decent!

Conclusion

All in all I’m pleased with how this design turned out. I used the exact same methods as can be found in one of my best selling osc books – designing oscommerce – so, if you want to learn how to make good looking sites, take a look at my oscbooks.com website!

Special Offer

Do you like this template? I’m going to sell it at $175. However for anyone who purchases the designing osCommerce eBook before friday, I will send you this template absolutely FREE OF CHARGE on sunday of this week.

Look, you won’t find a professionally coded to osCommerce standards template hardly anywhere – especially for “free” – so do yourself a favour and buy the “designing osCommerce” eBook before friday – then on sunday you’ll get this template at zero cost. After friday, you will pay $175 for the template alone. So save yourself $175 NOW…

Got questions?

Fire away.

call api in checkout process of oscommerce

Schilt asks;

Dear Sir, how do I go about to solved below problems ?…thank you in advance

Fatal error: Call to a member function call_api() on a non-object in /home/ /public_html/shop/checkout_process.php on line 127

call_api() is a function that tells your checkout_process to do something. call_api() is not a standard part of the checkout_process.php file, so it must be something that you (or someone else) has added (eg a contribution).

I had a quick look and see that “buy safe” uses a call_api() function so this would be your first clue as to what you ahve done and how to fix it.

So how should you fix it?

Try to remember the changes you made to add this call_api() in, and reverse the changes – in other words: uninstall!

osCommerce Makeover Service – price increase

My Makeover Service is proving to be a big hit so I am putting the price up from $200 to $250 with effect from today, 1st July. However, for anyone who orders this service until friday, I will charge the $200 price.

You can read more about my makeover service. I’m doing 10 or 12 of these per month, and really it’s the same price as you pay for a template from the like of Template Monster – but what you get with my makeover is a uniquely designed site that only you have – rather than some poorly coded piece of rubbish that perhaps 1000 other stores are using!

My latest makeover

The latest makeover I made went from a standard grey osc shop to a much nicer looking shop. I recoded a number of the modules to make them standardised throughout the shop (eg the new_products contentbox is the same theme as the specials.php page, which is the same as the what’s new infobox and so on). I recoded the categories box to output nicely, without subcategories. I then removed a column and added some things in the header area (shopping cart, languages, currency selection). Also added the logo across the header along with a language dependent banner and the search facility. Then I came up with a whole new colour scheme for the site. It turned out really well!

Here’s an idea of the new look;

So, how do I do the work?

First step is for you to make a deposit of 50% – I then book out a full day in my diary. I ask you for any sites that you like the look of and for your prefered colour scheme. I download your site and make a mirror on my localhost and then make the necessary design changes to your files. Once complete I upload ONLY the changed files to your live site – now your new design is LIVE!

In this way I can ensure that there is ZERO downtime on your live site and I can ensure that any contributions you have already loaded are not affected by my changes! You now pay the remaining fee. After about a week, we (that’s me and you, the client) revisit the site to see if you want any changes made.

Interested?

Email me on oscshops@gmail.com – and remember the $200 price is good until friday.