Monday, 30 April 2012

SSL, getSkinUrl and ARGGGH broken padlock or missing images in chrome/ie! Solution...

As above. The issue is, that when using getSkinUrl in Magento to plonk an image anywhere, if you also use SSL, on the https:// versions of the page, you sometimes (not always!) get a NON secure image.

i.e. and chrome dont like this one bit. They'll warn the customer that you're totally unsafe, and shouldn't be trusted. Hmm. A bit extreme, to say the least.

The solution is, well, the reason first. getSkinUrl seems to be caching the images in question. So the solution is to tell it to refresh that image.
I can't say I understand this 100%, but I took it from here (in the comments):

file to edit:
app/code/local/Mage/Catalog/Block/Navigation.php
(if you dont have the above, copy it from app/code/core - NEVER edit core files, always copy them over to app/code/local)

line to add (in magento 1.6 at least!) :


   public function getCacheKeyInfo()
    {
        $shortCacheId = array(
            'CATALOG_NAVIGATION',
            Mage::app()->getStore()->getId(),
            Mage::getDesign()->getPackageName(),
            Mage::getDesign()->getTheme('template'),
            Mage::getSingleton('customer/session')->getCustomerGroupId(),
            'template' => $this->getTemplate(),
            'name' => $this->getNameInLayout(),
            $this->getCurrenCategoryKey(),
            $this->getSkinUrl()
        );
        $cacheId = $shortCacheId;

        $shortCacheId = array_values($shortCacheId);
        $shortCacheId = implode('|', $shortCacheId);
        $shortCacheId = md5($shortCacheId);

        $cacheId['category_path'] = $this->getCurrenCategoryKey();
        $cacheId['short_cache_id'] = $shortCacheId;

        return $cacheId;
    }

Sunday, 4 March 2012

How to kill a cron job that's hanging around

If like me, you have your magento on a server, you might find that you're constantly nagged by "excessive resouce usage: " messages from lfd/csf firewall.

Or you may just notice that cron jobs aren't finishing.

To kill them you need two things
1) SSH access under the same user as the cron job is running (usually just your cpanel username)
2) the process ID (PID)

Then it's simple

$ Kill -9 PID

All done.

Course, you shouldnt kill active processes. Kill -9 is very harsh, and can cause problems if the cron job was actually half way through doing something. Better to wait maybe a day or so before killing processes!

Tuesday, 7 February 2012

Show an image in any .phtml file with a RELATIVE link, i.e. not hardcoded!

Thing about magento you learn pretty soon in...

...how you code stuff is VERY dependent on where you're putting the code.

This works in .phtml files. Or I guess, any files where php will be parsed. Maybe.

<img src="<?php echo $this->getSkinUrl('images/btn_trash.gif') ?>" alt="" />

Of course, the image is in your skin/frontend/<yourtemplate>/images/ folder

nice, neat way of making your site not break if you move it ;)


Monday, 6 February 2012

Another way of doing a bog standard link

Sometimes an <a> tag isn't appropriate.

You can also use:


onClick="location.href='index.html'"


inside any other tag. 

example

<img src="photo of a dog eating a cow.jpg" onClick="location.href='index.html'">

awesome. 

Sunday, 5 February 2012

Search boxes anywhere!

A quickie:

<?=$this->getLayout()->getBlock('top.search')->toHtml()?>

will put a search box anywhere you want!

 

Backing up your Magento DB. Go Take a Dump. Literally

Pun intended.

Cpanel db backup, mysql export, they're all rubbish with large databases (i.e. >10mb). I don't know why they bother.

To do it properly, you *need* ssh access to the server, or some other shell access. If you dont have it, get it. Seriously.

Once you're in the shell:

~> # mysqldump -u [your cpanel login] -p [FULL_dbname] > backup.sql


Then you have yourself a proper reliable sql file.

Remember to turn off the foreign key check before you import!

Oh no! Easy tabs messes up my product view page!

Now, this one can be a little infuriating.

After installing the awesome easy tabs plugin
http://www.magentocommerce.com/magento-connect/magento-easytabs.html

You suddenly find that any mods you've previously done to your product view page disappear.

Like say, a lightbox mod.

Oh no!

Simple answer: easy tabs uses this file:

app\design\frontend\yourtemplate\default\template\easytabs\catalogproductview.phtml

instead of what you would have been using before:

app\design\frontend\yourtemplate\default\template\catalog\product\view.phtml.


So there you go. Copy your code across.