dongqiulei6805 2013-10-21 08:16
浏览 65

重定向到仪表板后,Magento自定义注册成功消息

I need to extend the custom success message after the customer registration. Now after registration the user is redirected to the dashboard and the standard success message is shown: "Thank you for registering with...".

I need that this message changes base on the customer group attribute. I read on-line but didn't find a working solution... but I think I'm making it in the wrong way. I started from here: http://mydons.com/simple-example-using-magento-event-observer/ to make a custom observer on the customer_register_success event, so I made the module xml named Bbox_Regmess.xml in app/etc/modules:

<config>
  <modules>
    <Bbox_Regmess>
      <active>true</active>
      <codePool>local</codePool>
    </Bbox_Regmess>
  </modules>
</config>

Than I made the app/code/local/Bbox/Regmess/etc and app/code/local/Bbox/Regmess/Model folders with inside the config.xml:

<config>
  <modules>
    <Bbox_Regmess>
      <version>0.1.0</version>
    </Bbox_Regmess>
  </modules>
  <frontend>
    <events>
      <customer_register_success>
        <observers>
          <Bbox_Regmess_Model_Observer>
            <type>singleton</type>
            <class>Bbox_Regmess_Model_Observer</class>
            <method>Customregmess</method>
          </Bbox_Regmess_Model_Observer>
        </observers>
      </customer_register_success>
    </events>
  </frontend>
</config>

And the Observer.php that is just a first try to see if I'm able to add a custom success message:

<?php
    class Bbox_Regmess_Model_Observer {
        public function Customregmess($observer) {
        $event = $observer->getEvent();  //Fetches the current event
        $customer = $event->getCustomer();
            $eventmsg = "Current Event Triggered : <I>" . $event->getName() . "</I><br/> Currently Added Product : <I> " . $customer->getCustomerName()."</I>";
            //Adds Custom message to shopping cart
            Mage::getSingleton('customer/session')->addSuccess($eventmsg);
        }
    }
?>

Now if a user registers to the shop, he get the standard registration message and there is not the custom $eventmsg

What I'm making wrong? There is another way to to that? Thanks

UPDATE:
looking deeper I found out the default success message is defined in the app/code/core/Mage/Customer/controllers/AccountController.php at line 390 (just after the line 334 where there is the definition of customer_register_success event I'm trying to work with).
at line 390 there is the _welcomeCustomer function that is in charge of setting the success message, send confirmation email and set the success redirect url:

protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{
    $this->_getSession()->addSuccess(
        $this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName())
    );

    $customer->sendNewAccountEmail(
        $isJustConfirmed ? 'confirmed' : 'registered',
        '',
        Mage::app()->getStore()->getId()
    );

    $successUrl = Mage::getUrl('*/*/index', array('_secure'=>true));
    if ($this->_getSession()->getBeforeAuthUrl()) {
        $successUrl = $this->_getSession()->getBeforeAuthUrl(true);
    }
    return $successUrl;
}

Is there any chance to extend this function so I can manage multiple success message base on the customer group?
I've look for some resource about it, but I didn't find anything usefull

  • 写回答

1条回答 默认 最新

  • doufeikuang7724 2013-10-21 08:27
    关注

    I think that you must place the events tag in the global tag

    <config><global>...<events>...</events>...</global>...</config>

    EDIT:

    and the observer file extends Varien_Event_Observer, at least that worked with mine

    class Bbox_Regmess_Model_Observer extends Varien_Event_Observer{}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大