Magento自定义送货方法未显示在后端手动订单创建中

时间:2014-02-09 19:18:52

标签: magento magento-1.7

我创建了一个Custom shipping Module working fine in frontend.

但是当我尝试create an order manually from backend然后custom shipping method is not appearing.

以下是Model/Carrier/Distributor.php

下的代码
<?php
class Distributor_Ship_Model_Carrier_Distributor extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface {
    protected $_code = 'distributor';

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {
        if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
            return false;
        }

 $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
 $subtotal = $totals["subtotal"]->getValue(); //Subtotal value
$range1 = $this->getConfigData('range1');
$range2 = $this->getConfigData('range2');
$price1 = $this->getConfigData('price1');
$range3 = $this->getConfigData('range3');
$range4 = $this->getConfigData('range4');
$price2 = $this->getConfigData('price2');
$range5 = $this->getConfigData('range5');
$price3 = $this->getConfigData('price3');

$customer = Mage::helper('customer')->getCustomer();
$group = null;
if($customer)
{
    $group = $customer->getGroupId();
}
if($group == 6 && $subtotal>$range1){

if($subtotal>$range1 && $subtotal<$range2){
$price = $price1;
//$methodName = 'For Residential Address if Order Amount is greater than '.$range1.' And less than '.$range2.'.Then shipping cost is';
}
else if($subtotal>$range3 && $subtotal<$range4){
$price = $price2;
//$methodName = 'For Residential Address if Order Amount is greater than '.$range3.' And less than '.$range4.'.Then shipping cost is';
}
else if($subtotal>$range5)
{
    $price = $price3;
    //$methodName = 'For Residential Address if Order Amount is greater than '.$range5.'.Then shipping cost is';
}
}
else{
return false; // disable the shipping method
}
        //$price = 0;
        /*

        */


        $handling = Mage::getStoreConfig('carriers/'.$this->_code.'/handling');
        $result = Mage::getModel('shipping/rate_result');
        $show = true;
        if($show){

            $method = Mage::getModel('shipping/rate_result_method');
            $method->setCarrier($this->_code);
            $method->setMethod($this->_code);
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethodTitle($this->getConfigData('name'));
            $method->setPrice($price);
            $method->setCost($price);
            $result->append($method);

        }else{
            $error = Mage::getModel('shipping/rate_result_error');
            $error->setCarrier($this->_code);
            $error->setCarrierTitle($this->getConfigData('name'));
            $error->setErrorMessage($this->getConfigData('specificerrmsg'));
            $result->append($error);
        }
        return $result;
    }
    public function getAllowedMethods()
    {
        return array('distributor'=>$this->getConfigData('name'));
    }
    public function isTrackingAvailable()
{
    return true;
}
}

这是config.xml下的etc

<?xml version="1.0"?>
<config>
    <modules>
        <Distributor_Ship>
            <version>0.1.0</version>
        </Distributor_Ship>
    </modules>
    <frontend>
        <routers>
            <ship>
                <use>standard</use>
                <args>
                    <module>Distributor_Ship</module>
                    <frontName>ship</frontName>
                </args>
            </ship>
        </routers>
        <layout>
            <updates>
                <ship>
                    <file>ship.xml</file>
                </ship>
            </updates>
        </layout>
    </frontend>
    <global>
        <models>
            <ship>
                <class>Distributor_Ship_Model</class>
                <resourceModel>ship_mysql4</resourceModel>
            </ship>
            <ship_mysql4>
                <class>Distributor_Ship_Model_Mysql4</class>
                <entities>
                    <ship>
                        <table>ship</table>
                    </ship>
                </entities>
            </ship_mysql4>
        </models>
        <resources>
            <ship_setup>
                <setup>
                    <module>Distributor_Ship</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </ship_setup>
            <ship_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </ship_write>
            <ship_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </ship_read>
        </resources>
        <blocks>
            <ship>
                <class>Distributor_Ship_Block</class>
            </ship>
        </blocks>
        <helpers>
            <ship>
                <class>Distributor_Ship_Helper</class>
            </ship>
        </helpers>
    </global>
    <default>
        <carriers>
          <distributor>
               <active>1</active>
               <model>ship/carrier_distributor</model>
               <title>Carrier Title</title>
               <name>Method Name</name>
               <price>5.00</price>
               <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
            </distributor>
         </carriers>
       </default>
</config>

I cant understand what is the problem..plz help ...我需要在magento backend order create

中展示它

1 个答案:

答案 0 :(得分:2)

我希望你已经找到了解决方法,但我最近遇到了同样的问题,经过一些干预后,我找到了解决方案,并认为我会分享。

问题似乎是由于以下几行代码

$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value

这些不适用于管理部分。因此,为了获得小计,我用以下代码替换了上述代码。

$model = Mage::getModel('adminhtml/sales_order_create');
$totals = $model->getQuote()->collectTotals();
$subTotal = $totals["subtotal"];    

这解决了我的问题,发货方法出现在后端。我希望它对你也有所帮助。