Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Detect IE6 and redirect to compatible site in CRE Loaded

There are tons are beautiful CRE Loaded sites--if you are ever in the market for one, I personally am a huge fan of AlgoZone and RocketTheme for CRE Loaded and Joomla themes. But one of the downsides of the nicer themes is compatibility issues. For those of you who have not jumped on the CSS bandwagon, or for others of you unaware of the "old days" of web development, there has been a huge shift over time in the way styles are applied to sites.

In the old days, tables were your only tool. Whatever you needed to do, you created tables, nested tables, and played with table attributes. Tables could do a lot, but the final code for a complex page was all but incomprehensible, and forget trying to debug someone else's. It could be a real mess to find and fix errors, or to try to add new elements into pages.

The shift over time has been to use CSS styles applied to DIV tags. This keeps a great deal of presentation details separate from the pages, allow for page content to be developed apart from really complex styles. In addition to separating the actual code, this also provides great ways to take a page and render it completely differently based completely on the CSS applied. Content management systems in particular make extensive use of this because their individual widgets can display simple content, and the CSS applied can really change the output. This would have been a very difficult job in the old table days.

So back to CRE Loaded styles. I recently was working on putting a new template on a storefront, when one of my team members thought to look at the in IE6. The results were horrific. The site not only looked bad, elements such as the product menu just didn't show up. We ran some stats and found to our surprise that nearly 10% of potential customers coming to the store use IE6. So something had to be done.

I decided the easiest solution was to set up another domain, check the browser type, and then redirect IE6 users to the other domain. Connection information in CRE Loaded would stay the same, so both sets of users would share the same database, and the job would be trivial.

So, I searched the code and found a good place to put the IE6. The first step was the put the following in includes/application_top.php:


// first.....since IE6 performs very badly with our template....
// detect the browser and send all those poor souls to the
// old template
include('includes/browser_detect.php');

$a_browser_data = browser_detection('full');
if ( $a_browser_data[0] == 'ie' )
{
if ( $a_browser_data[1] <= 6 ) { $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $url = str_replace("www.myDomain.com", "www2.myDomain.com", $url); header('Location: ' . $url ) ; } }



I found some great code to detect the browser type here. I put that code in includes/browser_detect.php.

Then I went to test, and discovered that half the time I clicked on things, I was being redirected to the old site. After some seaching, I found that the domain is actually stored in a few pages of the php script. I changed those, and then I was staying consistently in the new site. Perfect.

Next I went into the admin side of the new site, and changed the template. Oh wait. The default template is stored in the database! The database that I am sharing between the sites! Time for more analysis.

I searched and searched through the code and discovered that DEFAULT_TEMPLATE was the variable that I needed to set, but DEFAULT_TEMPLATE was not set anywhere in the code. I realized my lack of PHP knowledge was hurting me, so I started looking up constant definition in PHP. It became clear that the value was being set somewhere, but searching the codebase had turned up nothing. Then I realized there must be somewhere in the code that all the configuration variables were being pulled in from the database and constants were being created for them.

After more searching, I discovered the code I expected was in includes/application_top.php, not far from where I had inserted the above lines:


// set application wide parameters
$configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
while ($configuration = tep_db_fetch_array($configuration_query)) {
define($configuration['cfgKey'], $configuration['cfgValue']);
}



PHP does not allow you to redefine the constants either....so there was no way to let this loop occur and then redefine the value later. Instead, you could either put an if clause in the code, look for DEFAULT_TEMPLATE, and set the value there, or instead set your override value first, then check as you are looping to see if the value is already defined, and only define it if it is not. It was late at night, so I chose the first. The more bulletproof way would really be to set up an include to define overrides and then put the conditional logic in this loop to skip any values that are currently defined. When I have some free time I will definitely refactor this code.

Anyone ever try to do anything like this? Let me know if you had a better solution. Thanks!

Zero to e-commerce in 2 days with CRE Loaded

If you have done any amount of freelance web development, you have probably been asked at some point to put together an e-commerce store front for someone. Most likely, the request also contained some caveats--like, the customer was just getting started, and wanted a store front for cheap, and they wanted it to be up pretty quickly (i.e. no long development cycle, with a minimum to the requirements gathering process), and they wanted some kind of admin tools so they did not have to contact you any time they wanted something simple like a price change.

