Posts Tagged ‘reader questions’

Open Source is all about choice

Wednesday, February 10th, 2010

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.

Originally posted here:
Open Source is all about choice

Use as little code as possible when writing PHP

Friday, September 11th, 2009

I’ve commented on this many times in the past across a number of forums and blogs. If you use as little PHP as possible to get something done, it is usually far easier to keep track of, both for yourself and for future readers of your code. Here’s a typical example, taken from the osCommerce forum;

Does anyone know how to show credit card numbers seperated by dashes like on admin/orders.php thanks in advance for the help

What this guy wants is a credit card number to be written like this: 4111-1111-1111-1111 instead of 4111111111111111 – quite why he wants it is beside the point as he should not be storing the info anyway in my opinion, but anyway, that doesn’t really matter as the point of this article is not about the legalities of storing CC numbers, but more about writing code nicely…

No-one replied to his thread, so he came up with a workable solution himself;

PHP:

  1. $cc_p1=substr($order->info['cc_number'],0,4);
  2. $cc_p2=substr($order->info['cc_number'],4,4);
  3. $cc_p3=substr($order->info['cc_number'],8,4);
  4. $cc_p4=substr($order->info['cc_number'],12,4);
  5. echo $cc_p1 . ‘-’ . $cc_p2 . ‘-’ . $cc_p3 . ‘-’ . $cc_p4;

Here he is splitting the $order->info['cc_number'] into 4’s and adding a – between each. Easy enough. But look at the ugly code!

My solution is like this:

PHP:

  1. echo rtrim(chunk_split($order->info['cc_number'], 4 , “-”), “-”);

Here I am using chunk_split to split the $order->info['cc_number'] into 4’s and adding a – at the same time after (not between) each block of 4. The only problem is that this will add a – onto the end of the number – to combat this I am using rtrim to take off the end – : so I go from this 411111111111111 to this: 4111-1111-1111-1111- to this: 4111-1111-1111-1111

Easy as 123? Well maybe not if you are not that skilled in PHP ;)

Of course, I am not saying that my way is the right way – there are probably many ways in which the same effect can be achieved. What you have to agree with is that my line of code is much sexier than the first block of code posted and much easier to read!

Have fun with PHP and osCommerce! You can click the links in the PHP snippets above to learn more about rtrim, chunk_split etc

The rest is here:
Use as little code as possible when writing PHP

Free Shipping Unless Weight is greater than 1kg

Wednesday, March 25th, 2009

John asks;

I’ve hunted high and low and can’t find a solution to this problem. I want to provide free shipping for orders over £20 … but needs to apply a charge if the total weight exceeds 1kg. Is there a way to do this – or a contribution that can be used to do this.

The simplest way to do this is to enable the shipping order_total module to over-ride all of your shipping modules if the amount of the order is greater than £20. This is easy, follow this previous blog post of mine.

However, you also need to disable this if the weight of the order exceeds 1kg. Easy!

Open up checkout_shipping.php and add this code:

PHP:

  1. if ($total_weight> 1) $free_shipping = false;

Right underneath this existing code:

PHP:

FAQ: Free Shipping in osCommerce

Thursday, February 12th, 2009

Another question that I see asked time after time is;

How do set up osCommerce so that any order over £50 has free shipping?

The easiest way is to go into your admin area > modules > order_total

Now click on the shipping module, and press [edit]. This brings up a screen like this:

The bit that we are particularly interested in is this:

Simply insert a number in that box! If you want free shipping over £50, insert 50. Free shipping over £75, insert 75. And so on. Once done, press [update].

Note that this order_total module setting OVER-RIDES any charge that is applied via a shipping module.

Isn’t that easy?

See the rest here:
FAQ: Free Shipping in osCommerce

Split an image into the breadcrumb

Saturday, January 10th, 2009

“M” asks;

Is it possible to replace “Top” with an image, and not effect the rest of the breadcrumbs; I mean not cause the colored background increase in height. Rephrasing…is it possible to overlay and image, that would replace “Top” on the breadcrumb line so that I could surround the image in a matching square or circle background that would seemlesly merge with the background stripe of the breadcrumb background color.

and supplies an image;

This is fairly easy – in short you have to split the “i” image up into three parts;

1. the middle piece which is the same HEIGHT as the breadcrumb bar.
2. the top piece
3. the bottom piece

Then use CSS to place each piece appropriately in your design.

1. middle piece goes in the breadcrumb, then indent the text of the breadcrumb
2. top piece goes at the BOTTOM LEFT of the td ABOVE the breadcrumb
3. bottom piece goes at the TOP LEFT of the td BELOW the breadcrumb

