Find URLs in Text description With Regex PHP

Saturday, 20. October 2012

This little regex script gives you another simple way to fetch for all possible URLs embedded as simple text in a your rather large description text.

It’s flexible and you can add more filters appropriate for your requirement as you wish..

# take it to the test!
$matches = null;
$returnValue = preg_match_all('%(https://|http://|www)[a-zA-Z0-9\/#&-_\.]+%', $desc_variable, $matches);
# see what you got!


Can’t save customer – call_user_func Zend Validate Hostname Com getCharacters

Thursday, 18. October 2012

A rather strange error on live server happened when customers try to register an account they get and error message “Can’t save customer”.

After a bit of digging and throwing lots of exceptions – came to find the solution as explained below..

** HANG ON – Ideally you will want to make these changes on your local folder. Please don’t edit the core files **

Go to file: lib/Zend/Validate.

Scroll down to around line 324 where you will spot a script similar to:

     if (Zend_Loader::isReadable($classFile)) {

Replace that line with:

     if (file_exists($classFile) && Zend_Loader::isReadable($classFile)) { 
      # added: file_exists($classFile) &&

RESET Mysql Root Password In LAMPP or XAMPP

Sunday, 30. September 2012

If you are reading this, chances are you have either lost or forgotten your mysql root password and definitely in need of help!

OK – this solution assumes you have access to your Lampp installation files.

- Go to your config file: lampp/etc/my.cnf 
- Open the file and look for text: [mysqld]
- Under it, insert text: skip-grant-tables
- Restart MySQL

Now access your phpmyadmin: localhost/phpmyadmin. You should be able to log in without the need of password

You can now change/reset the root password to something else:

UPDATE mysql.USER SET Password='new_password' WHERE USER='root'


Custom options changing product price to zero Magento 1.7

Thursday, 21. June 2012

After an upgrade to the latest version of Magento – time of writing 1.7, we noticed that the custom options selection was changing the price to zeros instead of updating them.

Turned out there was a bug in the options.phtml file of the current theme – and suprisingly on the base/default too.

To fix the problem

Locate the file: in app/design/[your package]/[your_theme]/template/catalog/product/view/options.phtml on around line 141

Then change

if (this.config[optionId][selectOption.value]) {
   price += parseFloat(this.config[optionId][selectOption.value]);


if (this.config[optionId][selectOption.value]) {
   price += parseFloat(this.config[optionId][selectOption.value].priceValue);


If your theme has this line instead

   price += parseFloat(this.config[optionId][element.getValue()]);

Change it to:

   price += parseFloat(config[optionId][element.getValue().price]);

Only variables should be passed by reference in lib_Zend_Db_Select line 246

Wednesday, 13. June 2012

Had this strange error today while doing a database backup via Magento admin

Strict Notice: Only variables should be passed by reference  in ../lib/Zend/Db/Select.php on line 246
#0 ../lib/Zend/Db/Select.php(246): mageCoreErrorHandler(2048, 'Only variables ...', '/var/www/client...', 246, Array)

After a bit of digging around, the issue was simply solved by doing the following:

– Navigate to: /lib/Zend/Db/Select.php and go to live 246


$correlationName = current(array_keys($this->_parts[self::FROM]));

– Replace that with

$correlationName = array_keys($this->_parts[self::FROM]);
$correlationName = $correlationName[0];

Please NOTE:
You have just edited the core file there. I will recommend you take a note of this for future reference.

Add custom attributes to Magento product grid or listing page

Saturday, 14. April 2012

Thought this will help someone. If you want to use a custom attribute in category product listing pages follow these steps below:

1) Ensure addAttribute Method exists
Navigate to app/code/core/Mage/Catalog/Block/Product/List.php. Search for a method called addAttribute

This should already been added with new versions of Magento, but if your version doesn’t have it. Copy this file to


Then before the end of class add this script:

   * Use this method in layouts for extra attributes
   * @param string $code internal name of attribute
  public function addAttribute($code)
    return $this;

2) Update your catalog.xml file
Once we have the method in place. Now navigate to your theme’s catalog.xml file and open it.
– Look for handlers catalog_category_default and catalog_category_layered
– then add your attribute codes as show below:

    <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">			
	<action method="addAttribute"><name>attribute_code</name></action>
	<action method="addAttribute"><name>attribute_code2</name></action>

3) Use your attribute in list.phtml page
Now you can use the attribute in your theme’s list.phtml page just as normal.

    echo $_product->getAttributeCode(); # OR
    echo $_product->getData('attribute_code2'); # OR
    echo $_product->getAttributeText('attribute_code2');


Zend_Db_Statement_Exception Lock wait timeout exceeded try restarting transaction

Friday, 13. April 2012

If you have ever come across this error Next exception ‘Zend_Db_Statement_Exception’ with message ‘SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction’ while running long queries these can possibly be one of your solutions

1) Best option is to try and reduce/break the size of your query into small queries.

