Add alternate pricing option to Cartweaver

A Cartweaver user asked how he can add alternate pricing to his Cartweaver ecommerce site. He was understandably concerned about the need to edit the database, and how much code editing might be involved. But if you take a systematic approach, it is pretty straightforward.

The first part of setting up any alternate pricing system is to get that info into your database and admin, so you can work with it. In this case, since the basic goal is to duplicate the existing 'price' system, that is exactly what we are going to do.

more...

Marking current menu link with jQuery for CartWeaver categories

Working on a heavily-modified Cartweaver Coldfusion E-Commerce shopping cart site, I have created a database-driven navigation menu containing links to each category. When a user clicks a link, the products in that category are displayed, and the menu link for that category is highlighted via a special 'currentLink' css class.

Now of course I could use CF to add ' class="currentLink" ' to the current category's menu option, but I am not doing this particular menu that way. Besides, it is just as easy with jQuery!



<cfif cgi.script_name contains 'results.cfm' AND isDefined('url.category') and url.category gt 0>
<cfsavecontent variable="highlight">
<script type="text/javascript">
$(document).ready(function(){
$('.sideNav li a').removeClass('currentLink');
$('.sideNav li a[href=results.cfm?category=<cfoutput>#url.category#</cfoutput>]').addClass('currentLink');
//end jQuery
});
</script>
</cfsavecontent>
<cfhtmlhead text="#highlight#">
</cfif>

Simple enough - if we are on the 'results' page, and a category is defined in the url, remove the 'currentLink' class from all existing menu items, find the one where the 'href' attribute matches the current pagename and category, and add the class back to that link. Done.

The use of cfsavecontent and cfhtmlhead means I can put this right below the code that calls in my custom nav tag, for easy fine-tuning right where i need it (rather than in an external scripts file).

Quick , easy, and done in a flash with jQuery!

Redirect secure 'https' requests using getPageContext() and isSecure()

Working on a site using a shared ssl, where only 2 specific pages of the site are required to operate under the https:// SSL prefix, I needed a quick way to check whether a page request for either of those pages was using the 'https' prefix - if not, redirect, adding the 's'. Likewise, all other pages, we want to make sure they are not using the 's' and redirect without it.

I found this blog post, which got me started: http://www.chapter31.com/2007/07/21/detecting-and-redirecting-http-to-https/

Using the fun and interesting CF goodies
getPageContext() and isSecure()

<!--- REDIRECTION TO SSL / non-SSL --->
<cfset secureRequest = getPageContext().getRequest() />
<!--- for these pages, redirect to secure (https) page  --->
<cfif cgi.SCRIPT_NAME contains 'payment.cfm' OR cgi.SCRIPT_NAME contains 'payment_response.cfm'>
<cfif NOT secureRequest.isSecure()>
<cflocation url="https://#secureRequest.getServerName()##secureRequest.getRequestURI()#?#secureRequest.getQueryString()#" addtoken="false" />
</cfif>
<cfelse>
<!--- for all other pages, redirect to non-secure (http) page --->
<cfif secureRequest.isSecure()>
<cflocation url="http://#secureRequest.getServerName()##secureRequest.getRequestURI()#?#secureRequest.getQueryString()#" addtoken="false" />
</cfif>
</cfif>

Quick and simple.

301 "Permanent" URL Redirection with Coldfusion 8 and cflocation

When moving domains, or forwarding the traffic from one site to another, the usual and preferred method is a "301" or "permanent status" redirection, which, simply put, means "the page is gone and it is not coming back. Please look here from now on --> "

As Pete Frietag quickly explains in this blog post : http://www.petefreitag.com/item/648.cfm , 301 redirection with ColdFusion is as simple as could be as of CF8.

<cflocation url="http://www.newsite.com" statuscode="301" addtoken="false">

That's it.... just plop that in your old page, set the url, there's yer 301 .

Of course, this only works in cases where the old domain is still hosted on a live server, i.e. moving a directory within an existing site. For full-blown root domain redirection, see your friendly neighborhood domain registrar or server control panel.

Modify CartWeaver functionality based on customer login

A CartWeaver user asked the question:

"I want to have viewers Register (or, log in if they've already registered) before they can see anything in the cart. How would I do this?"

 

Here's my quick answer:

In Cartweaver, the trigger for whether someone is logged in can be found in the "client.customerID" variable.

So, any logic that you want to base on 'if a customer is logged in', might look like this:

<cfif isDefined('client.customerID') AND client.customerID gt 0>
THE USER IS LOGGED IN
<cfelse>
THE USER IS NOT LOGGED IN, SHOW THE LOGIN FORM, HIDE THE CART CONTENT
(or redirect to login page.. whatever)
</cfif>