Read more about CSS at w3schools.com.

Top:

Middle:

Bottom:

More Help

I show how to do something very similar in both of my “designing oscommerce” and “oscommerce sts” ebooks. In the designing one I show how to split up an image and use css to place it in a couple of areas, and in the sts book I show how to move the breadcrumb along to suit a design. More info on these eBooks by going to oscbooks.com – and if you buy one, you get the other FREE.

See more here:
Split an image into the breadcrumb

Shipping Modules are fun to code

Thursday, December 18th, 2008

Here is a question from a client;

Im setting a a new oscommerce website and cant seem to get the shipping working. I would need to have about 5 zones. Each zone would contain different countries. For each zone there is a basic rate per pound. eg $35 . Each additional pound cost $5 etc per zone. That cost differs per zone. Also i would need packaging cost.

I’ve not seen anything quite like this available as a contribution – so instead of spending hours looking for it, I decided it would be more cost effective to code this up from scratch. It was actually fairly straightforward. Here’s the interesting info;

In the Admin section, I simply made an input form for the module. For each Zone that is set up, the client can insert 3 different prices. In the image below, I have set up 2 zones…

As you can see, each Zone has 3 inputs: “1st”, “rest” and “handling”. “1st” takes care of the first unit of weight, and “rest” takes care of any subsequent units. Handling is obvious! In Zone 1 (in the image) I set up 3 countries: AG,BB,DM. So the costings inserted in the three price fields will be used for those 3 countries. In Zone 2, similarly, 3 countries US,CA,FR with different prices for “1st” etc.

You will also notice above these Zones, an area entitled “Cost for all other Zones” – this is a fail-safe method of making sure that each country gets a quotation for postage. A country that is not in any existing zone will default to this.

In the actual codebase for the module, the relevant piece of code that works out the actual price is as follows:

PHP:

  1. $shipping_cost = $shipping;
  2. if ($shipping_weight> 1) $shipping_cost += ($shippingtoo * ($shipping_weight1));
  3. $shipping_cost += $handling;

Which basically says;

PHP:

  1. $shipping_cost = $shipping;

This is for items of a total of 1 unit of weight or less

PHP:

  1. if ($shipping_weight> 1) $shipping_cost += ($shippingtoo * ($shipping_weight1));

Here we are saying IF the total weight is GREATER than 1, then $shipping_cost should be INCREASED by the “rest” ($shippingtoo) amount multipled by the $shipping_weight -1. Remember that we have to do -1 as the first unit has already been worked out!

PHP:

  1. $shipping_cost += $handling;

Easy and straightforward, add the handling fee on top!

Code hints

You might notice me using something weird in these calculations, the += sign. What this does is simply add something onto an existing total. It’s a shorthand way of saying;

PHP:

  1. $shipping_cost = $shipping_cost + $handling;

It’s a bit less work to just say

PHP:

  1. $shipping_cost += $handling;

So, there you have it. I thought it might be interesting for you to see a bit about how I code things up – I try to make things as simple as possible.

Why not just use “Zone Rates” module?

If you have a bit of knowledge about osCommerce, you are probably thinking “he could have just used Zones Rate”. Well, that’s true, but there are good reasons why you should not…

1. Using Zones Rate you would have to set up EVERY country into a Zone to get a shipping quote. In mine you do not need to do this. Each country NOT in a Zone will default to “all other zones”.

2. Zones Rate cannot handle an open-ended system of weight, as the database field is simply too small – so if the customer ordered 400 units, with each unit costing say $5, my version can work this out very easily. Using the standard Zones Module would be IMPOSSIBLE (under normal use).

Original post:
Shipping Modules are fun to code

Stop People Checking Out? Huh?

Thursday, December 11th, 2008

Interesting question posed at the osCommerce forum;

All my products are 5lbs each. Is there a way to set a minimum order of 10lbs. This would mean they have to purchase a minimum of two items (2 of the same product or 2 different products).

Is there a way in the USPS shipping module or any other file to set a minimum order of 10lbs or 2 products?

Easiest way is to do it on the 2 product minimum purchase, as I have already covered this in a previous post. cart->count_contents() is the code to use in this case…

So here is my answer to the question…

Add this in checkout_shipping.php, underneath require(‘includes/application_top.php’);

PHP:

  1. if ($cart->count_contents() <2 ) tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, ‘error_message=’ . urlencode(ERROR_NOT_ENOUGH_IN_CART)));

How simple was that? The line of code basically says:

IF the number of products in the cart at checkout time is LESS THAN 2, then REDIRECT the user back to the Shopping Cart and DISPLAY an error message to tell him/her so.

