In this section we look at my cache mechanism. It’s similar in principle to the WordPress “transient” concept. For example, the “top sellers in the last 30 days” does not need to be calculated every page load. Calculating once per hour should be more than sufficient. Doing both calculations (all time best sellers and best sellers last 30 days) takes 1–4 seconds depending on server load, and the Top Sellers page turns out to be one of the most popular pages. It is therefore a good candidate for caching.
I also found that a lot of the border/navigation items take a long time to generate, and again are good candidates for caching. Within SunShop we make all sorts of lists for navigation purposes, every page load, and then never use much of the result. With caching, I reduced the hundreds of queries per page load down to a dozen or so.
For example, if it takes a hundred queries to build up a sorted list, and we can safely cache the result for an hour or so, we have a huge page-performance gain. Why so many queries? In certain cases, SunShop does one query to get a sorted list of item IDs, and then loops through the list doing a separate query for each item in the list.
We’ll use the Top Sellers plugin as our use case. We cache the result of each top sellers calculation for 60 minutes. Read more…
In this section we look at my Top Sellers plugin. This gives us a concrete example of writing a plugin. However, with this example we’ll use my full plugin “framework” which includes my Registered Object mechanism. We’ll also see my persistent-cache mechanism in use, which we’ll then explore in a later post.
Top Sellers Plugin Invocation
We invoke the two plugins as follows, in the Top Sellers page template. We use “bb_” as the prefix to avoid namespace collisions: Read more…
Here in Part 4 I show another technique which I use to keep my custom code off to the side. I’m no longer a fan of the Singleton Design Pattern because of its difficulty in unit testing. However, it’s a good tool for SunShop modifications.
Our Top Sellers page has two tabs, one tab for All time top selling products, and another tab for top sellers over the past 30 days. I use “bb_” as my prefix to ensure no namespace collisions. Here is the page template: Read more…
In this section we look at one of my custom SunShop pages, the SEO list. I’m assuming you have access to a SunShop admin area, and you know what an admin page looks like. Visit the SunShop Official Demo Page here to follow along if you need to.
The Customization
As part of our SEO (Search Engine Optimization) work, we are examining all product descriptions, short descriptions, meta descriptions, sample text, etc. I wrote code for the Edit Product page which creates a product preview, a Google-listing simulation, etc., with the target search terms highlighted.
In order to highlight the search terms, naturally, we need to know the list of target search terms. This quick-and-simple admin page allows us to enter each search term, its relative priority (1, 2, 3, etc.) on our list, and a CSS class defining the highlight color. You will recall our page support looks like this: Read more…
In Part 2 I explain how to get the code modifications off to the side. We start by explaining why this is important.
Why We Need to Get Our Code Off To The Side
SunShop is actively supported software under active development. That means your SunShop installation could, at some point, be upgraded to a new software release. That generally means you lose your custom modifications — unless they are completely separate from the mainline code.
The SunShop installation instructions explain how to do this with the template/css/javascript files: Copy your preferred theme templates to a new folder and do your template modifications in the new folder. This way, when the software is upgraded and the standard template folder is replaced, your template files will not be overwritten.
Since this “SunShop Modifications” series is aimed at PHP developers, not tweaking templates, that’s all I have to say about managing the template files!
SunShop Admin Area Enhancements
My general strategy for the SunShop Admin Area is to create a new admin page. This doesn’t always work, for example, I added some additional fields to the Edit Product page. The best I could do in this case is add my name and date as a comment, so that I can search on my own name when it comes time to upgrade the software.
My custom admin page support looks like this: Read more…
The SunShop software is a commercial product from Turnkey Web Tools. These tutorials do NOT expose any original SunShop code, only my own code.
The Project
My client commissioned me to make custom cart modifications to SunShop. I am sharing source code with my client’s permission. The modifications include:
- Feature/bug fixes
- New functionality aimed at enhancing the user experience
- SEO work (Search Engine Optimization) based on a consultant’s recommendations and my own recommendations. This became a number of areas including page load time, additional text, and layout changes. Read more…
I have a situation where I’m able to download a CPAN module distribution, but I’m behind a firewall and I therefore can’t install the module using the cpan installer. The recommended offline solution is to use the CPAN Mini Mirror. But that presents the same problem: It expects to have Internet access.
The solution is simple — don’t use the CPAN installer! Just do the Makefile yourself. Here is how I installed the Test::Class module:
tar xzf Test-Class-0.37.tar.gz
cd Test-Class-0.37
perl Makefile.PL
make
make test
make install
If you can’t do it the easy way, don’t forget you can do it the “Old School” way!
Categories:
Perl Webmastery Tags:
My son Jakob Barnard recommended the NextGEN plugin for WordPress. If you’re pressed for time in learning to use it, I recommend you find a tutorial via Google. I found
The WordPress Ninja tutorial gave me a great overview of what the workflow is in setting up a gallery. The video tutorial was well worth the additional 12 minutes. The author takes the time to generate errors and show how you see what is going wrong. Very helpful!
Having just put up my own first NextGEN gallery, I have additional tips for you.
Fix For NextGEN Gallery Slide Show Not Working
A google search showed numerous complains that the Slide Show feature was not working. Answers included conflicting plugins and Go Daddy hosting. My solution was quite simple: Work your way through all of the NextGEN settings! I’ve gotten spoiled by all the great plugins out there and have begun to expect everything to work well enough “out of the box.” Wrong answer! Read more…
I find Apple’s Time Machine backup system to extremely annoying. After five years, it finally paid off!
Hard Drive Failures Do Happen
To be sure, when my MacBook hard drive failed four years ago, restoring from backup was extremely easy. Getting the hard drive replaced was, in theory, easy. I went to the Apple store at the Mall of America and they replaced it under warranty. Unfortunately this was the same weekend the iPhone 3G was released. We spent all day waiting for the hard drive replacement!
But once I got my MacBook home, I plugged in the backup hard drive, which is maintained by the Time Machine backup system, and it restored everything from there. I lost up to four hours’ worth of email, but absolutely everything else was preserved. Nice!
How does Time Machine work and why do I find it so annoying? Read more…
Today I upgraded the The Strong Family Association of America, Inc. theme. I use Atahualpa, and it’s been years since I updated the theme. I needed to move my favicon and logo from theme folder atahualpa333 to atahualpa. Fortunately, the theme carried my options forward to the new version.
Here is a hint: Turn on Firebug and let it tell you what images are broken or missing!
I found that the sticky note graphic was missing. Here is the fix: Go to the Atahualpa theme options. Click on the section Style POSTS & PAGES. The second section is POST Container: STICKY. There is a space in the background image url. For my site, it reads:
background: #eee url(‘http://strongfamilyofamerica.org/wp-content/themes/atahualpa /images/sticky.gif’) 99% 5% no-repeat;
Whereas it should read:
background: #eee url(‘http://strongfamilyofamerica.org/wp-content/themes/atahualpa/images/sticky.gif’) 99% 5% no-repeat;
The problem is that pesky space after atahualpa and before /images/sticky.gif. Remove the space, save your settings, and you’re good!