Magento - 如何将新的送货地址(附加)设置为默认地址
我开发了一个自定义结帐模块并且工作正常。在第一次结账时,当我输入新的帐单和送货地址时,它们被设置为默认帐单和送货地址,这很好。现在,我有一个要求,每当输入新的送货地址时,这应该成为默认的送货地址。不知何故,我无法完成这项工作。我已尝试以下操作:
$shipdata 是一个具有新地址详细信息的数组。
$shipAddress = $this->getQuote()->getShippingAddress();
$shipAddress->addData($shipdata);
$shipAddress->setIsDefaultShipping(true);
if($this->getQuote()->getDefaultShipping()) {
$this->getQuote()->setData('default_shipping', '');
$this->getQuote()->addAddress($shipAddress);
}
$this->getQuote()->collectTotals();
$this->getQuote()->save();
我还尝试在 $shipdata 中添加以下内容
$shipdata['default_shipping'] = 1;
,但也没有帮助。 有人可以在这方面提供帮助吗?
I developed a custom checkout module and is working fine. During checkout for the first when I enter new billing and shipping address, they are getting set as default billing and shipping address, which is fine. Now, I have a requirement, whenever a new shipping address is entered, this should become as default shipping address. Somehow, I cannot make this work. I have tried the following:
$shipdata is a array having the new address details.
$shipAddress = $this->getQuote()->getShippingAddress();
$shipAddress->addData($shipdata);
$shipAddress->setIsDefaultShipping(true);
if($this->getQuote()->getDefaultShipping()) {
$this->getQuote()->setData('default_shipping', '');
$this->getQuote()->addAddress($shipAddress);
}
$this->getQuote()->collectTotals();
$this->getQuote()->save();
I also tried to add the following in the $shipdata
$shipdata['default_shipping'] = 1;
but also did not help.
Can some one help in this regard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试在“customer_address_save_before”事件上使用观察者。在那里设置 isDefaultShipping 标志就可以了。我唯一不知道的是检查您是否处于结帐过程中。
You could try to use an observer on the "customer_address_save_before" event. Setting the isDefaultShipping flag there will work. Only thing I don't know is checking whether you are in the checkout process.
在发布到下一页的表单中,只需包含隐藏的输入
In the form that posts to the next page simply include a hidden input