Magento禁用购物车上的自动送货报价

时间:2013-09-24 14:06:21

标签: php magento

在magento我想删除自动发货计算。目前,如果您输入邮政编码进行计算,请返回购物并添加更多购物车,当您返回购物车时,它将自动计算运费。我想要求每次都按下“获取报价”按钮计算出货量。

想法?

1 个答案:

答案 0 :(得分:0)

我试图在一周内做同样的事情,但它不能100%工作。我认为代码应该是这样的:

第一步:添加一个JS函数:

_instantQuoteShippingResponse {
    var cart = document.getElementsByClassName('cart-shipping-block')[0];
    cart.innerHTML = response.responseText.evalJSON().cart_shipping;
    cart.innerHTML = cart.firstChild.innerHTML;
    return true;
}

instantQuoteShipping() {
    try {var request = new Ajax.Request(coShippingMethodForm.form.action, {method: 'post',
            parameters: {
                country_id: $('country').value, region_id: $('region_id').value,
                region: $('region').value, estimate_postcode: $('postcode').value},
                redirect: 'no',
            onSuccess: function(response) {_instantQuoteShippingResponse(response);},
            onFailure: function(response) {coShippingMethodForm.submit();}});
    } catch(e) { return false;}
    return true;
}

第二步:将点击事件添加到出货报价按钮(app \ design \ frontend \ default \ modern \ template \ checkout \ cart \ shipping.phtml)。

onclick="instantQuoteShipping()"

第三步:编辑购物车控制器(Mage / Checkout / controllers / CartController.php) 重写estimatePostAction:

public function estimatePostAction()
{
    parent::estimatePostAction();
    if ($this->getRequest()->getParam('redirect') == 'no') {
        try {
            $response = array();
            $this->loadLayout();
            $this->_getSession()->getMessages(true);
            // $response['cart_shipping'] = $this->getLayout()->getBlock('checkout.cart.shipping')->toHtml();
            $response['cart_shipping'] = $this->getLayout()
                ->createBlock('checkout/cart_shipping')
                ->setTemplate('checkout/cart/shipping.phtml')->toHtml();
            $this->getResponse()->clearAllHeaders();
            $this->getResponse()->setBody(Zend_Json::encode($response));
            $this->getResponse()->setHttpResponseCode(200);
        } catch(Exception $e) {
            Mage::log($e->getMessage());
        }
    }
}

第四步:编辑cart.phtml(app \ design \ frontend \ default \ modern \ template \ checkout \ cart.phtml)复制shipping.phtml中的所有内容,估算费率块除外:

// Locate this line:
<?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>

// Update to...:
<?php if (!$this->getIsVirtual()): ?>
    // Paste all content from shipping.phtml here
<?php endif; ?>


// ATENTION: Dont paste the code below
if (($_shippingRateGroups = $this->getEstimateRates())) {
    ...
}

它应该有用!