home | contact us
» » August


If you have a long running script that is designed to run as cron but may be run manually from the terminal then you may want to enforce screen so that the process can’t be aborted by the SSH terminal being closed for whatever reason.

We already blogged about how to force running as screen here.

This is an extension of this that also checks for running as Cron and if so, does not force screen.

# First off, ensure running from Cron and if not, Screen
if [ -t 1 ]
then
    echo "Not running as Cron Task"
    if [ -n "$STY" ];
    then
        echo 'We are inside screen, good';
    else
        echo "Not in a screen, please run with screen"
        echo "Exiting"
        exit 1
    fi
else
    echo "Running as Cron Task"
fi

Simply paste this somewhere close to the top of your script before it does anything and this will work nicely.


 

In certain places in Magento, you can simply access the data from an object by property, but beware!

For instance, in the product template the following two code snippets have the same effect :-

$_qty = $_product->stock_item->stock_qty;

and

$_qty = $_product->getStockItem()->getStockQty();

However only the latter will work if you call it from the category view. This is because the product is not fully loaded, and even doing a

$_newproductobject = Mage::getModel('catalog/product')->load($_product->getId());

will not help!

So the moral of this is, use the getters not the magic property.


 

One of the things that often frustrates those who have used Photoshop in the past often complain about the switch to Linux and the GIMP specifically is the lack of groupable layers.

There is a plugin that does provide this functionality, albeit in a rather unintuitive manner :-

It’s called LayerGroups and is at http://registry.gimp.org/node/16563

This is a really useful feature and really does need an overhaul on the usability stakes but might be useful if you are moving to Linux from Windows.


 

It appears that all the paypoint (formally secpay) modules have vanished from the magento connect site.

This is a pain for a lot of people who have chosen the gateway to service their payments, and leaves two options for most people :-

  • * Choose a different provider
  • * Get a custom module written

As Magento developers we’re happy to quote for the latter option, but we expect a lot of people will go for the former.


 

Sometimes when your cron process in Magento seems to not be working it is worth doubling up the ways it gets executed.

One reason for this is various extensions (notably EERP from boostmyshop) set up an override to ensure that the same cron task is not run a second time if it’s still running when the first run happens.

Often the cli setup for php is not configured with the same timeouts etc. that the web setup is. Therefore one thing that can make your cron more “stable” is to use wget or curl to fetch the cron.php file rather than (or as well as) running the cron.sh script.

Here’s what to add to the server’s crontab (/etc/crontab or crontab -e) to use wget to fire off the cron :

* * * * * /usr/bin/wget -O- www.mycoolsite.com/cron.php > /dev/null 2> /dev/null

That of course needs the url changing to match your domain. It’s worth noting that having output and stderror piped to /dev/null in a crontab is probably not the best practice but given that any module can create cron tasks that output stuff, your sysadmin might dislike getting that emailed to them!


 

Not the most elegant way to do this, and probably could do with some extra tweaks but it works for our purposes, so presented here in case it fits yours :

# xml_value path/to/file node_key
function xml_value(){
    grep "<$2>.*<.$2>" $1 | sed -e "s/<\!\[CDATA\[//" | sed -e "s/\]\]>//" | sed -e "s/^.*<$2/<$2/" | cut -f2 -d">"| cut -f1 -d"<"
}

It also strips out the CDATA tags, which we needed to pull the database details from Magento’s local.xml

To use this to get, for example, the database host, you would use the following:

DB_HOST=$(xml_value app/etc/local.xml host)

To use this


 

I recently had to develop a bespoke CMS within magento.

One of the requirements was that the system should be very easy to customise, and should use the existing Pages and Static blocks functionality within magento.

I wanted the ability to call a block that I had created from with a static block. Magento allows you to do this using the code below

{{block type='companyname/path_to_block' name='custom.block' template='path/to/template/file.phtml'}}

The issue that I came across if you need to call a method on the block before it is rendered. If I was calling the block using XML I could use the action tag, but that is not avalible here.

However, it is possible to call certain methods using the code above. The magento parser takes each of the pair values and calls a set method on them, so for example template=’path…’ actually calls the setTemplate method on your block.

This means that you can create a set method and trigger it from with in the static block like so


{{block type='companyname/path_to_block' name='custom.block' template='path/to/template/file.phtml' methodName="3"}}


 

If you have a few URLS you are constantly going to and you would prefer a quick keyboard based way of going to them without having to type full URLs then this little extension could be for you.

The concept is very simple. You can create an alias word (eg phpmyadmin) which then redirects to your full phpmyadmin URL.

When you first install it you might set up some aliases and try to use them but get redirected to the google search results pages for that word instead. The extension author has worked around this behaviour by requiring you to put an “a “, the letter a followed by a space, before your alias.

Setting up the aliases is simple and I can already see this becoming one of my must have extensions.

Check it out for yourselves:
https://chrome.google.com/webstore/detail/hnmffkbofelpmfnimaicmkdhimnaegla


 

If you use the disqus plugin on your wordpress site, you may be surprised to learn that your content is hidden on mobile devices (specifically ipad/iphone).

The problem that occurs is that the content is covered by a nice white box that you can’t see through.

Thankfully there’s a nice quick fix. In your site’s css rules, simply add the following :-

#disqus_thread { clear: both !important; }

And mobile users can see your content again!


 

It’s a little bit annoying that such a core feature is just broken in many versions of magento – the headings for the custom options chosen, whilst fully working on the cart; checkout and emails to the customer, only show the heading and no content on the backend order.

There are a couple of fixes :
in
app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Name.php
there is no extending, so you can copy it to
app/code/local/Mage/Adminhtml/Block/Sales/Items/Column/Name.php
and add the following class method :

public function getFormattedOption($value) {
  $_remainder = '';
  $value = Mage::helper('core/string')->truncate($value, 55, '', $_remainder);
  $result = array(
    'value' => nl2br($value),
    'remainder' => nl2br($_remainder)
  );
  return $result;
}

and/or change the admin theme in
app/design/adminhtml/default/default/template/sales/items/column/name.phtml
around about line 44 from :

<?php $_option = $this->getFormattedOption($_option['value']); ?>

to

<?php if (!is_null($this->getFormattedOption($_option['value']))) {
    $_option = $this->getFormattedOption($_option['value']);
} ?>

Then the custom options chosen by customers will happily show in the backend.


 
rss icon