Chủ Nhật, 8 tháng 5, 2016

Increasing “Make contact with people” features within Magento


One regarding the particular many crucial facets of virtually any enterprise will be customer care. That is actually essential to be able to permit your current consumers to simply get to in order to an individual when they will have to make contact with a person.

Out there associated with the actual container Magento gives good web form upon “Contact us” webpage wherever clients can easily enter in their own details and also post assistance ask for with no beginning their particular e-mail consumer as well as browsing regarding your own consumer services e mail.

Nonetheless , occasionally honestly, that is certainly not adequate. Based upon of the company sort and also sizing, you might want to break up your own client help in to division to be able to increase your current effectiveness regarding dealing with assistance demands.




Thankfully, it may be not really complex thus let us commence!

Signing up the module

Note: I am working with fresh install of recent Magento CE 1 . nine. 2 . 3 with small sample data

We will certainly override primary Magento component named Colleagues therefore we will furthermore title our own component Buddies through adding that in order to the particular Inchoo merchant chart inside regional program code pool area. 1st phase will be to be able to sign up the component within Magento simply by producing Inchoo_Contacts. xml in app/etc/modules folder of our own project. The record ought to seem anything just like this specific:

 <? xml version="1. 0"? > 
  <config> 
  <modules> 
  <Inchoo_Contacts> 
  <active>  true  </active> 
  <codePool>  local  </codePool> 
  </Inchoo_Contacts> 
  </modules> 
  </config> 
Now, let us create our own quests directory website framework in app/code/local directory. Very first we all generate Inchoo directory site as well as and then put youngster directory website named Colleagues. Today all of us have got website directory construction such as this particular: app/code/local/Inchoo/Contacts. Next thing is actually in order to help to make the segments setup document, just where all of us establish just about all types, adjoint, occasions and so forth . Help to make and so on listing inside app/code/local/Inchoo/Contacts and also produce config. xml file. We all may then add simple details within that will document, our own component brand as well as model, thus config. xml must appear just like this specific:

 <? xml version="1. 0"? > 
  <config> 
  <modules> 
  <Inchoo_Contacts> 
  <version>  one 0. 0  </version> 
  </Inchoo_Contacts> 
  </modules> 
  </config> 
Now the off shoot ought to be signed up inside Magento and also detailed within supervision inside Configuration→Advanced under “Disable Modules Output” party, yet this does not whatever it takes, therefore let us alter which.

Producing after sales logic

