Get all parent id of sub category


Consider this tree as example.

2
 - 5
   - 8
 - 6
   - 9
   - 12
     - 20

The easiest way to do so is this:

$category = Mage::getModel('catalog/category')->load(20);

Each category has a field called path that contains the ids of the parents and current category.

$path = $category->getPath();

This should return something like this 1/2/6/12. All you need to do is to split this string by / and remove the first element. That one is the id for ‘root of all roots’.

$ids = explode('/', $path);
unset($ids[0]);

Delete all custom option on catalog_product_save_before event using observer


Hope you have configure observer for this event.if not please configure and add below code to it.

$product            = $observer->getProduct();
if ($product->getId()) {
            $productMod = Mage::getModel('catalog/product')->load($product->getId());
            $opt        = $productMod->getOptions();
            foreach ($opt as $o) {
                /** delete the selected custom option **/
                $o->getValueInstance()->deleteValue($o->getId());
                $o->deletePrices($o->getId());
                $o->deleteTitles($o->getId());
                $o->delete();
            }
        }

Create custom e-mail template in magento


I hope you are aware with the system.xml file in magento so we will not go deep in to it.just add below code to your system.xml file to add select box for choose our custom template.


<email_template translate="label">
<label>Email Template (Sender Notification)</label>
<frontend_type>select
<source_model>adminhtml/system_config_source_email_template
<sort_order>30
<show_in_default>1
<show_in_website>1
<show_in_store>1

The next step is to add an html-template of the letter. /app/locale/en_US/template/email/contact_sender_notification.html

<!--@subject My Email Subject Subject @-->
<!--@vars {"store url=\"\"":"Store Url", "var logo_url":"Email Logo Image Url", "var logo_alt":"Email Logo Image Alt", "htmlescape var=$data.name" : "Email sender contact form" } @-->
<!--@styles body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; } @-->

<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
            <!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
                        <a href="{{store url=""}}" style="color:#1E7EC8;"><img src="{{var logo_url}}" alt="{{var logo_alt}}" border="0"/></a></td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign="top">
<h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Dear {{htmlescape var=$data.name}},</h1>
Some text</td>
</tr>
<tr>
<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;">
<center>

Thank you again, <strong>{{var store.getFrontendName()}}</strong>

</center></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
IMPORTANT NOTE :: On the above section you have notice commented code it is not actually commented.

But it use internally in magento to setup subject and var.
If you forgot to define subject it will send mail and raise exceptions in log file.

After adding the code (see above) we will declare the template in the configuration file and will set the template as default in Email Template (Sender Notification) app/code/local/namespace/module/etc/config.xml

<config>
    …
     <global>
         ...
        <template>
            <email>
               <contacts_sender_notification_email_template translate="label" module="{justmodulenameonly}">
                   <label>Contact Sender Notification</label>
                   <file>contact_sender_notification.html</file>
                   <type>html</type>
               </contacts_sender_notification_email_template>
            </email>
        </template>
        ...
    </global>
     ...
    <default>
        <contacts>
            <sender_notification>
                <email_template>contacts_sender_notification_email_template</email_template>
            </sender_notification>
        </contacts>
    </default>
...
</config>

IMPORTANT NOTE :: in the above config.xml file. “contacts_sender_notification_email_template” is the combination of your{section_group_field} of your system.xml file(Please take care of this otherwise it will not reflect on your configuration).

Now you can send mail using this template.