When someone logs in, their 'ID' gets stored in the 'client' scope.
(Simply put, a variable that follows them around during their session on the site).
If they have a clientID defined and it is greater than '0', we can assume they have logged in already.

( I use isDefined() as a safeguard, but actually the default for this variable, if not logged in, is simply 0. )

You can safely wrap this line around anything you want to show ONLY if somebody is logged in

<cfif isDefined('client.customerID') AND client.customerID gt 0>
 STUFF HERE
</cfif>

And if you only want stuff to show when the person is NOT logged in

<cfif (isDefined('client.customerID') AND client.customerID eq 0) OR not isDefined('client.customerID')>
 STUFF HERE
</cfif>

Again, simpler version would be just:
<cfif client.customerID eq 0>

but I like to make sure the var exists when giving code examples,
so you can put that code anywhere in your site you like.

 

ColdFusion Meetup

Today I attended my first ColdFusion Meetup. I've been watching and/or listening to the previous meetups now and then, but today I clicked through and there was one in progress so I jumped in. What a neat system this is. If you are a ColdFusion user and want to learn more about the CF world in general, it is obvious this is a good thing to be part of.

The whole platform takes a bit of reckoning - the Adobe Connect viewer seems to handle itself once installed, but there's some stuff happening on the screen once you log in... you've got somebody's video - whoever is in control at the moment - showing a live screencast,  the voice of the host and/or current speaker as the audio channel, and a scrolling chat window with all sorts of things including notes from the presenters, questions from the audience, and various interjections.

Connecting live and having my own typed questions answered on the realtime voice track was fun... though listening to the recordings can be educational and thought-provoking, being there 'with' all the other CF-folks in realtime is definitely the way to go... I plan to be back at more CF meetups soon!

The CF Meetup site is here: http://www.meetup.com/coldfusionmeetup/

The one I participated in today, "Leveraging Eclipse for ColdFusion Development", with Mike Henke", is here: http://www.meetup.com/coldfusionmeetup/calendar/10900365/

( Thanks to the host Charlie Arehart and to Mike for the info about CFeclipse - I learned several useful things today and look forward to what's coming next! )

 

Replace missing images sitewide with jQuery and ColdFusion

In my application.cfc, within the 'onRequestStart' function, I have a variable defined for the replacement image to use in my site.

Then, in an include that puts special goodies into the head of every generated html page sitewide, I have this bit of cf code



<!--- missing img src --->
<cfif fileExists(expandPath(request.missingImage))>
    <cfset imgErrorSrc = '#request.thisdir##request.missingImage#'>
<cfelse>
    <cfset imgErrorSrc = ''>
</cfif>

This checks to make sure the 'error' image actually exists - if not, we just use a blank '' value. (Note: request.thisDir is my own global variable that references the root of the site - you can replace that with any hardcoded or dynamic url)

Then, write a simple function to replace any images - this duplicates a similar usage of the tag's 'onerror' attribute ( which is fine for images in non-strict doctypes, but is not entirely valid ).



<!--- replace all missing images with replacement image, or with empty src --->
<script type="text/javascript">
$(document).ready(function(){
    $('body img').error(function(){
        $(this).attr('src', '<cfoutput>#imgErrorSrc#</cfoutput>').attr('alt','');
    });
});
</script>

That's it. Also notice I am clearing the 'alt' attribute as a final precaution. Using this method, any missing image anywhere within the html will simply be 'blanked out'.

I could use jQuery's .remove() function, to remove a missing image completely from the DOM, but there are times when I want the space or layout to be preserved, and really, I don't want errant images in my pages at all, so this gives me a way to debug if I find my self (inevitably) scratching my head when a missing image simply 'vanishes' from the page 4 or 5 sites from now.

As a final note, the CF part of this, setting the value for the 'src' attribute, can be enhanced to include different images for different pages, or under different conditions. Likewise, the jQuery function could be expanded to target images in one location with a specific action, and in another with a separate function by using different css selectors.

Just another example of how Jquery + CF = bliss :-)

Setting up Eclipse 3.5 w/ CFeclipse 1.34 & Aptana 1.5

A new version of Eclipse (version 3.5 aka 'Galileo') was just released, along with a well-timed new version of CFeclipse (version 1.34), the Eclipse-based ColdFusion editor, and a new version (1.5) of the incredibly versatile Aptana Studio eclipse plugn.

I've been using Eclipse for a while now, but my installation was done as a total noob and it is unclear to me what is part of native Eclipse, what came with my current version of the CFeclipse plugin, and what's provided as part of the wonderful Aptana code editor, another must-have plugin for my daily Eclipse use.

In an effort to trace my steps this time around, I'm attempting to make notes as I go. Your mileage may vary (I'm on Windows, not sure if it varies for Mac, for example), but here's what I did: .

more...

Things I miss from Dreamweaver (in Eclipse / CFeclipse / Aptana)

