创建自定义注册表单,其中包含联系信息和公司信息Magento

时间:2013-11-25 14:55:57

标签: magento customization registration

朋友们,我不是 magento 的专家,但我对它有很好的了解,但我对模块知之甚少,我需要创建

  

自定义注册表,包含联系信息和公司信息

详情,

  

我需要在我自己的自定义页面上创建它,我需要magento   默认注册页面

,我检查了

app\code\core\Mage\Customer\controllers/AccountController  

我得到了

public function createPostAction()
    {
        $session = $this->_getSession();
        if ($session->isLoggedIn()) {
            $this->_redirect('*/*/');
            return;
        }
        $session->setEscapeMessages(true); // prevent XSS injection in user input
        if ($this->getRequest()->isPost()) {
            $errors = array();

            if (!$customer = Mage::registry('current_customer')) {
                $customer = Mage::getModel('customer/customer')->setId(null);
            }

            /* @var $customerForm Mage_Customer_Model_Form */
            $customerForm = Mage::getModel('customer/form');
            $customerForm->setFormCode('customer_account_create')
                ->setEntity($customer);

            $customerData = $customerForm->extractData($this->getRequest());

            if ($this->getRequest()->getParam('is_subscribed', false)) {
                $customer->setIsSubscribed(1);
            }

            /**
             * Initialize customer group id
             */
            $customer->getGroupId();

            if ($this->getRequest()->getPost('create_address')) {
                /* @var $address Mage_Customer_Model_Address */
                $address = Mage::getModel('customer/address');
                /* @var $addressForm Mage_Customer_Model_Form */
                $addressForm = Mage::getModel('customer/form');
                $addressForm->setFormCode('customer_register_address')
                    ->setEntity($address);

                $addressData    = $addressForm->extractData($this->getRequest(), 'address', false);
                $addressErrors  = $addressForm->validateData($addressData);
                if ($addressErrors === true) {
                    $address->setId(null)
                        ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
                        ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
                    $addressForm->compactData($addressData);
                    $customer->addAddress($address);

                    $addressErrors = $address->validate();
                    if (is_array($addressErrors)) {
                        $errors = array_merge($errors, $addressErrors);
                    }
                } else {
                    $errors = array_merge($errors, $addressErrors);
                }
            }

            try {
                $customerErrors = $customerForm->validateData($customerData);
                if ($customerErrors !== true) {
                    $errors = array_merge($customerErrors, $errors);
                } else {
                    $customerForm->compactData($customerData);
                    $customer->setPassword($this->getRequest()->getPost('password'));
                    $customer->setConfirmation($this->getRequest()->getPost('confirmation'));
                    $customerErrors = $customer->validate();
                    if (is_array($customerErrors)) {
                        $errors = array_merge($customerErrors, $errors);
                    }
                }

                $validationResult = count($errors) == 0;

                if (true === $validationResult) {
                    $customer->save();

                    Mage::dispatchEvent('customer_register_success',
                        array('account_controller' => $this, 'customer' => $customer)
                    );

                    if ($customer->isConfirmationRequired()) {
                        $customer->sendNewAccountEmail(
                            'confirmation',
                            $session->getBeforeAuthUrl(),
                            Mage::app()->getStore()->getId()
                        );
                        $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
                        $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
                        return;
                    } else {
                        $session->setCustomerAsLoggedIn($customer);
                        $url = $this->_welcomeCustomer($customer);
                        $this->_redirectSuccess($url);
                        return;
                    }
                } else {
                    $session->setCustomerFormData($this->getRequest()->getPost());
                    if (is_array($errors)) {
                        foreach ($errors as $errorMessage) {
                            $session->addError($errorMessage);
                        }
                    } else {
                        $session->addError($this->__('Invalid customer data'));
                    }
                }
            } catch (Mage_Core_Exception $e) {
                $session->setCustomerFormData($this->getRequest()->getPost());
                if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
                    $url = Mage::getUrl('customer/account/forgotpassword');
                    $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
                    $session->setEscapeMessages(false);
                } else {
                    $message = $e->getMessage();
                }
                $session->addError($message);
            } catch (Exception $e) {
                $session->setCustomerFormData($this->getRequest()->getPost())
                    ->addException($e, $this->__('Cannot save the customer.'));
            }
        }

        $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
    }
  

