Test a cron module in #magento

Recently, I’ve developed a cron module script to send scheduled¬†newsletters. During the development, I had to hit a lot of time cron.php to test it, but, of course, I needed to wait at least 1 minute to check the result. That is because 1 minute is the minimum cron interval time.

So, I googled a bit and I found a script to test module models. With minor changes, it also works to test cron scripts:

The script has to be saved in domain/module folder and its direct execution has to be allowed in the app/.htaccess file, removing the deny directives.

#Javascript translations. The #magento way

Text translations in magento are very easy. You just need to use a syntax in you code like this:

<?php echo $this->__('Text to translate');?>

then in your theme locale folder you have to create a csv file like this:

"Text to translate","Text translated"

But how to apply the same mechanism to javascript files? Since Magento 1.7 there is a Translator object, so in any javascript file you can use a syntax like this:

Translator.translate('Text to translate')

Then you need to add a jstranslator.xml file in the module:

<jstranslator>
<mystring translate="message" module="yourmodule">
<message>Text to translate</message>
</mystring>
</jstranslator>

Mystring should just be an unique tag.

In this way, Magento will use the string from the same csv file used for html text :)

How to avoid fatal error if an image doesn’t exist in #Magento

Recently, I developed a slider to show product details and image in home page. I added a new slider_img product attribute to allow the selection of an image, but if any error had occurred during the image loading process, the whole slider didn’t work at all. I tried several checks using if/else, but the best was using try/catch and logging:

Using try/catch, seems the best option in order to avoid a fatal error and so the slider works fine showing other product details

Setup Apache password protected directories

Check the virtual server configuration AllowOverride parameter. It should be:

AllowOverride All

or at least

AllowOverride AuthBasic

Create an .htpassword file using the command:

htpasswd -c .htpassword username

Add directives to .htaccess file in the root foolder

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /file_path/.htpassword
Require user username

Check if the .htpassword file is readable by Apache user (www-data)

Restart the webserver

Remove the review block in #magento

I was working on a bootstrap template that uses the same product view template for a
quickview in home page.
My client needed to remove some blocks from the quickview layout, so I used the remove method in the xml file. I was able to remove everything except the reviews because they were rendered by this function:

$this->getReviewsSummaryHtml()

instead of the usual getChildHtml() function.

So I removed that function from the main product view and I used a wrapper block called product.info.review_custom. Then, using:

remove name="product.info.review_custom"

worked.
I hope there are any drawback using this workaround.