Magento自定义控制器操作不呈现设计

时间:2014-04-08 14:03:47

标签: 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上安装了主题。但是,当我打开页面时,它会渲染基本的magento主题,而不是我安装的主题。 如果我将代码从if($company->getCustomerId())评论为$this->loadLayout();(不包括$ this-> loadLayout();),则会显示正确的主题。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

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

$company = Mage::getModel('businesscategory/company')->load($requestData['id']);
这里可能没有设置$ requestData ['id'],因为你的if条件没有结束方法的处理。所以在代码中你可能没有$ company并且你在null上调用函数。

检查$ company是否为对象。

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

答案 1 :(得分:0)

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