用于创建新帐户

  

但我不想编辑这个功能,因为我需要magento   默认注册页面als

o,所以请建议我如何创建一个新的功能,我可以让客户提供信息,并可以注册,我可以存储在数据库中,基本上我需要存储联系信息和公司地址表中的信息,以便信息可以在管理

中显示

2 个答案:

答案 0 :(得分:1)

您的自定义模块应包含类似内容:
封装/模块的/ etc / config.xml中
封装/模块/控制器/ contactController.php
封装/模块/ SQL / modulename_setup / mysql4安装,1.0.0.php
应用程序/设计/前端/默认/默认/布局/ customercontact.xml

<强> config.xml中:

<config>

...

<modules>
    <Package_Module>
        <version>1.0.0</version>
    </Package_Module>
</modules>

<frontend>
<!--configure your controllers-->
<routers>
  <modulename>
     <use>standard</use>
       <args>
         <module>Package_Module</module>
         <frontName>modulename</frontName>
       </args>
  </modulename>
</routers>
<layout>
  <updates>
      <modulename>
          <file>customercontact.xml</file>
      </modulename>
  </updates>
</layout>
</frontend>

<global>
<blocks></blocks><!--you can read some blogs etc-->
<models></models><!--you can read some blogs etc-->
<helpers></helpers><!--you can read some blogs etc-->
<resources>
            <modulename_setup>
                <setup>
                    <module>Package_Module</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </modulename_setup>
            <modulename_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </modulename_write>
            <modulename_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </modulename_read>
        </resources>
</global>

...

</config>

<强> ContactController.php

public function customerDetailsAction(){

   /*render your form 
     Use layout handle to set your own blocks
    */

}

public function customerDetailsPostAction(){

   /*borrow some logic from AccountController or Build your own
     get posted data, validate and set to model & save
    */

}

<强> mysql4安装-1.0.0.php

在我的类似任务中使用以下脚本:

$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');//invoke customer entity setup class

// add your attribute to customer entity
$setup->addAttribute(
        'customer', 
        'attribute_code', 
        array(
                'type'              => 'varchar',
                'input'             => 'text',
                'label'             => 'Company name',
                'global'            => 1,
                'visible'           => 1,
                'required'          => 0,
                'user_defined'      => 1,
                'visible_on_front'  => 1,

         )
);

if (version_compare(Mage::getVersion(), '1.6.0', '<='))
{
      $customer = Mage::getModel('customer/customer');
      $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId();
      $setup->addAttributeToSet('customer', $attrSetId, 'General', 'attribute_code');
}
if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
    /*
     * To get new attribute listed for customer/form  various models, example checl line 275 to 277 AccountController.php 
     */
    Mage::getSingleton('eav/config')
    ->getAttribute('customer', 'attribute_code')
    ->setData(
               'used_in_forms', 
                array(
                       'adminhtml_customer',//will make new attribute appear in admin
                       'customer_account_create',//will make new attribute appear on registration
                       'customer_account_edit',//will make new attribute appear in account dashboard
                       'checkout_register'// on checkout page
                )
    )
    ->save();
}

customercontact.xml

<layout>

...

<modulename_contact_customerDetails>
 <update handle="customer_account_create"/><!--if only some additional fields are needed-->
 <referene name="customer_form_register"><!--set your template based on customer/form/register.phtml-->
  <action method="setTemplate">path to your template</action>
 </reference>
</modulename_contact_customerDetails>

...

</layout>

希望这能说明需要做些什么!

答案 1 :(得分:0)

对于您来说,前面看似最简单的方法是创建一个自定义模块,如果您希望将联系表单收集的数据呈现给管理员用户,请使用前端控制器,单个表模型和管理网格其他magento模块显示数据。

如果使用正确的工具集,创建magento扩展非常容易,您可以使用this模块创建者立即创建扩展。