Engine23

Development

Rsync to remote computer

To get all items in remote folder

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

To only get new items from remote folder:

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

To show the progress of the transfer

rsync -e ssh user@192.168.1.1:/path/to/remote/file/ /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;

ALTER TABLE customer_entity 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(
            Mage_Core_Model_Locale::FORMAT_TYPE_SHORT
        );

        $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.

Watching a slow query log

watch 'more mysqld-slow.log | grep Query_time | wc -l; more mysqld-slow.log | grep Query_time;' This can be helpful if your trying to debug slow queries or just capture them as they come in.

Magento error: The stock item for Product is not valid.

This can have many causes as your search through the internet has obviously found. My problem with this particular issue was I had my products setup properly, so it was not the fact that it was out of stock. This site almost had me excited but only to find out my product creation script already took care of it: http://zaclee.net/magento/errors-magento/stock-item-for-product-is-not-valid So, after some hard core searching, I found that I was not using the proper product object. The only way I could get my auto add to cart working was to use this $product = Mage::getModel('catalog/product')->load($product_id); I had a different product object, ( loading by the sku ) and apparently you can not use that type of object to add items to the cart. 5 hours of my life lost, hopefully to spare yours.

Magento Programmatically add an item to the cart with custom options

Lest say you have a need in your Magento store to have an "auto add to cart". This would be in situations where maybe you provide a free sample if they purchase a specific product, or maybe you will attach a warranyt sku to specific products automatically. However, this item your adding to the magneto cart has custom options! This can be tricky. Here is an example function I use when I run into this situation.

 
    protected function _saveCustomOption($product_id, $product, $qty)
    {
        // Load up a product that has the custom options and get the attributes, in this case we just have one custom option
       // This custom option is a text field and our end goal is to populate that with sku-product name
        $_product   = Mage::getSingleton('catalog/product')->load($product_id);
        $attrs      = $_product->getOptions();
        foreach($attrs as $attr)
        {
           // Loop through all the custom options ( once again we only have one in our scenario ) and assign the values we need        

Read more

Webmin Lockout

If you have ever received a message similar to:

The host has been blocked because of too many authentication failures.

Fear not, just restart the service and you can log back in again! $ /etc/init.d/webmin stop ( hit enter ) $ /etc/init.d/webmin start ( hit enter ) Viola, service running and you can log back in again.