Alternative will be to be able to allow management customers in order to determine fresh email messages which ought to end up being obtainable with regard to “Get in touch with us” web page, as well as include “Obtainable in get in touch with all of us webpage” environment with regard to present e-mail. Sadly, to be able to moderators effectively put brand new email messages we all must generate somewhat difficult common sense and also apply main grid within administrative and we will not carry out that will today. Rather all of us will certainly include brand new e mail job areas inside our own system. xml record wherever we all may change the Setup web page inside supervision section. Thus , throughout and so forth directory site associated with our own component produce system. xml record as well as replicate next computer code:

 <? xml version="1. 0" encoding="UTF-8"? > 
  <config> 
  <sections> 
  <trans_email> 
  <groups> 
  <ident_sales> 
  <fields> 
  <contact_us> 
  <label>  Available on contact us web page  </label> 
  <frontend_type>  choose  </frontend_type> 
  <sort_order>  thirty  </sort_order> 
  <show_in_default>  one  </show_in_default> 
  <show_in_website>  a single  </show_in_website> 
  <show_in_store>  one particular  </show_in_store> 
  <source_model>  adminhtml/system_config_source_yesno  </source_model> 
  </contact_us> 
  </fields> 
  </ident_sales> 
  <ident_support> 
  <fields> 
  <contact_us> 
  <label>  On contact us page  </label> 
  <frontend_type>  select  </frontend_type> 
  <sort_order>  30  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  <source_model>  adminhtml/system_config_source_yesno  </source_model> 
  </contact_us> 
  </fields> 
  </ident_support> 
  <ident_repair> 
  <label>  Repair  </label> 
  <frontend_type>  text  </frontend_type> 
  <sort_order>  9  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  <fields> 
  <name translate="label"> 
  <label>  Name (Label)  </label> 
  <frontend_type>  textual content  </frontend_type> 
  <backend_model>  adminhtml/system_config_backend_email_sender  </backend_model> 
  <validate>  validate-emailSender  </validate> 
  <sort_order>  ten  </sort_order> 
  <show_in_default>  just one  </show_in_default> 
  <show_in_website>  one  </show_in_website> 
  <show_in_store>  a single  </show_in_store> 
  </name> 
  <email translate="label"> 
  <label>  Email  </label> 
  <frontend_type>  text  </frontend_type> 
  <validate>  validate-email  </validate> 
  <backend_model>  adminhtml/system_config_backend_email_address  </backend_model> 
  <sort_order>  20  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  </email> 
  <contact_us> 
  <label>  Available on contact us page  </label> 
  <frontend_type>  select  </frontend_type> 
  <sort_order>  30  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  <source_model>  adminhtml/system_config_source_yesno  </source_model> 
  </contact_us> 
  </fields> 
  </ident_repair> 
  <ident_returns> 
  <label>  Returns  </label> 
  <frontend_type>  text  </frontend_type> 
  <sort_order>  10  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  <fields> 
  <name translate="label"> 
  <label>  Title (Label)  </label> 
  <frontend_type>  text  </frontend_type> 
  <backend_model>  adminhtml/system_config_backend_email_sender  </backend_model> 
  <validate>  validate-emailSender  </validate> 
  <sort_order>  1  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  </name> 
  <email translate="label"> 
  <label>  Email  </label> 
  <frontend_type>  text  </frontend_type> 
  <validate>  validate-email  </validate> 
  <backend_model>  adminhtml/system_config_backend_email_address  </backend_model> 
  <sort_order>  20  </sort_order> 
  <show_in_default>  1  </show_in_default> 
  <show_in_website>  1  </show_in_website> 
  <show_in_store>  1  </show_in_store> 
  </email> 
  <contact_us> 
  <label>  Available on contact us webpage  </label> 
  <frontend_type>  pick  </frontend_type> 
  <sort_order>  fifty  </sort_order> 
  <show_in_default>  one particular  </show_in_default> 
  <show_in_website>  just one  </show_in_website> 
  <show_in_store>  one  </show_in_store> 
  <source_model>  adminhtml/system_config_source_yesno  </source_model> 
  </contact_us> 
  </fields> 
  </ident_returns> 
  </groups> 
  </trans_email> 
  </sections> 
  </config> 
In this particular codes all of us included many organizations to be able to segment   <trans_emails>   which usually sources in order to “Retail outlet E mail Includes” site within Admin→Configuration. Every single team symbolizes info concerning individual current email address which the web site makes use of. From the package presently there are usually a number of groupings currently additional inside Magento, for example generally there tend to be   <ident_support> ,   <ident_sales>   etc .

These people stand for consumer help e-mail along with revenue agent e mail, correspondingly. Let us point out an individual desire all those e-mail in order to become outlined about “Contact us” webpage because divisions thus we all will need extra industry just where all of us can easily arranged accessibility regarding these email messages with “Contact us” page. All of us included fresh area to each e-mail team and also known as that   <contact us>   as well as established it is tag to be able to “Accessible in call us web page”. It may be any basic “Yes/No” pick industry together with a number of other alternatives, When youre tiny baffled a person may study a lot more regarding areas in addition to system. xml in this article. From this article you can see, we all additional a couple of fresh organizations known as   <ident_repair>   and   <ident_returns>   that signifies our own Fix and also Profits divisions. Each and every associated with these provides about three areas, “Brand (Label)”, “Email” as well as “Obtainable upon buddies all of us webpage” which usually all of us can easily adjust within management.