As a custom build, this would be nothing short of impossible. Hopefully your next thought is to use an existing framework and customize it, to accomplish the goals and get something up quickly and cheaply. Next, you are also thinking about hosting, which can be expensive too, depending the requirements of the tool you buy.

I was presented with a similar request lately, so I started looking at some existing frameworks. My research took to through such disparate tools as DotNetNuke (of course the Microsoft guy would look at DNN) and MamboCharge, but I landed on CRE Loaded. CRE Loaded is a PHP script that has been developed on the popular OSCommerce framework. And the results are amazing.

Some of the best parts of CRE Loaded are the multitude of plug-ins available (including secure credit card processing), the availability of resources (both people and web content that can assist), and the easy and speed of getting a store up and running. CRE Loaded brags about how quickly you can get a Payment Card Industry (PCI) compliant store up and running, which promises secure processing in an industry standard framework. And it is every bit as easy as they say.

I recently got a store up in just a few days. I spent additional time tweaking the product, and learned a lot of the ins and outs. Let me tell you that if you plan to do any serious customization, or even maintain an inventory of even 100 items, you owe it to yourself to learn how to make changes in the SQL tables directly. I am sure CRE Loaded would rather you would either use their front end, or their custom load process--but if you know what you are doing, you can turn a difficult update across your entire inventory into a few minutes work.

Case in point, I was setting up shipping for the store, and discovered that shipping requires product weights. The inventory list that I had gotten from the customer's POS system was missing a lot of things, not the least of which was shipping weights. So I had 3 options--go through the admin screens and add a weight to every item (probably close to an hour's work); extract the database to a spreadsheet, update the spreadsheet, and then reload the spreadsheet, praying that the only thing that would be changed would be the product weight (probably 15 minutes work, plus an undetermined amount of time to fix anything that might have been broken due to a typo, etc); or, write a SQL query to set every product weight to 1 pound (1 minute's work).

If you are PHP person, you can also dig into the entire source, and tweak the application. This is not for those lacking caution, though, because it is a somewhat complex script, so I would not advise hacking into to it to make changes--spend some time first and figure out what it is doing. Another example, I had to make some changes to the shipping module to allow various flat rate shipping types, selectable by the customer. Currently, CRE Loaded expects that you will either use one flat rate, or chose from a number of different available shipping options. The moral of the story, though, is that will a little analysis, even this was a fairly easy change, and I could customize the app to meet the business' requirements.

CRE Loaded offers a free version that is a bit limited, but the pro version does a lot and only costs the equivalent of a few hours' work. In am impressed with the speed, ease, and flexibility. If you need to get a storefront up, make sure you include it in the list of products you research. It is worth every penny!

CRE Loaded Automated Load

I am working on a project right now that is quite a challenge--making CRE Loaded work with an automated load from a separate POS system. CRE Loaded is a tremendous tool, but I don't think it was intended to provide automated capabilities to tie into an existing POS system.

For those of you unfamiliar with it, CRE Loaded is a free, PHP-based storefront. You can find out more here. CRE Loaded is based on the popular OSCommerce platform, and is a great way to get an appealing and flexible storefront up on the web quickly. In addition to the free version, there is a paid Pro version that provides additional capabilities and features.

Generally, I have been very happy with CRE Loaded, but the loading process, called Easy Populate, is lacking. A few of the things you would expect to be there (automated loads, additional fields for the loads, and complete refresh of your entire store inventory) require stepping up to the Pro version, or are not available at all outside custom development. I believe the automated load of the store inventory is going to require hand coding of a CRON job to script out backing up the database, clearing it, and loading from a new import file.

This is a bit of surprise because CRE Loaded seems to handle the vast majority of the desired functionality simply and easily, right out of the box. Personally, it seems like a pretty common feature to require handling a load from a POS system or other external system. Because of that, I am surprised at what seems like anemic capabilities to support load imports.

That said, CRE Loaded is generally a great product, and the ability to write custom code as needed will even mitigate this issue. If you need to set up a storefront, I would put this at the top of your list to review. Just be sure you either don't need to handle external inventory, or can invest in custom code to fulfill this requirement.

Good luck out there!