How to setup PhpStorm for Drupal

July 12, 2013 12:50

PhpStorm is a great IDE with PHP. By default it supports Drupal development. Please refer to TigerFish’s blog – Setting up JetBrains PhpStorm for use as a Drupal IDE for detail.

Enjoy the powerful of PhpStorm.

Share

Get correct date and time in Magento

June 3, 2013 17:38

How to get the correct date and time in Magento with timezone? Here you are:

date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));

That is.

Share

How to search utf8 wordings in Magento Enterprise Edition with Solr?

April 30, 2013 20:20
Tags: , , ,

Magento Enterprise Edition has an option that can use the Apache Solr for the indexing and searching engine. For English searching is working like a charm, however, not working well with UTF8 encoding like Traditional Chinese.

I’ve found that it is because the class “Apache_Solr_Service” sends the search request to Solr with the content-type “application/x-www-form-urlencoded”. This content type doesn’t specific the charset is UTF8, and sends the wrong encoded search text to Solr. At the end, for sure that unexpected result will be returned.

It’s very easy to fix this problem. First copy the file “lib/Apache/Solr/Service.php” to “app/code/local/Apache/Solr/Service.php”, then modify “app/code/local/Apache/Solr/Service.php” line 968 from:

    return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded');

to

    return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');

That is, great?

Share

How to add logo or additional information to custom payment method in Magento?

April 25, 2013 17:08

After you finished the functionality of the custom payment module, you may find that the payment method shows in checkout page is without logo:

payment_method_without_logos

How to add the logo or other additional information below the name of payment method as below image?

payment_method_with_logos

Well, quite easy.

Step 1: in your module config.xml, add following tags in <frontend>:

<layout>
    <updates>
        <your_module_name>
            <file>your_module_name.xml</file>
        </your_module_name>
    </updates>
</layout>

Step 2: add your_module_name.xml in app/design/frontend/<package>/<theme>/layout/:

<?xml version="1.0"?>

<layout version="0.1.0">
    <checkout_onepage_index>
        <reference name="checkout.payment.methods">
            <block type="core/template" name="payment.method.<your_payment_method_code>" template="<your_module_name>/<whatever.phtml>" />
        </reference>
    </checkout_onepage_index>
</layout>

Step 3: add <whatever.phtml> in app/design/frontend/<package>/<theme>/template/<your_module_name>/:

<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); ?><your_module_name>/card_sm_visa.gif" alt="<?php echo $this->__('VISA'); ?>" />
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); ?><your_module_name>/card_sm_masterc.gif" alt="<?php echo $this->__('Master'); ?>" />
<div class="additional_info">
    Other additional information
</div>

That is, done!

Share

How to validate your data in Magento?

April 16, 2013 14:39

You should face to data validation when you do some customize development in Magento. The frontend validation is using class element combined with the magic of prototype in “js/prototype/validation.js”. Backend validation simply calls Zend_Validate in every Model->validate() method. Inchoo posted a article about validation which can give you a draft idea about them.

Share

Observer Event Order from Alan Storm

April 11, 2013 19:10

Today Alan Storm made a good answer for the question about the observer event order. Please have a look at below link and you will have a great understanding about the observer event.

http://stackoverflow.com/questions/15934553/how-do-you-set-the-sort-order-for-event-observers-in-magento

Share
Comments Off

How to add product qty to your product collection

March 25, 2013 15:14

Sometimes you have to add the product qty to your product collection which is not included in default. Normally people will get the collection first, then run the below code per product:

$qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();

If you have more than 10000 records, it spends too much time by additional SQL query and increase server loading. Actually you can join the inventory table when you are getting the collection as below codes:

$productCollection = Mage::getModel('catalog/product')->getCollection();
$productCollection->joinField('qty', 'cataloginventory/stock_item','qty','product_id=entity_id', '{{table}}.stock_id=1','left');

foreach ($productCollection as $product) {
    echo $product->getQty();
}

More efficient, right?

Happy Magento’ing ~

Share

MIGS (Server Hosted) for Virtuemart

August 16, 2012 11:23

Recently my company’s shopping cart which using Virtuemart with Joomla needs to change the payment gateway from Pay Dollar to MIGS. I’ve made MIGS payment gateway using “Server Hosted” method for Magento two years ago but no idea how to implement payment gateway for Virtuemart. I’ve searched in Google but only find “Merchant Hosted” codes, but not “Server Hosted” which my company preferred. So I decided to use some implemented codes and modified it.

I’ve downloaded the zip file from Tony Milne website and modified the codes which refer to PayPal payment gateway in Virtuemart. It’s done now and the payment gateway work perfectly. Here I would like to share the codes to everyone. Please free feel to use or modify the codes together with Tony Milne’s license.

Downlaod: mw_ps_migs.zip

Share

Split email username and domain name in Excel

December 9, 2011 11:42

How to split email username and domain name to two cells in Excel? Suppose the email address is in A2 cell.

Grab domain name from email
=MID($A2,FIND(“@”,$A2)+1,LEN($A2)-FIND(“@”,$A2)+1)

Grab username name from email
=MID($A2,1,FIND(“@”,$A2)-1)

Easy, right?

Share
Comments Off

How to create member only module in Magento?

June 13, 2011 14:26

Sometimes you may have to implement the module that is for member only, how to do it in Magento?

In your controller which extends Mage_Core_Controller_Front_Action, add the following function:

        public function preDispatch() {
            parent::preDispatch();

            $action = $this->getRequest()->getActionName();
            $loginUrl = Mage::helper('customer')->getLoginUrl();

            if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) {
                $this->setFlag('', self::FLAG_NO_DISPATCH, true);
            }
        }

If the customer didn’t login, the controller will redirect the page to login page.

Got it?

Happy Magento’ing ~

Share