Right now when we move in order to supervision settings and also wide open “Store Email Addresses” area we all may observe that will presently there are usually 2 brand new groupings regarding e-mail. But their own job areas tend to be vacant therefore let us arranged arrears ideals inside our own config. xml document. Put these kinds of outlines to be able to your own config. xml:

 <? xml version="1. 0"? > 
  <config> 
  <! -- This comment represents some other config nodes we arranged earlier --> 
  <default> 
  <trans_email> 
  <ident_sales> 
  <contact_us>  1  </contact_us> 
  </ident_sales> 
  <ident_support> 
  <contact_us>  1  </contact_us> 
  </ident_support> 
  <ident_repair> 
  <name>  Repair  </name> 
  <email>  repair@example. com  </email> 
  <contact_us>  a single  </contact_us> 
  </ident_repair> 
  <ident_returns> 
  <name>  Earnings  </name> 
  <email>  returns@example. com  </email> 
  <contact_us>  1  </contact_us> 
  </ident_returns> 
  </trans_email> 
  </default> 
  <! -- This particular comment represents other config nodes we set previously --> 
  </config> 
As an individual can easily identify, these types of systems which all of us additional adhere to section/group/field framework along with beliefs we all put underneath the area systems (in the case “name”, “email” as well as “contact_us” are field nodes) is going to be viewed within setup configurations.

Subsequent factor is actually in order to compose a few computer code wherever all of us get email messages that will are usually accessible in “Contact us” web page. Since “Contact us” webpage will be key Magento performance, we all ought to override several associated with the actual Magento lessons. To become much more certain, all of us may override Info tool regarding Buddies key component. An individual may go through much more overriding adjoint inside this specific write-up however generally we all include subsequent collections within the config. xml:

 <? xml version="1. 0"? > 
  <config> 
  <! -- This comment signifies other config nodes all of us set earlier --> 
  <global> 
  <helpers> 
  <contacts> 
  <rewrite> 
  <data>  Inchoo_Contacts_Helper_Data  </data> 
  </rewrite> 
  </contacts> 
  </helpers> 
  </global> 
  <! -- This opinion represents other config systems we set earlier --> 
  </config> 
Now all of us need to produce Tool directory website inside our own quests directory site and also generate record Information. php. Content of that data file must end up being such as this particular:

 <? php

class Inchoo_Contacts_Helper_Data extends Mage_Contacts_Helper_Data

    /**
     * Get emails for "Contact us" page
     *
     * @return mixed
     */
    public function getContactEmails()
    
        $allowedEmails = array();
        $emails = Mage::getStoreConfig('trans_email');

        foreach ($emails as $email) 
            if (isset($email['contact_us']) && $email['contact_us'] == 1) 
                $allowedEmails[] = $email;
            
       

        return $allowedEmails;
   

We expanded central Buddies assistant school and included one particular approach that earnings e-mail which will certainly become detailed upon “Contact us” web page. 1st we all run a great clear variety, second of all all of us retrieve all the e mail organizations that will tend to be situated in   <trans_email>   area. And then within foreach cycle we all are usually looking at regardless of whether each and every e-mail offers established “contact_us” industry benefit to be able to 1 (that is “Yes” in configuration). In case it may be arranged we have been saving this inside the range as well as ultimately returning which assortment.

Exhibiting division upon “Contact us” page

Now that will we all produced reasoning regarding having e-mail, all of us ought to show all of them in “Contact us” webpage. Initial we all require in order to locate web template data which we are definately override.

To do this, all of us should seem beneath   <contacts_index_index>   layout manage within app/design/frontend/rwd/default/layout/contacts. xml design document. Presently there we all can easily notice that will theme record all of us will need is actually “contacts/form. phtml”. I actually assume a person tend to be making use of custom made concept, however in case certainly not, an individual must constantly choose a customized style when you are going to adjust and also override Magento web templates. A person may study a lot more concerning making custom made designs right here.

Right now put these kinds of outlines for your customized concept “contacts/form. phtml” file:

 <? php
$emails = Mage:: helper('contacts')->  getContactEmails();
? > 
 <! -- Some other markup →

 <! -- Other form fields --> 

  <div class="field"> 
  <label for="department">   <? php replicate Mage:: helper('contacts')->  __('Department')? >   </label> 
  <div class="input-box"> 
  <select name="department" id="department" class="input-select validate-select"> 
  <option value="">  Select Department  </option> 
  <? php foreach($emails as $email):? > 
  <option value="  <? php echo $email['email']#@@#@!!? >  ">   <? php echo $email['name']#@@#@!!? >   </option> 
  <? php endforeach? > 
  </select> 
  </div> 
  </div> 
 <! -- Other contact form fields →
