Admin Star Rating System

So, got an email from a potential client who wants to be able to make star ratings on a per product basis from within the admin;

I will like only myself (the admin or owner of the website) to grade the items that I’m selling with stars or with numbers. Let’s say that i have 5 stars icons and if the item is in good condition I will light up or show the 5 stars if it not so good maybe only 4 stars, and so on

So, I came up with a simple system.

In the Admin area;

As the only star rating is made by the shop owner, the only database entry is a single vote (0 or 1 or 2 or 3 or 4 or 5), so an “int” added to the products table is quite enough.

In the shop side;

Draw the value from the database and show a nice graphic.

Files changed were;

  • admin/categories.php (and language file)
  • product_info.php

And a few new files to show the stars.

Conclusion

And the cost for all this was just $75, and the time to get it from initial email to finished and working was less than a couple of hours. As you can see, it is sometimes preferable to pay a little amount to someone who can easily come up with code, than to waste a day or two trying to work out how to do something yourself.

Warehouse Pick n Pack

Had email from a previous client yesterday who wanted the ability to list the items ordered for the previous day, but grouped by items. The reason for this is to get the warehouse staff to easier collect the items to be posted.

So, instead of a list like this:

1 x dvd-tsab
2 x msimexp
1 x dvd-tsab
1 x dvd-tsab
3 x msimpro
1 x msimpro

It would list like this;

4 x msimpro
3 x dvd-tsab
2 x msimexp

I quoted on the project, but the client found some base code to work with. I requoted on the project and am awaiting reply.

In the meantime, I continued to make the new module, which now looks like this;

Here you can plainly see that I list the orders, and at the side a combined list as required for picking and packing. Then I thought to add two extras;

1. a date picker, so that the shop owner can also look at other dates to be picked and packed.
2. a status chooser to drill down the items (they might already have been picked and packed for example).

In my testing, it seems to work quite well. I don’t know how useful it could be to the majority of shop owners.

Video

Turn off Payment method based on currency used

Had an email overnight from an osCommerce user who needs to turn on and off payment methods based on what currency is being used in the checkout. I thought I had covered this already in the blog, but could not find it. So here we go;

1. Add an extra input to each payment method used

This allows us to add a list of currencies supported by the payment method.

As you can see in the example above, I have set the currencies to GBP (British Pounds) and EUR (European Euros).

Code changes (taking cod.php as the example):

