0

我需要大家的指导..

我在里面添加了这个方法:Mage_Sales_Model_Order(它在本地文件夹中)。

public function getShippingEmailAdd()
{
    $ShippingEmailAdd='';
    $postData = Mage::app()->getRequest()->getPost();
    if (!isset($ShippingEmailAdd))
    {
       if (isset($postData['shipping:email'])) {
            $ShippingEmailAdd =$postData['shipping:email'];
        }else{
            $ShippingEmailAdd = 'lol@email.com';
        }
        // $shipment_data = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData();
        // $ShippingEmailAdd = $shipment_data;
    }



    return $ShippingEmailAdd;
}

此方法的重点是从单页结帐中获取 shipping[email] 输入。并且还在方法下添加了这一行:samefile::sendNewOrderEmail()

$mailer->setTemplateParams(array(
            'order'        => $this,
            'billing'      => $this->getBillingAddress(),
            'payment_html' => $paymentBlockHtml,
            'emailadd' => $this->getShippingEmailAdd() <--- added line
        )
    );

这样我就可以在 order_*.html 模板中使用 {{var emailadd}} 了。但我什么也没得到,我做错了什么?什么是实现我的目标的正确方法?

按要求更新:这是电子邮件输入,来自作为单页结帐过程的一部分的装运表格:

<li>
            <div class="input-box">
                <label for="shipping:emailadd"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br />
                <input type="text" name="shipping[email]" id="shipping:emailadd" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" />
            </div>
            <div class="input-box">
                <label for="shipping:emailadd"><?php echo $this->__('Confirm Email') ?> <span class="required">*</span></label><br />
                <input type="text" name="shipping[emailconfirm]" id="shipping:emailconfirm" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="validate-email required-entry input-text" />
            </div>
        </li>

同样,我的目标是在发送结帐流程后获取电子邮件字段输入,并将 shipping[email] 值添加到 Mage_Sales_Model_Order::getShippingEmailAdd() 以便当我在方法 age_Sales_Model_Order:: 下使用它时sendNewOrderEmail() 像这样:

$mailer->setTemplateParams(array(
            'order'        => $this,
            'billing'      => $this->getBillingAddress(),
            'payment_html' => $paymentBlockHtml,
            'emailadd' => $this->getShippingEmailAdd() <------ like this
        )
    );

所以我可以在 order_*.html 电子邮件模板中使用它作为 {{var emailadd}}

而已。

4

1 回答 1

1

getShippingEmailAdd()将返回''

if 语句中的代码不会被执行。

$ShippingEmailAdd='';

if (!isset($ShippingEmailAdd))
{
    // remove your code from here
    $ShippingEmailAdd = 'executed';
}
else{
    $ShippingEmailAdd = 'not executed';
}

echo $ShippingEmailAdd;

您将在这里测试http://writecodeonline.com/php/

尝试

public function getShippingEmailAdd()
{
    $postData = Mage::app()->getRequest()->getPost();

    if (isset($postData['shipping:email'])) {  // <- double check your form field name
        $ShippingEmailAdd =$postData['shipping:email'];
    }else{
        $ShippingEmailAdd = 'lol@email.com';
    }

    return $ShippingEmailAdd;
}
于 2013-10-14T14:09:07.927 回答