2) If reducing the size of your queries is not an option, you may try this. In you my.cnf file (somewhere /etc/mysql/my.cnf) look for and change/add the following entry

innodb_lock_wait_timeout = 50 # Set this to a big number to cater your needs!

REMEMBER: You will need to Restart mysql for changes to take effect. Then re-run your query.

Remember to change the value back to small number while on production server. Its there as a small value for a reason!!

Zend_Cache_Exception can’t get apc memory size

Thursday, 12. April 2012

trying to run Magento indexes on command line is an excellent way to get things done rather quickly. However there are times it can be rather annoying and more so when performance enhancement measueruses such as APC cache is in place.

A common error with APC cache exception ‘Zend_Cache_Exception’ with message ‘can’t get apc memory size’ in lib/Zend/Cache.php:209 can be very annoying and if like me you have been scratching your head over this, the post may be your solution.

After soul searching I came to find out this is merely a configurations issue and the most common settings you need are these below.
apc.enable_cli=1    # VERY IMPORTANT

You will need to add these entries to your apc.ini file that can be found (at least on my server)


REMEMBER you will need to restart apache for these changes to take effect.


Setting Up Magento Cron Jobs Via SSH Command Line

Tuesday, 10. April 2012

Setting up cron jobs via command line tool is easy if you know how. First you will need to open the cron tab before you can enter and schedule your tasks.

This simple walk through will shade some lights on how to do just that and what are the required setting to complete a successful job setup.

1) Opening the Cron Tab

To open the cron tab as the user you are logged in as type:

crontab -e

To open the cron tab as a specific user, type:

crontab -u USERNAME -e

Time Format Steps:
minute hour day month day-of-week

minute 0-59
hour 0-23
day 1-31
month 1-12
day-of-week 0-7 (where both 0 and 7 mean Sun, 1 = Mon, 2 = Tue, etc)

This is how the cron should look

min hour day month dayofweek command_to_run

Examples: What stuff really means

0 1 * * *  ==> Every day at 1Am
* * * 12 * ==> December
14,29,44,59 * * * * ==> at after 14, 29, 44 and 59 minutes every hour of everyday
*/5 * * * * ==> Every 5 minutes

Now that you know where to add your cron job command, let’s go through two simple ways to set it up.

Magento Cron Job Using WGET

*/5 * * * * wget -q

Magento Cron Job Using PHP

*/5 * * * * /path/to/php -f /local/path/to/cron.php

Testing The Magento Cron Jobs

It is difficult to test that the Magento cron jobs are now set up correctly without waiting a couple of days and seeing whether your indexes have been refreshed. Fortunately, there is a quick test you can perform to tell. Change your cron tab command to one of the following (depending on the method you chose).

[email protected]
*/5 * * * * wget-bad-command -q
[email protected]
*/5 * * * * /path/to/php -f /local/path/to/cron-bad-filename.php

More examples

# run at 10 pm on weekdays, 
0 22 * * 1-5   mail -s "It's 10pm" ken%Ken,%%Where is food?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun     echo "run at 5 after 4 every sunday"

There was a problem with reindexing process – Magento

Thursday, 23. February 2012

For anyone working with Magento, I am sure you have come across There was a problem with reindexing process error at least once in your life time using Magento.

As you can tell, the error is not always very explicit on what the issues is and more than often its because MySQL database has encountered an error and could not proceed with the process.

Best way I have found to deal with this is get a bit more information is to run the PHP shell script for re-indexing the database that comes with your Magento install. This will throw detailed message to you on what went wrong!

Open your command line tool and navigate to the root of your Magento site (htdocs or publich_html etc) and type this commend.

php shell/indexer.php reindexall

Sit back and observe!