Find:
function install() {

Add an extra line of code, as so:
tep_db_query(“insert into ” . TABLE_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values (‘Currencies available for this payment method.’, ‘MODULE_PAYMENT_COD_CURRENCIES_ACCEPTED’, ”, ‘Comma separated list of accepted Currencies.’, ‘6’, ‘0’, now())”);

Find:
function keys() {

Add:
‘MODULE_PAYMENT_COD_CURRENCIES_ACCEPTED’,

After:
‘MODULE_PAYMENT_COD_ZONE’,

Turn off the COD module if you already have it turned on. Turn it on again to reset it. You now have the necessary input box to allow you to add the currencies acceptable.

2. Turn the module off if an unacceptable currency is used

Still working on cod.php ….

Find:
// disable the module if the order only contains virtual products

Above this, add:
[php]// disable the module based on available currencies
$good_currencies = explode(‘,’, MODULE_PAYMENT_COD_CURRENCIES_ACCEPTED);
if (!in_array($order->info[‘currency’], $good_currencies)) {
$this->enabled = false;
}[/php]

Here, we create an array of acceptable currencies using explode. We then compare the currency being used to those acceptable currencies. If the currency being used is NOT found in the list, then the module is turned off.

Easy as 123.

You would need to do similar for every payment module that you use. Make sure to change this: _COD_ to reflect the name of the module you are amending.

List of Product Ordered for seasonal promotions

At the osCommerce forum, Heather asked;

What Im basically looking for is a list of customers against what products they ordered, some of my products are seasonal, and I want to be able to email the customers that bought them last year to remind them that they are in stock again.

Ideally:

Product + Customer + email address

My answer was to use phpmyadmin, and run the following SQL query;

[php]SELECT DISTINCT op.products_name, o.customers_name, o.customers_email_address
FROM orders o
LEFT JOIN orders_products op
ON o.orders_id = op.orders_id
ORDER BY op.products_name[/php]

I didn’t test it, but Heather returned to the thread to advise it worked as she wanted it. I’m not all that great at SQL stuff, so was hoping it worked out OK.

Basically, the SQL query is interrogating two osCommerce tables; orders and orders_products. From orders we are getting the “customers name” and the “customers email address”. From orders_products we are getting the “products names” ordered, but because we placed a DISTINCT on that, it only returns one rather than many (as there is no point knowing that Mr XYZ bought 3 of the same item!). Then we link the results from the two tables together, based on the orders_id (which is the same integer in each of the two tables). And finally we present the results ordered by products name.

So, in a real life situation, the output from phpmyadmin would look somewhat similar to this;

Please note I blurred out the email addresses in my graphics program.

What’s next?

I’m thinking that this (obviously with a few amendments) could be made into an automated script, which is run on a daily basis. This script would email each customer to let them know that a year ago (or a month ago or whatever) they ordered XYZ product, and it is now time for them to order again. Completely automated with no additional work needed from the shop owner. Probably make a really good addition to osCommerce, though I guess most shops don’t sell seasonal products?

Facebook “LIKE” on your osCommerce shop

Jan asks;

possible to put the new like button on osc

Yep, and it’s super simple, using this quick and dirty code.

Step 1: Add this code to your header, footer, or wherever you want the like button to show;

[php]here.

Step 3: Add this code to the bottom of either /includes/footer.php (pre rc3) or includes/template_bottom.php (rc3), making sure to substitute “your app id” with your actual app id;

[php]


[/php]

Done.

Code needs to be cleaned up for real use, but this should give you enough of an idea to be able to do what you need to do.

osCommerce Style Sheet? Use Colorzilla Firefox.

Sean asks;

I’ve got a bit of trouble with editing the colours in stylesheet.css.

I don’t have a problem with hex colours or even putting them into the stylesheet, my problem is I don’t know which bit is which. Is there are a chart or something where I can refer to different bits of the oscommerce main page with the code that controls the colors for it?

Really easily, assuming you are using Firefox, or can install Firefox. Use the “colorzilla” plugin, which allows you to point at an area of the page and it will tell you what .css is being used.

In this image, you can see that the red outlined area, is made up of a td.smallText (look at the bottom grey browser bar) – and so this (smallText) is what you would change in the stylesheet to affect the style.

Search Engine Optimised URLs for osCommerce

Dave asks;

Which URL rewriting contribution do you recommend?

I get asked this question quite often. In my opinion, there is just two decent versions of URL rewriters, depending upon whether you have PHP4.x or PHP5.x

If you are running PHP4.x ;

Ultimate SEO Urls – click on the “history” tab and find the version by FWR Media, dated 12 Jan 2010.

If you are running PHP5.x ;

ULTIMATE Seo Urls 5 – by FWR Media

There is also a “Pro” version of #6768, but I am not sure if this has been publically released yet.

Open Source is all about choice

Josh commented;

First, thank you for the original 1.12 contribution [of discount coupons]. It is a very simple, and very easy to follow install. I have been reading for hours all over your site, mostly about the contribution, but I tend to go off on tangents when I see other topics of interest (like the trademark issue).

Anywa, like I said, I’ve been reading about your contribution all day, mostly on your site. What I don’t understand is your attitude (please don’t take offense, it’s the only word I could think of) towards sharing your code. I consider myself an intermediate php programmer, with intermediate oscommerce skills and knowledge (far from advanced on both accounts), so I don’t understand why you keep telling people “I have new great code, and you can buy it, but only if you give me access to your installation and let me install it myself, I will not let anyone else install it.”

The only thing I can think of is that it’s a support issue and you don’t want to answer the hundreds of questions that are bound to follow when you give someone the code and let them try to install it. But I’m with Tai Kahn when I say that I would not want you (or anyone else) installing anything into any of my websites. You made a (what I took as, sarcastic) comment to him (above) saying “when you are ready to start trusting, come back”, but I think that’s a poor attitude for someone who keeps mentioning “paying projects” in many of their blogs (and comments).

If someone like Tai or myself were willing to pay you the same rate that you’re charging to do the install, for simply emailing us the code, why would you scoff at that? Why can’t you simply make the sale with the simple condition that you will not offer any help installing it? I’m sure if the new contribution is as easy to install as v1.12, you wouldn’t hear any more than “thanks” from people who are confident that they can install it themselves.

Now, instead of just buying your code, I’m going to have to take hours to modify v1.12 code to do what you’ve already written. If this was an issue of money, I could understand, but it doesn’t seem to be, so I really don’t understand your point of view. Can you please explain it to me (and everyone else who reads this? In fact, I think this would actually be worthy of getting it’s own blog topic. I’m sure you have many readers who don’t read every blog and all of their comments, so making this a new blog topic would make it visible to everyone.

Again, thank you for the original contribution that you were actually willing to share.

Josh, no offence taken, and I hope you will not take offence at my answer and understand my viewpoint…

Open Source is all about choice. I’ts my choice to relese code in any way I see fit. As you already know the v1.2 is a very simple install – yet I get between 5 and 10 support requests daily…if I go on to release a codebase that is 5 times bigger and harder to install, how many support requests might I get? 20 per day, 30? It’s not viable for me to even look at so many emails…

So, that brings me to YOUR choices. You choose to disallow me access to your shop admin, and that’s OK! Your choice therefore is to use a different discount system, or to use the v1.2 as you already are and update it – that’s great – would be better if, after you update it, you then contribute it back to the community and support it.

You may have noticed that my contribution total stands at around 40 to 50 – guess how many people have actually emailed me over the past 10 years to say “hey thanks for contribution XYZ, it really helped me”. You could count the number on the fingers of 1 hand. But that’s unimportant and is a side-issue. Many more people have thanked me for taking the time to install and support after payment!

As you rightly say, it’s not about the money – $50 doesn’t come close to covering my time to install and support, but it sorts out the people who are serious about their business, compared to those who are not.

So, my choice is to release this only with installation.
And your choice is to accept that, or not.

It seems a fair and equitable way to make the vast majority of people realise that Open Source does not mean Free.

Only 1 product at a time in osCommerce

Over at the official osCommerce forum, someone asked about the possibility of only allowing a buyer to select 1 of each product.  My answer was to amend the display of the shopping cart and the shopping cart class…

It’s fairly easy.  What I am going to show you is amending the display using HTML and CSS, then a bit of PHP code to only add 1 of a product in the class file.

Step 1:  Make the quantity box readonly and look nicer.

As someone who has done a lot of HTML over the years I know that the attribute called “readonly” makes an input “read only”!  So I add this to the shopping cart page.  Open up shopping_cart.php and find

[php]’text’ => tep_draw_input_field(‘cart_quantity[]’, $products[$i][‘quantity’], ‘size=”4″‘) . tep_draw_hidden_field(‘products_id[]’, $products[$i][‘id’]));[/php]

Change it to:

[php]’text’ => tep_draw_input_field(‘cart_quantity[]’, $products[$i][‘quantity’], ‘size=”4″ id=”clubosc” readonly=”readonly”‘) . tep_draw_hidden_field(‘products_id[]’, $products[$i][‘id’]));[/php]

You can see that I have added the readonly attribute and given it a css ID called “clubosc”.

Step 2:  Amend the look of the box using .css

Open up stylesheet.css and add this code;

[php]#clubosc {
border: none;
text-align: center;
background: transparent;
}[/php]