If we all renew our own “Contact us” web site all of us ought to observe fine brand-new Section dropdown along with labeling that will can easily end up being improved inside the administrative settings.

Ultimate stage would be to change control which usually is actually dealing with this specific demand. Since a person may imagine, we all need to override primary Magento control as well as which will be IndexController associated with key Contacts component. Include subsequent collections to be able to config. xml document associated with our own element:

 <? xml version="1. 0"? > 
  <config> 
  <! -- This comment signifies other config nodes all of us set earlier --> 
  <frontend> 
  <routers> 
  <contacts> 
  <args> 
  <modules> 
  <Inchoo_Contacts before="Mage_Contacts">  Inchoo_Contacts  </Inchoo_Contacts> 
  </modules> 
  </args> 
  </contacts> 
  </routers> 
  </frontend> 
  <! -- This particular comment represents other config nodes we set previously --> 
  </config> 
Now with app/code/local/Inchoo/Contacts/controllers directory website produce document IndexController. php and add the next content:

 <? php
require_once(Mage:: getModuleDir('controllers', 'Mage_Contacts'). DS. 'IndexController. php');

class Inchoo_Contacts_IndexController stretches Mage_Contacts_IndexController
 {
    public function postAction()
    {
        $post = $this->  getRequest()->  getPost();
        if ( $post ) 
            $translate = Mage::getSingleton('core/translate');
            /* @var $translate Mage_Core_Model_Translate */
            $translate->  setTranslateInline(false);
            try 
                $postObject = new Varien_Object();
                $postObject->  setData($post);
                // get emails enabled for Contact us page
                $allowedEmails = Mage::helper('contacts')->  getContactEmails();

                $error = false;

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) 
                    $error = true;
                

                if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) 
                    $error = true;
                

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) 
                    $error = true;
                

                if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) 
                    $error = true;
                

                // validate department email
                if (!Zend_Validate::is(trim($post['department']), 'EmailAddress')) 
                    $error = true;
                

                // check whether submitted emails is enabled in configuration
                $foundEmail = false;
                foreach($allowedEmails as $email)
                
                    if($email['email'] == $post['department'])
                        $foundEmail = true;
                    
                
                // if email is in allowed emails set error to false, if it's not
                // in allowed emails set error to true
                $error = ! $foundEmail;

                if ($error) 
                    throw new Exception();
                
                $mailTemplate = Mage::getModel('core/email_template');
                /* @var $mailTemplate Mage_Core_Model_Email_Template */
                $mailTemplate->  setDesignConfig(array('area' =>   'frontend'))
                    ->  setReplyTo($post['email'])
                    ->  sendTransactional(
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                        // send to selected department email
                        $post['department'],
                        null,
                        array('data' =>   $postObject)
                    );

                if (!$mailTemplate->  getSentSuccess()) 
                    throw new Exception();
                

                $translate->  setTranslateInline(true);

                Mage::getSingleton('customer/session')
                    ->  addSuccess(Mage::helper('contacts')->  __('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
                $this->  _redirect('home');

                return;
             catch (Exception $e) 
                $translate->  setTranslateInline(true);

                Mage::getSingleton('customer/session')->  addError(Mage::helper('contacts')->  __('Unable to submit your request. Please, try again later'));
                $this->  _redirect('*/*/');
                return;
            

         else {
            $this->  _redirect('*/*/');
        }
    }
}
We’ve overridden publish Action() method and also in fact cloned the majority of regarding the particular program code coming from mother or father course. All of us merely included further agreement with regard to the division e mail as well as checked out whether or not it is empowered within our own settings. We additional a few remarks previously mentioned outlines I extra due to the fact it may be less difficult in order to stick to almost everything inside computer code.

Bottom line

And that is that people, together with simply the small hard work you are able to expand your current “Contact us” web page through breaking your current client support directly into divisions that ought to velocity way up managing associated with help ask for.

And also regarding program, it is easier with regard to your own consumers to be able to send out a person assistance desires simply because there is simply no require regarding converting in electronic mail clientele and also looking with regard to your own personal email messages.

Thank you regarding looking at, allow me to realize within the actual feedback for those who have any kind of concerns. Appreciate code!

0 nhận xét:

Đăng nhận xét

Copyright © 2012 Extension magento free All Right Reserved