We’re launching a new custom Joomla eCommerce site this week. I’m especially excited about this one, because it’s one of my own ventures, via Mock-Epic LLC. The first retail site is TwistedPens.com, which sells twisted pens (some of which we make here in-house). We hope to have a total of three retail sites online before this summer. Looking forward to it!
I’ve just spent the last few hours troubleshooting why a Joomla 2.5 site I’m working on was redirecting to the home index.php page for bad URLs instead of loading my template’s custom error.php page. Instead of the 404 response code, it was returning a 303 response: 303 See other
From what I can tell, it was because in the Global Configuration settings, I had the site offline for testing. So apparently even if logged in as a user who can view the offline site, it still won’t load the error page until the site is back online. When I put it back online, the 404 response was loading as expected… now I know.
I’ve been experimenting with modifying a copy of the Joomla “profile” plugin (/plugins/users/profile) and adding custom profile fields to use in other Components. Retrieving those stored profile values required some research, but it turns out it’s pretty straight-forward:
$User = JFactory::getUser(); $Profile = JUserHelper::getProfile(User->id);
From there, it may be easiest to just use the print_r() function to see what properties are available. In my case, they were in the “profile” property of the $Profile object, which was an array. So:
$favorite_goat = $Profile->profile['favorite_goat'];
I’ve become very accustomed to using Joomla’s JRequest class in custom Components. Since that class is now deprecated, I’m having to find new work-arounds, most involving the JInput class. Pretty much ever form had been using JRequest::checkToken() to guard against CSRF attacks, like:
if (!JRequest::checkToken()) $this->setError('Invalid (or expired) request token.');
To get around using JRequest, I’m now using this:
$app = JFactory::getApplication(); $token = JSession::getFormToken(); if (!$token || !$app->input->get($token, null, 'alnum')) $this->setError('Invalid (or expired) request token.');
…which seems to work in pretty much the same way. In the old JRequest::checkToken() method, it was also redirecting to the login page if no session was detected, which I’m generally skipping.
If you’re working on a custom post type in WordPress and make a change to the post type or category slug (or add a new one), and you’re getting 404 errors when visiting the pages at the new address, chances are you just need to refresh the WordPress rewrite rules for permalinks. You can do this in your code by calling the flush_rewrite_rules() function:
…or, go to the WordPress admin under Settings > Permalinks and hit the “Save Changes” button, which also triggers the function. This is usually the best and quickest fix if making changes while developing. If using the flush_rewrite_rules() function, be sure to only call it on plugin or theme activation and deactivation.
While working on an e-commerce system, I needed to use PHP to round a number to a minimum number of decimal places, but allow for more if needed. For instance, if the value was 1.2, I’d want it rendered as $1.20, but if it was 1.256, I’d want it to keep the precision and render as $1.256. I ended up converting the number to a string, splitting by the decimal, enforcing the minimum precision and then using PHP’s number_format() function, like: Read More »
I recently found Joomla’s feature to easily add custom component-specific nested Categories. It makes for a quick way to create categories similar to what is used in com_content and an interface to manage those categories without having to build it all manually. You can use JForm to easily add a select menu of your custom categories. The categories interface can even include a custom sub-menu to easily get back to the rest of your component.
I’m still planning to develop new form processing scripts, but in the meantime, a patch update has been posted for ProcessForm to deal with possible error messages in PHP 5.3+ about the eregi() function being deprecated (has been replaced by the newer preg_match() function). Also, I’ve switched the encoding to utf8 to better support non-English characters in the email text, confirmation screen and MySQL storage.
I should start out by mentioning that I’ve been a big fan of Panic for years – I’ve used Transmit since Mac OS 9 days, and Coda since its initial release. Since then, Coda has been my primary web development application.
I should also mention that I’m not someone who avoids change, particularly in the software I use. Over the years of waiting for a Coda update, I’ve delved into other apps like Espresso, Sublime Text, BBEdit, PhpStorm. There are plenty of things I’ve liked in each of the other apps (as far as I’m concerned, all the above are great), but I always found myself returning to Coda. Read More »