2014-04-08 98 views
0

人。我有个问题。我在我的自定义模块中有一个动作,创建客户。 有一个代码:Magento自定义控制器操作不渲染设计

在我的Magento
class SeosClub_BusinessCategory_CustomerController extends Mage_Core_Controller_Front_Action { 

public function createAction(){ 

    $requestData = Mage::app()->getRequest()->getParams(); 
    if(!$requestData['id'] || !$requestData['activation_code']){ 
     Mage::getSingleton('core/session')->addError('Request data invalid'); 
    } 

    $company = Mage::getModel('businesscategory/company')->load($requestData['id']); 
    if (!$company->getId()){ 
     Mage::getSingleton('core/session')->addError('Your company does not exist'); 
    } 
    if($company->getCustomerId()){ 
     Mage::getSingleton('core/session')->addNotice($this->__('Customer already created. Forgot password?')); 
     $this->_redirect('customer/account/forgotpassword/'); 
     return; 
    } 

    $group = Mage::getModel('customer/group')->load('Companies', 'customer_group_code');; 

    $customer = Mage::getModel("customer/customer"); 
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId()); 
    $customer->setStore(Mage::app()->getStore()); 
    $customer->setData('group_id', $group->getId()); 

    $customer->setFirstname($company->getName()); 
    $customer->setLastname($this->__('Unknown')); 
    $customer->setEmail($company->getEmail()); 
    $customer->setPassword(Mage::helper('core')->getRandomString(8)); 
    try{ 
     $customer->save(); 
     $customer->sendNewAccountEmail(); 
     $company->setCustomerId($customer->getId()); 
     $company->save(); 
     Mage::getSingleton('core/session')->addSuccess($this->__('Account was created succefully')); 
    } 

    catch (Exception $e) { 
     Mage::getSingleton('core/session')->addError($e->getMessage()); 
    } 


    $this->loadLayout(); 
    $this->renderLayout(); 

} 

}

我也安装的主题。但是,当我打开页面时,它渲染了基础magento主题,而不是我安装的主题。 如果我将代码从if($company->getCustomerId())改为$this->loadLayout();(不包括$ this-> loadLayout();),它将呈现正确的主题。

任何想法?

回答

0

好的,解决我需要在渲染布局后发送客户电子邮件。

0

在magento中启用开发人员模式。取消index.php中的display_errors的注释。你应该会看到一些错误,因为你必须:

$company = Mage::getModel('businesscategory/company')->load($requestData['id']); 

$的RequestData [“身份证”]可能不能在此设置,因为你如果条件不结束该方法的处理。因此,在代码中,您可能没有$ company,并且您可以在null上调用函数。

检查$ company是否是一个对象。

我认为它呈现默认主题,因为你有错误。

+0

已启用。没有错误。 '公司' - 这是一个选项。 '$ requestData ['id']'定义。除了设计,一切都在运作。 –

+0

再往下看你的代码? $ company-> getCustomerId()? – Emi

+0

我告诉过你,除了设计之外,一切都在运转。当客户被创建时,它将customer_id设置为定义的公司。它能正常工作。 –