Follow these rules and your mail templates will most likely not be considered as spam: 1. Always wrap the content in … 2. Remove all empty lines 3. Remove all font size definitions, like font:11px/1.35em 4. Avoid spam words such…
Getting the SQL query of a collection (Magento 1)
This short piece of code returns the SQL query behind a Magento collection.
|
1 |
$select = $collection->getSelect()->__toString(); |
Getting the front name of a route programmatically (Magento 1)
Use the ollowing code to get a routes front name:
|
1 2 |
// will display "config" $frontName = (string)Mage::getConfig()->getNode('frontend/routers/whatever/args/frontName'); |
The code will return “config”, if you add the following XML to your modules config.xml:
|
1 2 3 4 5 6 7 8 9 10 11 |
<frontend> <routers> <whatever> <use>standard</use> <args> <module>Company_Module</module> <frontName>config</frontName> </args> </whatever> </routers> </frontend> |
Getting the full country name by country code (Magento 1)
See the following example on how to get the long country name by its short code:
|
1 2 3 4 5 6 7 |
$address = Mage::getModel('customer/address')->load($addressId); // DE, AT ... $countryCode = $address->getCountryId(); // Deutschland, ... $country = Mage::app()->getLocale()->getCountryTranslation($countryCode); |
Loading a mail template by its name (Magento 1)
Use the below code to load a Magento transaction mail template by its name:
|
1 2 |
$templateId = Mage::getModel('core/email_template')->loadByCode('<name>')->getTemplateId(); $template = Mage::getModel('core/email_template')->load($templateId); |
Getting mail template content by name (Magento 1)
Use the following code to get a mail templates content by its name:
|
1 2 3 |
$mailTemplate = Mage::getModel('core/email_template'); $templateByName = $mailTemplate->loadbyCode($templateName); $text = $templateByName ->getData('template_text'); |
Getting mail template content by id (Magento 1)
Use the following code to get a mail templates content by its id:
|
1 2 3 |
$mailTemplate = Mage::getModel('core/email_template'); $template = $mailTemplate->load($templateId); $text = $template->getData('template_text'); |
Adding the message block to a template (phtml) (Magento 1)
If you want to show the Magento messages (success, error, …) in your template file, add the following code the top of your template:
|
1 |
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?> |
Displaying missing image filenames during product imports (Magento 1)
The import tells you when images are missing, but does not identify which images. If you override app\code\core\Mage\Catalog\Model\Product\Attribute\Backend\Media.php and make the following changes to the addImage function, the missing images will be displayed. Find:
|
1 |
Mage::throwException(Mage::helper('catalog')->__('Image does not exist.')); |
Change it to:
|
1 |
Mage::throwException('Not found: ' . $missingImage); |
Now…
Configuring and running cron jobs (Magento 1)
To add and run a Magento cron job in your module, add the following XML to your modules config.xml:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<config> <crontab> <jobs> <some_unique_job_code> <schedule> <!-- every minute for example --> <cron_expr>*/1 * * * *</cron_expr> </schedule> <run> <model>module/observer::functionToRun</model> </run> </some_unique_job_code> </jobs> </crontab> </config> |
Thats the first step. Once that was done, you have to manually or automatically run cron.php. Its in your stores…