yes there are a few...  I've been DW-free  and 100% eclipse-coding for about a year now I think... and I still find myself wishing for just a few of the features that were in DW. Maybe they'll be in 'ColdFusion Builder' ... maybe they already exist in eclipse and I'm not looking at it correctly.

My workspace is currently Eclipse 3.4 w/ CFeclipse plugins and Aptana code editor. The perspective I work in is largely Aptana's default w/ some stuff moved around.

Anyway, here's my short list of things I wish I had in my daily IDE : 

- Highlighted Tag Matching. Yes there is a bit of that in my eclipse/cfeclipse build, i.e. 'jump to matching tag', but in DW I could hit a key combo that would highlight the tag and its contents, and with another keystroke, jump to the parent matching tag, expanding outward. Then I could collapse that section - or any section I want - among other things. I miss that.

- (smarter) Tag Completion: In eclipse, I can type <p> and it puts the closing </p> right after. That's great. But in DW, I could type <p> then a big long sentence and then simple ' </  ' ... and it would know to put the closing 'p>' in there for me. Same for /div>, whatever. That was cool.

- Last Modified Dates /. 2-part FTP Panel: I love eclipse's "project" view, where i can have any number of projects in a single scrolling pane without flipping back and forth like DW's 'sites' system. Awesome. And the built-in FTP w/ Aptana is much faster and more reliable for me than DW ever was (this was the main reason i finally forced myself to become friendly w/ eclipse after years as a die-hard DW user). But sometimes I really miss the expanded FTP view from DW, where i could see files on the local server as well as the remote, with last-modified dates and everything. I still suspect this lurks in eclipse but have not found the right 'view' as of yet.

- User Defined Keyboard Shortcuts: this is a BIG one. Snippet shortcuts are awesome, but still not quite the same as being able to set my own key combos on any menu or window item.

 

No chance I'll be going back to DW any time soon (or ever) - there's too much in Eclipse that I would not only miss but become less productive if I did not have. For the most part I have a great, stable (and free!) web coding system in place, but these are the main features I find myself missing. My hands get tired after 12-hour coding days - every little auto-completed key-shortcutable item counts! - and when going between windows and views, I wish I didn't have to use the mouse so much.

I'm curious to hear from other DW-to Eclipse converts... what's your wish list for Eclipse?

 

CF Gallery Creator & jQuery Slider Gallery !New and Improved!

Still a work in progress, I have fixed a few small things and added better setup notes for the CF Gallery Creator and jQuery Slider Gallery (click for explanation in previous post)

The new code is available as a zip file, attached ** see below **

This package contains

1) a custom ColdFusion image gallery generator, which will create thumbnails and large images of any size you specify from a folder containing your original images, and outputs them to the page in a nice unordered list html markup.

Includes options for multiple subfolders, each one a separate 'gallery' with thumbnail or dropdown navigation.

 

2) a simply but effective 'slider gallery' built on css and jQuery. Example here:

http://www.gowestweb.com/cfdev/_tags/gallery/slidergallery.cfm?gallery=some-gallery-name

( Without the jQuery and css, the raw markup from the CF tag alone looks like this
http://www.gowestweb.com/cfdev/_tags/gallery/gallerypage.cfm?gallery=some-gallery-name

 

As usual this was built to meet a specific need for a client project and has been tweaked and adjusted along the way.

Please DO try it out, and let me know if/when you use it.
Comments, enhancements and suggestions welcome!

Some alternatives to Adobe NNTP Newsgroups

As many dedicated web developers mourn the passing of the NNTP interface for Adobe's support forums ( formerly nntp://forums.adobe.com ), I'd like to extend a hearty welcome, inviting all web developers, friends and interested cohorts to join myself and a number of other seasoned web professionals in some popular NNTP-friendly alternative hangouts.

http://www.miuaiga.com/page.cfm/Web-Developer-Newsgroups

In addition to general web developer newsgroups, there are some specialized groups for ColdFusion, javascript (ok, mostly jQuery), all three flavors of CartWeaver (E-commerce) and more.

Every one of the newsgroups listed on the page above is happy to welcome new and interesting contributors, the more the merrier. You may even discover some old friends among the archived threads. 

NOTE: If you are not currently using NNTP to interact with other web-folks online, you've been missing out! I recommend Mozilla Thunderbird, and an account at each one of the places listed. See you there!

---

In regards to the big switch, the Adobe Dreamweaver support forum says this:

ANNOUNCEMENT: Forums will be unavailable for planned system maintenance
starting at 3pm PST on April 3, 2009. New forums will be online on
Monday April 6, 2009.

( currently April 3, 1:35 Pacific time ... T-minus 90 minutes )

More Entries

blogcfc 5.9.1.002 by raymond camden
contact michael evangelista