October 19, 2016 17:52
Sometimes you want to get the date range from MySQL without table. Here you are:
SELECT '2016-09-01' + INTERVAL a + b DAY AS date_selected
FROM
(SELECT 0 a UNION SELECT 1 a UNION SELECT 2 UNION SELECT 3
UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7
UNION SELECT 8 UNION SELECT 9 ) d,
(SELECT 0 b UNION SELECT 10 UNION SELECT 20
UNION SELECT 30 UNION SELECT 40) m
WHERE '2016-09-01' + INTERVAL a + b DAY < '2016-10-01'
ORDER BY a + b
It is useful when you want to generate some reports.
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.
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.
April 30, 2013 20:20
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?
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:

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

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!
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.
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
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 ~
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
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?