gpt4 book ai didi

magento - 如何为 onepagechekout 自动填写送货方式 Magento

转载 作者:行者123 更新时间:2023-12-01 12:49:41 26 4
gpt4 key购买 nike

我想自动填写送货方式,而不是在单页结帐时显示。通过在 app/code/local/Mage/Checkout/controllers/OnepageController.php 上更改此设置,我能够在我的 Onepagechekout 上隐藏送货方式:

/**
* save checkout billing address
*/
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
// $postData = $this->getRequest()->getPost('billing', array());
// $data = $this->_filterPostData($postData);
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);

if (isset($data['email'])) {
$data['email'] = trim($data['email']);
}
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);

if (!isset($result['error'])) {
/* check quote for virtual */
if ($this->getOnepage()->getQuote()->isVirtual())
{
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
} elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1)
{
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);

$result['allow_sections'] = array('shipping');
$result['duplicateBillingInfo'] = 'true';
} else {
$result['goto_section'] = 'shipping';
}
}
$this->saveShippingMethodAction();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}

如您所见,我更改了链接,在该链接中我将结算操作后的下一步重定向到付款步骤。

为了自动保存送货方式,我添加了

$this->saveShippingMethodAction();

在函数的末尾,这个方法如下所示:

    public function saveShippingMethodAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
/* $this->savePaymentAction(); */
$data = $this->getRequest()->getPost('shipping_method', 'flatrate_flatrate');
$result = $this->getOnepage()->saveShippingMethod($data);
$this->getResponse()->setBody(Zend_Json::encode($result));
}

}

所以我所做的是尝试自动包含 flatrate_flatrate 方法作为默认方法。

但是当我尝试完成销售时,它说我没有指定送货方式。知道为什么它不起作用吗?

最佳答案

现在您需要在报价和 session 中强制使用 shipping_method:

$forcedMethod = "your_method_code";

$this->getOnePage()->getQuote()
->getShippingAddress()
->setShippingMethod($forcedMethod)
->save();

Mage::getSingleton('checkout/session')->setShippingMethod($forcedMethod);

就在你打电话之前:

$this->saveShippingMethodAction(); 

添加一个:

$this->getRequest()->setPost('shipping_method', $forcedMethod);

它应该可以工作;)

关于magento - 如何为 onepagechekout 自动填写送货方式 Magento,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13451810/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com