Magento Ecommerce Strategy, Design & Development

How to get Product image url from product id or SKU?



Example 1:



Example 2:




Example 3 (origional image without resize):


Magento: Set Random Order in Own Collection using RAND() function.

Scenario: You have created a custom module. You have entered certain data in your database. You need to show the data randomly. Solution: In MySQL the rand() function helps the select query to fetch data randomly. In Magento, you can select random rows from MySQL table using Zend_Db_Expr(‘RAND()’). You have to create a new function in your module’s collection class


public function setRandomOrder()
    $this->getSelect()->order(new Zend_Db_Expr('RAND()'));
    return $this;

Now, you can fetch random data from your table using the above create setRandomOrder function. The code below can be kept in the block or template (.phtml) file of your module.

$collection = Mage::getModel('yourmodule/yourmodule')

Read more

How many files are in a typical magento install

Well, I just did another install of Magento and as a Magento developer I always wanted to know roughly how many files and folders are in that. I did do some custom work to this install, so these number are slightly higher than whats in a fresh install but its rather impressive: First here is the command I ran: for t in files links directories; do echo `find . -type ${t:0:1} | wc -l` $t; done 2> /dev/null The output showed: 20384 files 0 links 5165 directories Now thats a lot of files and folders!

Rsync to remote computer

To get all items in remote folder

rsync -v -r --exclude-from 'exclude-sample.txt' -e ssh user@ /path/to/local/computer/folder/

To only get new items from remote folder:

rsync -vru -e ssh dev@ /path/to/local/computer/folder/

To show the progress of the transfer

rsync -e ssh user@ /path/to/local/computer/folder/ --progress

Remove all customers from Magento

SET FOREIGN_KEY_CHECKS=0; -- reset customers TRUNCATE customer_address_entity;

TRUNCATE customer_address_entity_datetime; TRUNCATE customer_address_entity_decimal;

TRUNCATE customer_address_entity_int; TRUNCATE customer_address_entity_text;

TRUNCATE customer_address_entity_varchar; TRUNCATE customer_entity;

TRUNCATE customer_entity_datetime; TRUNCATE customer_entity_decimal;

TRUNCATE customer_entity_int; TRUNCATE customer_entity_text;

TRUNCATE customer_entity_varchar; TRUNCATE log_customer;

TRUNCATE log_visitor; TRUNCATE log_visitor_info;

ALTER TABLE customer_address_entity AUTO_INCREMENT=1;

ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1;

ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1;

ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1;

ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1;

ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1;


Read more

Adding time to the Magento adminhtml Form

Have you ever wanted to know how to put a time on the adminhtml Form.php

               $dateFormatIso = Mage::app()->getLocale()->getDateTimeFormat(

        $fieldset->addField('date_start', 'date', array(
            'label'        => Mage::helper('enterprise_catalogevent')->__('Start Date'),
            'name'         => 'date_start',
            'required'     => true, 
            'time' => true,
            'image'        => $this->getSkinUrl('images/grid-cal.gif'),
            'format'       => $dateFormatIso

The magic is the 'time' line. By adding , 'time' => true, it puts the time at the bottom of the calendar.

Feel free to checkout our Magento support if you would like some help with this.