Add something to the cart and your quantity box now looks like this:

Whereas the usual look is like this:

Now, because we have made the contents of the quantity field readonly, we have to ensure that not more than 1 product can be added. At the moment a buyer could return to the product page, and click “buy” again, ending up with 2 of the same item in his cart.

Step 3: Making only 1 buyable…

Open up /includes/classes/shopping_cart.php and find this line of code:

[php]$this->update_quantity($products_id_string, $qty, $attributes);
} else {
$this->contents[$products_id_string] = array(‘qty’ => (int)$qty);[/php]

Simply change both $qty to (int)1. So you end up with;

[php]$this->update_quantity($products_id_string, (int)1, $attributes);
} else {
$this->contents[$products_id_string] = array(‘qty’ => (int)1);[/php]

And that is it. 3 easy steps to allow customers to only buy a maximum of 1 of each product.

osCommerce Quiz?

An osCommerce Quiz for you to think about;

[php]
switch (tep_get_zone_code($order->delivery[‘country’][‘id’], $order->delivery[‘zone_id’], ”)) {
case ‘HI’:
case ‘AK’:
$extra_cost = ($cart->show_total() * (13/100));
break;
default:
$extra_cost = 0;
switch ($order->delivery[‘country’][‘iso_code_2’]) {
case ‘US’:
$extra_cost = 0;
break;
default:
$extra_cost = ($cart->show_total() * (13/100));
}
}
[/php]

And then an extra piece of code like this, elsewhere in the file…

[php]+ $extra_cost[/php]

I came up with proof of concept code (proof of concept is just that, it shows it work but might not be the most graceful codebase) to illustrate something. Thought it might be interesting for you guys to see some code with no explanation, and find out what the code is for.

So, questions;

1. In which file(s) could this code be placed?
2. Which country/countries add NO cost?
3. Which states add an extra cost?
4. What is the extra cost?