How to send category based order emails in magento?

前端 未结 2 1013
野的像风
野的像风 2021-01-21 07:56

I have two root categories in my magento site. One is \"Home Products\" and the other is \"Office products\".

These two root categories have some sub categories also.

相关标签:
2条回答
  • 2021-01-21 08:56

    I suggest you to write own Observer to order.

    sales_order_place_after
    

    event suits best for your purpose.

    If buyer can add to shopping cart items only from 1 cateogry.

    Your module should:

    1. Get order via observer.
    2. Get order first item and get it's category
    3. Choose email based on category

    Send email

     public function sendOrder(){
        $order = $observer->getEvent()->getOrder(); 
                ...
                //Implement logic here
                ...
    
        $emailTemplate  = Mage::getModel('core/email_template')
                        ->loadDefault('your_template');                            
        $emailTemplateVariables = array();
        $emailTemplateVariables['order'] = $order;      
        $emailTemplate->setSenderName('Your shops name');
        $emailTemplate->setSenderEmail('addres@from.com');
        $emailTemplate->setTemplateSubject(Subject');
        $emailTemplate->send('to@addres.com','Name', $emailTemplateVariables);          
     }
    

    Update 1

    First of all I insist that you see the link I provide in the comments area.

    Then: To create module:

    1. Create in app/etc/modules/ Company_Module.xml file. With the content similiar to this one:

      true local This eill tell magento, that in app/code/local/Company/Module there is something interesting to watch.

    2. Create proper folder and file structure. For you module I think it would be enough:

      Company
      -Module
      --etc
      ---config.xml
      --Model
      ---Observer.php
      --Helper
      ---Data.php
      
    3. Magento should know everything about your module. Moreover you should define observer for event. Important note: we will catch Magento's event. Not ours.

    config.xml:

        <?xml version="1.0"?>
        <config>
            <modules>
                <Company_Module>
                    <version>0.1.0</version>
                </Company_Module>
            </modules>
            <global>
                <models>
                    <company_module>
                        <class>Company_Module_Model</class>
                    </company_module>
                </models>
                <helpers>
                    <cmod>
                        <class>Company_Module_Helper</class>
                    </cmod>
                </helpers>
                <events>
                    <sales_order_place_after>
                        <observers>
                            <sales_order_place_after_observer>
                                <class>company_module/observer</class>
                                <method>handleOrder</method>
                            </sales_order_place_after_observer>
                        </observers>
                    </sales_order_place_after>
                </events>
            </global>
        </config>
    

    Data.php - It is empty but it should be.

        class Company_Module_Helper_Data extends Mage_Core_Helper_Abstract{
    
        }
    

    Observer.php

        class Company_Module_Model_Observer{
                public function handleOrder($observer){
                        $order = $observer->getEvent()->getOrder();   
                                ...
                                //Implement logic here
                                ...
    
                        $emailTemplate  = Mage::getModel('core/email_template')
                                ->loadDefault('your_template');                            
                        $emailTemplateVariables = array();
                        $emailTemplateVariables['order'] = $order;        
                        $emailTemplate->setSenderName('Your shops name');
                        $emailTemplate->setSenderEmail('addres@from.com');
                        $emailTemplate->setTemplateSubject(Subject');
                        $emailTemplate->send('to@addres.com','Name', $emailTemplateVariables); 
                }
        }
    
    0 讨论(0)
  • 2021-01-21 09:01

    @Jevgeni (and anyone else needing the link), the Link for Magento has moved

    http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

    0 讨论(0)
提交回复
热议问题