0

お客様登録時:

デフォルトでは、Magento は提供された顧客名を使用して、デフォルトの配送/請求情報を自動入力します。私たちは B2B であり、登録時にその情報を個別に収集する必要があります。さらに、住所のファックス番号を取得する必要があります。

これらはカスタム属性ではなく (すでに多数作成されており、大幅に拡張された登録フォームに統合されています)、顧客の住所に関連付けられた標準の名、姓、およびファックス フィールドです。

私はこれを試みました:

        <span class="msg">Default shipping and billing information.</span>
        <ul class="form-list">
            <li class="fields">
                <div class="field billing_name">
                    <label for="billing_firstname" class="required"><em>*</em><?php echo $this->__('First Name') ?></label>
                    <div class="input-box">
                        <input type="text" name="billing_firstname" id="billing_firstname" value="<?php echo $this->htmlEscape($this->getFormData()->getFirstName()) ?>" title="<?php echo $this->__('First Name') ?>" class="input-text required-entry" />
                    </div>
                </div>
                <div class="field billing_name">
                    <label for="billing_lastname" class=""><em>*</em><?php echo $this->__('Last Name') ?></label>
                    <div class="input-box">
                        <input type="text" name="billing_lastname" id="billing_lastname" value="<?php echo $this->htmlEscape($this->getFormData()->getLastName()) ?>" title="<?php echo $this->__('Last Name') ?>" class="input-text required-entry" />
                    </div>
                </div>
            </li>

しかし、入力名がどうあるべきか明確ではありません。いずれにせよ、代わりにアカウント名が使用されます。

必要なフォーム フィールドの「名前」について少し情報を探したり、自動入力機能を無効にする方法も必要な場合があります。

乾杯


アップデート

これをもう少し詳しく見てみましょう。

私はmage/customer/controller/accountController.php :: createPostAction()をオーバーライドしています。コントローラーで、フォームが処理され、顧客エンティティとして入力される場所を確認します。

私はこのようなことを試みています

   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);


            // attempting to jam vars into address obj
                $address['_data']['firstname'] = $this->getRequest()->getPost('billing_firstname');
                $address['_data']['lastname'] = $this->getRequest()->getPost('billing_lastname');
                $address-['_data']['fax'] = $this->getRequest()->getPost('billing_fax');
            // end 
                Mage::log('createPostAction, after var jam: '. print_r($address, true ) );


            $customer->addAddress($address);

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

これをログアウトすると:

2012-12-18T01:51:10+00:00 DEBUG (7): createPostAction, after var jam: Mage_Customer_Model_Address Object
(
    [_customer:protected] => 
    [_eventPrefix:protected] => customer_address
    [_eventObject:protected] => customer_address
    [_resourceName:protected] => customer/address
    [_resource:protected] => 
    [_resourceCollectionName:protected] => customer/address_collection
    [_cacheTag:protected] => 
    [_dataSaveAllowed:protected] => 1
    [_isObjectNew:protected] => 
    [_data:protected] => Array
        (
            [entity_type_id] => 2
            [entity_id] => 
            [is_default_billing] => 1
            [is_default_shipping] => 1
            [firstname] => Chirp  // customer firstname
            [lastname] => Anaplex // customer lastname
            [company] => some agency
            [street] => 2345 somewhere dr
            [city] => somecity
            [country_id] => US
            [region] => 
            [region_id] => 44
            [postcode] => 84151
            [telephone] => 123-123-1233
        )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => 
    [_idFieldName:protected] => entity_id
    [_isDeleted:protected] => 
    [_oldFieldsMap:protected] => Array
        (
        )

    [_syncFieldsMap:protected] => Array
        (
        )

)

フォーム変数は正常に渡されています (ログに表示されます) が、この方法でアドレス オブジェクトに挿入できないようです。次の通知を受け取ります。

2012-12-18T16:39:39+00:00 ERR (3): Notice: Indirect modification of overloaded element of Mage_Customer_Model_Address has no effect  in /root/namespace/module/controllers/AccountController.php on line 79

これが「間接」の場合、「直接」の方法は何ですか?

誰?

4

1 に答える 1

0

ダープ。これは機能します。

$address->setData('firstname', $this->getRequest()->getPost('billing_firstname'));
$address->setData('lastname', $this->getRequest()->getPost('billing_lastname'));
$address->setData('fax', $this->getRequest()->getPost('billing_fax'));

他にこれが必要な人はいますか?

your/theme/template/persistent/forms/register.phtml
フォーム フィールドをオーバーライドMage_Customer_AccountController
setData('key', 'value')に追加するyourmodule/customer/controller/accountController.php :: createPostAction()

于 2012-12-18T16:54:20.117 に答える