Obviously you also need to make the define in the language file (includes/languages{your language}/shopping_cart.php):

PHP:

  1. define(‘ERROR_NOT_ENOUGH_IN_CART’, ‘You have not purchased enough stuff. Buy more you fool.’);

Nice, quick and easy solution – always best to keep things as simple as possible in case you ever want to change it in the future.

Read this article:
Stop People Checking Out? Huh?

Coupons v1 to v5 – worth it? Points, Rewards?

Tuesday, December 2nd, 2008

Jason asks;

I use Discount Coupon v1.2 on my site and it works and works well – looking at your site its hard to see whats available in version 2.3.4 and now 5 which isn’t in version 1 to see if its actually worth upgrading. Do you have a list of whats new in the later versions?

The main changes are as follows;

Admin changes:
+ ability to see when each coupon was last used
+ ability to view all orders that used each coupon
+ ability to set a “use once, one time” coupon (instead of per customer)
+ ability to set a minimum spend before a coupon can be applied

Shop changes:
+ moved coupon input box to shopping cart (away from checkout process)
+ ability to remove a coupon after it has been applied
+ now works with Tax calcaulations

Coming Soon:
- ability to set an expiry date per coupon

Also, age old question I know but any update on the GV side of the contribution?

As yet, no-one has offered to sponsor development, hence it’s (very) low down on the to-do list, as it’s something that I personally do not need.

Final point then – does this work with Point and Rewards Module – I only ask the instructions for it specifically mention things which need done if using CCGV and, while I obviously know your contrib Is NOT CCGV, it does similar things so was curious to know if this was tested or if you knew of any incompatibilities?

Should work OK with all contributions, IF those contributions are decently coded. I don’t know of any incompatilities with that particular contribution. My coupon system is coded far more cleanly than CCGV so I think that there should be no problem. An idea would be for someone ;) to install a new osc, then Points and Rewards, then v1.2 of coupons and see if it all plays together nicely.

More:
Coupons v1 to v5 – worth it? Points, Rewards?

Coupons v1 to v5 – worth it? Points, Rewards?

Tuesday, December 2nd, 2008

Jason asks;

I use Discount Coupon v1.2 on my site and it works and works well – looking at your site its hard to see whats available in version 2.3.4 and now 5 which isn’t in version 1 to see if its actually worth upgrading. Do you have a list of whats new in the later versions?

The main changes are as follows;

Admin changes:
+ ability to see when each coupon was last used
+ ability to view all orders that used each coupon
+ ability to set a “use once, one time” coupon (instead of per customer)
+ ability to set a minimum spend before a coupon can be applied

Shop changes:
+ moved coupon input box to shopping cart (away from checkout process)
+ ability to remove a coupon after it has been applied
+ now works with Tax calcaulations

Coming Soon:
- ability to set an expiry date per coupon

Also, age old question I know but any update on the GV side of the contribution?

As yet, no-one has offered to sponsor development, hence it’s (very) low down on the to-do list, as it’s something that I personally do not need.

Final point then – does this work with Point and Rewards Module – I only ask the instructions for it specifically mention things which need done if using CCGV and, while I obviously know your contrib Is NOT CCGV, it does similar things so was curious to know if this was tested or if you knew of any incompatibilities?

Should work OK with all contributions, IF those contributions are decently coded. I don’t know of any incompatilities with that particular contribution. My coupon system is coded far more cleanly than CCGV so I think that there should be no problem. An idea would be for someone ;) to install a new osc, then Points and Rewards, then v1.2 of coupons and see if it all plays together nicely.

Read more:
Coupons v1 to v5 – worth it? Points, Rewards?

COD only if Coupon is live

Thursday, November 27th, 2008

A previous post introduced the idea of making modules in osCommerce “interactive” based upon other inputs…

Stefan asks;

What I need is for the COD Method of payment to work only with a valid voucher. In other words you cannot use the COD Method of payment without first entering a valid voucher code.

I had already installed my Discount Coupon modification onto Stefans store, which was seen to work very well, then Stefan posed that question to me. I was sure that this should be really quite simple to get working…and after a bit of lateral thinking, all it took was the following code (added to the COD module):

PHP:

  1. if (!tep_session_is_registered(‘coupon_code’)) $this_enabled = false;

Which basically says;

if a session called “coupon_code” is NOT present, then disable the “Cash On Delivery” module. This works as my coupon module sets a number of sessions, one of them being “coupon_code”, when a coupon is live.

Easy as 123. Can you think of ways to make your site more interactive for your shoppers?

Continue reading here:
COD only if Coupon is live