2014-04-08 93 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設置爲定義的公司。它能正常工作。 –